Compare commits

...

3 Commits

Author SHA1 Message Date
67cc148bb8 Made condition more consistent📄 2025-03-02 07:56:35 -06:00
159126e7ca Got refactor to compile⚙️ 2025-03-02 04:58:05 -06:00
e329b1f223 Start of major refactor 2025-03-01 19:55:15 -06:00
8 changed files with 516 additions and 643 deletions

2
.gitignore vendored
View File

@ -3,4 +3,4 @@ Rocket.toml
/web/dynamic/script.js
/web/dynamic/style.css
/web/static
.env

2
build
View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
mkdir -p web/static
touch .env web/static/userstyle.css
source .env
lsc --no-header -bco web/dynamic/ web/src/script.ls || exit 1
npx sass --no-source-map web/src/style.scss web/dynamic/style.css || exit 2
rustfmt src/*.rs || exit 3

View File

@ -1,202 +0,0 @@
[
{
"id": "{3df927c0-9aa9-450b-ab2a-ae12c5489d57}",
"name": "Supplant Form",
"png": "https://cards.scryfall.io/png/front/3/d/3df927c0-9aa9-450b-ab2a-ae12c5489d57.png?1562824437",
"jpg": "https://cards.scryfall.io/small/front/3/d/3df927c0-9aa9-450b-ab2a-ae12c5489d57.jpg?1562824437",
"text": "Return target creature to its owner's hand. You create a token that's a copy of that creature.",
"count": 2
},
{
"id": "{30202613-d05f-4f47-af97-d0b75ccac293}",
"name": "Memory Lapse",
"png": "https://cards.scryfall.io/png/front/3/0/30202613-d05f-4f47-af97-d0b75ccac293.png?1634131658",
"jpg": "https://cards.scryfall.io/small/front/3/0/30202613-d05f-4f47-af97-d0b75ccac293.jpg?1634131658",
"text": "Counter target spell. If that spell is countered this way, put it on top of its owner's library instead of into that player's graveyard.",
"count": 8
},
{
"id": "{ad88e5ee-0eee-47af-a7b4-9bac044e1c8c}",
"name": "Accumulated Knowledge",
"png": "https://cards.scryfall.io/png/front/a/d/ad88e5ee-0eee-47af-a7b4-9bac044e1c8c.png?1562439718",
"jpg": "https://cards.scryfall.io/small/front/a/d/ad88e5ee-0eee-47af-a7b4-9bac044e1c8c.jpg?1562439718",
"text": "Draw a card, then draw cards equal to the number of cards named Accumulated Knowledge in all graveyards.",
"count": 4
},
{
"id": "{806e5536-103b-4d6c-83b4-8659a55b25b5}",
"name": "Mystic Retrieval",
"png": "https://cards.scryfall.io/png/front/8/0/806e5536-103b-4d6c-83b4-8659a55b25b5.png?1736467785",
"jpg": "https://cards.scryfall.io/small/front/8/0/806e5536-103b-4d6c-83b4-8659a55b25b5.jpg?1736467785",
"text": "Return target instant or sorcery card from your graveyard to your hand.\nFlashback {2}{R} (You may cast this card from your graveyard for its flashback cost. Then exile it.)",
"count": 2
},
{
"id": "{36fa9a0b-b0c9-43ea-ba11-99d7982f974e}",
"name": "Mystical Tutor",
"png": "https://cards.scryfall.io/png/front/3/6/36fa9a0b-b0c9-43ea-ba11-99d7982f974e.png?1675199375",
"jpg": "https://cards.scryfall.io/small/front/3/6/36fa9a0b-b0c9-43ea-ba11-99d7982f974e.jpg?1675199375",
"text": "Search your library for an instant or sorcery card, reveal it, then shuffle and put that card on top.",
"count": 2
},
{
"id": "{21fe2f1b-bfd1-4682-ae23-069300de3791}",
"name": "Svyelunite Temple",
"png": "https://cards.scryfall.io/png/front/2/1/21fe2f1b-bfd1-4682-ae23-069300de3791.png?1562867851",
"jpg": "https://cards.scryfall.io/small/front/2/1/21fe2f1b-bfd1-4682-ae23-069300de3791.jpg?1562867851",
"text": "Svyelunite Temple enters tapped.\n{T}: Add {U}.\n{T}, Sacrifice Svyelunite Temple: Add {U}{U}.",
"count": 2
},
{
"id": "{8beb987c-1b67-4a4e-ae71-58547afad2a0}",
"name": "Brainstorm",
"png": "https://cards.scryfall.io/png/front/8/b/8beb987c-1b67-4a4e-ae71-58547afad2a0.png?1726284649",
"jpg": "https://cards.scryfall.io/small/front/8/b/8beb987c-1b67-4a4e-ae71-58547afad2a0.jpg?1726284649",
"text": "Draw three cards, then put two cards from your hand on top of your library in any order.",
"count": 2
},
{
"id": "{c548d140-3d81-4b33-9985-87703d316a83}",
"name": "Dance of the Skywise",
"png": "https://cards.scryfall.io/png/front/c/5/c548d140-3d81-4b33-9985-87703d316a83.png?1562792779",
"jpg": "https://cards.scryfall.io/small/front/c/5/c548d140-3d81-4b33-9985-87703d316a83.jpg?1562792779",
"text": "Until end of turn, target creature you control becomes a blue Dragon Illusion with base power and toughness 4/4, loses all abilities, and gains flying.",
"count": 2
},
{
"id": "{7132999f-6e2d-4689-8131-7b12076a348d}",
"name": "Island",
"png": "https://cards.scryfall.io/png/front/7/1/7132999f-6e2d-4689-8131-7b12076a348d.png?1655495395",
"jpg": "https://cards.scryfall.io/small/front/7/1/7132999f-6e2d-4689-8131-7b12076a348d.jpg?1655495395",
"text": "({T}: Add {U}.)",
"count": 18
},
{
"id": "{7ca8a427-5c20-4650-bbb5-9895e4f2c009}",
"name": "Ray of Command",
"png": "https://cards.scryfall.io/png/front/7/c/7ca8a427-5c20-4650-bbb5-9895e4f2c009.png?1592754536",
"jpg": "https://cards.scryfall.io/small/front/7/c/7ca8a427-5c20-4650-bbb5-9895e4f2c009.jpg?1592754536",
"text": "Untap target creature an opponent controls and gain control of it until end of turn. That creature gains haste until end of turn. When you lose control of the creature, tap it.",
"count": 2
},
{
"id": "{2dc0bafd-debc-4b62-9fe0-56b4aad02484}",
"name": "Unsubstantiate",
"png": "https://cards.scryfall.io/png/front/2/d/2dc0bafd-debc-4b62-9fe0-56b4aad02484.png?1594735888",
"jpg": "https://cards.scryfall.io/small/front/2/d/2dc0bafd-debc-4b62-9fe0-56b4aad02484.jpg?1594735888",
"text": "Return target spell or creature to its owner's hand.",
"count": 2
},
{
"id": "{ac2e32d0-f172-4934-9d73-1bc2ab86586e}",
"name": "Dandân",
"png": "https://cards.scryfall.io/png/front/a/c/ac2e32d0-f172-4934-9d73-1bc2ab86586e.png?1562781784",
"jpg": "https://cards.scryfall.io/small/front/a/c/ac2e32d0-f172-4934-9d73-1bc2ab86586e.jpg?1562781784",
"text": "Dandân can't attack unless defending player controls an Island.\nWhen you control no Islands, sacrifice Dandân.",
"count": 10
},
{
"id": "{692a5bfa-9a50-4610-acd7-19fc0a53f798}",
"name": "Mind Bend",
"png": "https://cards.scryfall.io/png/front/6/9/692a5bfa-9a50-4610-acd7-19fc0a53f798.png?1562549129",
"jpg": "https://cards.scryfall.io/small/front/6/9/692a5bfa-9a50-4610-acd7-19fc0a53f798.jpg?1562549129",
"text": "Change the text of target permanent by replacing all instances of one color word with another or one basic land type with another. (For example, you may change \"nonblack creature\" to \"nongreen creature\" or \"forestwalk\" to \"islandwalk.\" This effect lasts indefinitely.)",
"count": 2
},
{
"id": "{a340af37-c0a7-4f26-974b-95397b5c32f7}",
"name": "Remote Isle",
"png": "https://cards.scryfall.io/png/front/a/3/a340af37-c0a7-4f26-974b-95397b5c32f7.png?1709139228",
"jpg": "https://cards.scryfall.io/small/front/a/3/a340af37-c0a7-4f26-974b-95397b5c32f7.jpg?1709139228",
"text": "Remote Isle enters tapped.\n{T}: Add {U}.\nCycling {2} ({2}, Discard this card: Draw a card.)",
"count": 2
},
{
"id": "{8eafb2bb-58bf-4c6b-ae8f-91bcea12c7d2}",
"name": "Insidious Will",
"png": "https://cards.scryfall.io/png/front/8/e/8eafb2bb-58bf-4c6b-ae8f-91bcea12c7d2.png?1576381260",
"jpg": "https://cards.scryfall.io/small/front/8/e/8eafb2bb-58bf-4c6b-ae8f-91bcea12c7d2.jpg?1576381260",
"text": "Choose one —\n• Counter target spell.\n• You may choose new targets for target spell.\n• Copy target instant or sorcery spell. You may choose new targets for the copy.",
"count": 2
},
{
"id": "{bfac9395-7ca5-48dd-ab83-7c26ada12f61}",
"name": "Izzet Boilerworks",
"png": "https://cards.scryfall.io/png/front/b/f/bfac9395-7ca5-48dd-ab83-7c26ada12f61.png?1712355049",
"jpg": "https://cards.scryfall.io/small/front/b/f/bfac9395-7ca5-48dd-ab83-7c26ada12f61.jpg?1712355049",
"text": "Izzet Boilerworks enters tapped.\nWhen Izzet Boilerworks enters, return a land you control to its owner's hand.\n{T}: Add {U}{R}.",
"count": 2
},
{
"id": "{349ac7e6-af38-4dc3-abfe-369564c75630}",
"name": "Predict",
"png": "https://cards.scryfall.io/png/front/3/4/349ac7e6-af38-4dc3-abfe-369564c75630.png?1592710621",
"jpg": "https://cards.scryfall.io/small/front/3/4/349ac7e6-af38-4dc3-abfe-369564c75630.jpg?1592710621",
"text": "Choose a card name, then target player mills a card. If a card with the chosen name was milled this way, you draw two cards. Otherwise, you draw a card.",
"count": 2
},
{
"id": "{f9ed455f-95cd-48ca-8b0d-4db259347bb6}",
"name": "Diminishing Returns",
"png": "https://cards.scryfall.io/png/front/f/9/f9ed455f-95cd-48ca-8b0d-4db259347bb6.png?1580013930",
"jpg": "https://cards.scryfall.io/small/front/f/9/f9ed455f-95cd-48ca-8b0d-4db259347bb6.jpg?1580013930",
"text": "Each player shuffles their hand and graveyard into their library. You exile the top ten cards of your library. Then each player draws up to seven cards.",
"count": 2
},
{
"id": "{78b384d3-3adf-493a-8b89-bfe68fd1c3e2}",
"name": "Vision Charm",
"png": "https://cards.scryfall.io/png/front/7/8/78b384d3-3adf-493a-8b89-bfe68fd1c3e2.png?1562277700",
"jpg": "https://cards.scryfall.io/small/front/7/8/78b384d3-3adf-493a-8b89-bfe68fd1c3e2.jpg?1562277700",
"text": "Choose one —\n• Target player mills four cards.\n• Choose a land type and a basic land type. Each land of the first chosen type becomes the second chosen type until end of turn.\n• Target artifact phases out. (While it's phased out, it's treated as though it doesn't exist. It phases in before its controller untaps during their next untap step.)",
"count": 2
},
{
"id": "{8798a4f1-34bb-449d-a8cc-faf8bda8e0ab}",
"name": "Crystal Spray",
"png": "https://cards.scryfall.io/png/front/8/7/8798a4f1-34bb-449d-a8cc-faf8bda8e0ab.png?1562922403",
"jpg": "https://cards.scryfall.io/small/front/8/7/8798a4f1-34bb-449d-a8cc-faf8bda8e0ab.jpg?1562922403",
"text": "Change the text of target spell or permanent by replacing all instances of one color word with another or one basic land type with another until end of turn.\nDraw a card.",
"count": 2
},
{
"id": "{63eb18e0-c723-4de4-8498-c5362c75b2b4}",
"name": "Halimar Depths",
"png": "https://cards.scryfall.io/png/front/6/3/63eb18e0-c723-4de4-8498-c5362c75b2b4.png?1726285434",
"jpg": "https://cards.scryfall.io/small/front/6/3/63eb18e0-c723-4de4-8498-c5362c75b2b4.jpg?1726285434",
"text": "Halimar Depths enters tapped.\nWhen Halimar Depths enters, look at the top three cards of your library, then put them back in any order.\n{T}: Add {U}.",
"count": 2
},
{
"id": "{a0f0c20c-184e-4d27-ae8b-933abb6fee0c}",
"name": "Metamorphose",
"png": "https://cards.scryfall.io/png/front/a/0/a0f0c20c-184e-4d27-ae8b-933abb6fee0c.png?1562533013",
"jpg": "https://cards.scryfall.io/small/front/a/0/a0f0c20c-184e-4d27-ae8b-933abb6fee0c.jpg?1562533013",
"text": "Put target permanent an opponent controls on top of its owner's library. That opponent may put an artifact, creature, enchantment, or land card from their hand onto the battlefield.",
"count": 2
},
{
"id": "{67652446-6d12-4e2a-bb51-ba685f2e79d1}",
"name": "Mystic Sanctuary",
"png": "https://cards.scryfall.io/png/front/6/7/67652446-6d12-4e2a-bb51-ba685f2e79d1.png?1706241201",
"jpg": "https://cards.scryfall.io/small/front/6/7/67652446-6d12-4e2a-bb51-ba685f2e79d1.jpg?1706241201",
"text": "({T}: Add {U}.)\nMystic Sanctuary enters tapped unless you control three or more other Islands.\nWhen Mystic Sanctuary enters untapped, you may put target instant or sorcery card from your graveyard on top of your library.",
"count": 2
},
{
"id": "{5833825f-aeb0-41bb-92a4-13e869765295}",
"name": "Lonely Sandbar",
"png": "https://cards.scryfall.io/png/front/5/8/5833825f-aeb0-41bb-92a4-13e869765295.png?1708054955",
"jpg": "https://cards.scryfall.io/small/front/5/8/5833825f-aeb0-41bb-92a4-13e869765295.jpg?1708054955",
"text": "Lonely Sandbar enters tapped.\n{T}: Add {U}.\nCycling {U} ({U}, Discard this card: Draw a card.)",
"count": 2
},
{
"id": "{224e8255-7bc6-44a2-86af-14f8446f4f77}",
"name": "Temple of Epiphany",
"png": "https://cards.scryfall.io/png/front/2/2/224e8255-7bc6-44a2-86af-14f8446f4f77.png?1730491248",
"jpg": "https://cards.scryfall.io/small/front/2/2/224e8255-7bc6-44a2-86af-14f8446f4f77.jpg?1730491248",
"text": "This land enters tapped.\nWhen this land enters, scry 1. (Look at the top card of your library. You may put that card on the bottom.)\n{T}: Add {U} or {R}.",
"count": 2
}
]

1
src/cards.json Symbolic link
View File

@ -0,0 +1 @@
/home/seoxi/Dev/rust/dandadan/src/cards_nuts.json

View File

@ -1,152 +1,202 @@
[
{
"3df927c0-9aa9-450b-ab2a-ae12c5489d57": {
"id": "{3df927c0-9aa9-450b-ab2a-ae12c5489d57}",
"name": "Supplant Form",
"png": "https://cards.scryfall.io/png/front/3/d/3df927c0-9aa9-450b-ab2a-ae12c5489d57.png?1562824437",
"jpg": "https://cards.scryfall.io/small/front/3/d/3df927c0-9aa9-450b-ab2a-ae12c5489d57.jpg?1562824437",
"text": "Return target creature to its owner's hand. You create a token that's a copy of that creature."
"text": "Return target creature to its owner's hand. You create a token that's a copy of that creature.",
"count": 2
},
"30202613-d05f-4f47-af97-d0b75ccac293": {
{
"id": "{30202613-d05f-4f47-af97-d0b75ccac293}",
"name": "Memory Lapse",
"png": "https://cards.scryfall.io/png/front/3/0/30202613-d05f-4f47-af97-d0b75ccac293.png?1634131658",
"jpg": "https://cards.scryfall.io/small/front/3/0/30202613-d05f-4f47-af97-d0b75ccac293.jpg?1634131658",
"text": "Counter target spell. If that spell is countered this way, put it on top of its owner's library instead of into that player's graveyard."
"text": "Counter target spell. If that spell is countered this way, put it on top of its owner's library instead of into that player's graveyard.",
"count": 8
},
"ad88e5ee-0eee-47af-a7b4-9bac044e1c8c": {
{
"id": "{ad88e5ee-0eee-47af-a7b4-9bac044e1c8c}",
"name": "Accumulated Knowledge",
"png": "https://cards.scryfall.io/png/front/a/d/ad88e5ee-0eee-47af-a7b4-9bac044e1c8c.png?1562439718",
"jpg": "https://cards.scryfall.io/small/front/a/d/ad88e5ee-0eee-47af-a7b4-9bac044e1c8c.jpg?1562439718",
"text": "Draw a card, then draw cards equal to the number of cards named Accumulated Knowledge in all graveyards."
"text": "Draw a card, then draw cards equal to the number of cards named Accumulated Knowledge in all graveyards.",
"count": 4
},
"806e5536-103b-4d6c-83b4-8659a55b25b5": {
{
"id": "{806e5536-103b-4d6c-83b4-8659a55b25b5}",
"name": "Mystic Retrieval",
"png": "https://cards.scryfall.io/png/front/8/0/806e5536-103b-4d6c-83b4-8659a55b25b5.png?1736467785",
"jpg": "https://cards.scryfall.io/small/front/8/0/806e5536-103b-4d6c-83b4-8659a55b25b5.jpg?1736467785",
"text": "Return target instant or sorcery card from your graveyard to your hand.\nFlashback {2}{R} (You may cast this card from your graveyard for its flashback cost. Then exile it.)"
"text": "Return target instant or sorcery card from your graveyard to your hand.\nFlashback {2}{R} (You may cast this card from your graveyard for its flashback cost. Then exile it.)",
"count": 2
},
"36fa9a0b-b0c9-43ea-ba11-99d7982f974e": {
{
"id": "{36fa9a0b-b0c9-43ea-ba11-99d7982f974e}",
"name": "Mystical Tutor",
"png": "https://cards.scryfall.io/png/front/3/6/36fa9a0b-b0c9-43ea-ba11-99d7982f974e.png?1675199375",
"jpg": "https://cards.scryfall.io/small/front/3/6/36fa9a0b-b0c9-43ea-ba11-99d7982f974e.jpg?1675199375",
"text": "Search your library for an instant or sorcery card, reveal it, then shuffle and put that card on top."
"text": "Search your library for an instant or sorcery card, reveal it, then shuffle and put that card on top.",
"count": 2
},
"21fe2f1b-bfd1-4682-ae23-069300de3791": {
{
"id": "{21fe2f1b-bfd1-4682-ae23-069300de3791}",
"name": "Svyelunite Temple",
"png": "https://cards.scryfall.io/png/front/2/1/21fe2f1b-bfd1-4682-ae23-069300de3791.png?1562867851",
"jpg": "https://cards.scryfall.io/small/front/2/1/21fe2f1b-bfd1-4682-ae23-069300de3791.jpg?1562867851",
"text": "Svyelunite Temple enters tapped.\n{T}: Add {U}.\n{T}, Sacrifice Svyelunite Temple: Add {U}{U}."
"text": "Svyelunite Temple enters tapped.\n{T}: Add {U}.\n{T}, Sacrifice Svyelunite Temple: Add {U}{U}.",
"count": 2
},
"8beb987c-1b67-4a4e-ae71-58547afad2a0": {
{
"id": "{8beb987c-1b67-4a4e-ae71-58547afad2a0}",
"name": "Brainstorm",
"png": "https://cards.scryfall.io/png/front/8/b/8beb987c-1b67-4a4e-ae71-58547afad2a0.png?1726284649",
"jpg": "https://cards.scryfall.io/small/front/8/b/8beb987c-1b67-4a4e-ae71-58547afad2a0.jpg?1726284649",
"text": "Draw three cards, then put two cards from your hand on top of your library in any order."
"text": "Draw three cards, then put two cards from your hand on top of your library in any order.",
"count": 2
},
"c548d140-3d81-4b33-9985-87703d316a83": {
{
"id": "{c548d140-3d81-4b33-9985-87703d316a83}",
"name": "Dance of the Skywise",
"png": "https://cards.scryfall.io/png/front/c/5/c548d140-3d81-4b33-9985-87703d316a83.png?1562792779",
"jpg": "https://cards.scryfall.io/small/front/c/5/c548d140-3d81-4b33-9985-87703d316a83.jpg?1562792779",
"text": "Until end of turn, target creature you control becomes a blue Dragon Illusion with base power and toughness 4/4, loses all abilities, and gains flying."
"text": "Until end of turn, target creature you control becomes a blue Dragon Illusion with base power and toughness 4/4, loses all abilities, and gains flying.",
"count": 2
},
"7132999f-6e2d-4689-8131-7b12076a348d": {
{
"id": "{7132999f-6e2d-4689-8131-7b12076a348d}",
"name": "Island",
"png": "https://cards.scryfall.io/png/front/7/1/7132999f-6e2d-4689-8131-7b12076a348d.png?1655495395",
"jpg": "https://cards.scryfall.io/small/front/7/1/7132999f-6e2d-4689-8131-7b12076a348d.jpg?1655495395",
"text": "({T}: Add {U}.)"
"text": "({T}: Add {U}.)",
"count": 18
},
"7ca8a427-5c20-4650-bbb5-9895e4f2c009": {
{
"id": "{7ca8a427-5c20-4650-bbb5-9895e4f2c009}",
"name": "Ray of Command",
"png": "https://cards.scryfall.io/png/front/7/c/7ca8a427-5c20-4650-bbb5-9895e4f2c009.png?1592754536",
"jpg": "https://cards.scryfall.io/small/front/7/c/7ca8a427-5c20-4650-bbb5-9895e4f2c009.jpg?1592754536",
"text": "Untap target creature an opponent controls and gain control of it until end of turn. That creature gains haste until end of turn. When you lose control of the creature, tap it."
"text": "Untap target creature an opponent controls and gain control of it until end of turn. That creature gains haste until end of turn. When you lose control of the creature, tap it.",
"count": 2
},
"2dc0bafd-debc-4b62-9fe0-56b4aad02484": {
{
"id": "{2dc0bafd-debc-4b62-9fe0-56b4aad02484}",
"name": "Unsubstantiate",
"png": "https://cards.scryfall.io/png/front/2/d/2dc0bafd-debc-4b62-9fe0-56b4aad02484.png?1594735888",
"jpg": "https://cards.scryfall.io/small/front/2/d/2dc0bafd-debc-4b62-9fe0-56b4aad02484.jpg?1594735888",
"text": "Return target spell or creature to its owner's hand."
"text": "Return target spell or creature to its owner's hand.",
"count": 2
},
"ac2e32d0-f172-4934-9d73-1bc2ab86586e": {
{
"id": "{ac2e32d0-f172-4934-9d73-1bc2ab86586e}",
"name": "Dandân",
"png": "https://cards.scryfall.io/png/front/a/c/ac2e32d0-f172-4934-9d73-1bc2ab86586e.png?1562781784",
"jpg": "https://cards.scryfall.io/small/front/a/c/ac2e32d0-f172-4934-9d73-1bc2ab86586e.jpg?1562781784",
"text": "Dandân can't attack unless defending player controls an Island.\nWhen you control no Islands, sacrifice Dandân."
"text": "Dandân can't attack unless defending player controls an Island.\nWhen you control no Islands, sacrifice Dandân.",
"count": 10
},
"692a5bfa-9a50-4610-acd7-19fc0a53f798": {
{
"id": "{692a5bfa-9a50-4610-acd7-19fc0a53f798}",
"name": "Mind Bend",
"png": "https://cards.scryfall.io/png/front/6/9/692a5bfa-9a50-4610-acd7-19fc0a53f798.png?1562549129",
"jpg": "https://cards.scryfall.io/small/front/6/9/692a5bfa-9a50-4610-acd7-19fc0a53f798.jpg?1562549129",
"text": "Change the text of target permanent by replacing all instances of one color word with another or one basic land type with another. (For example, you may change \"nonblack creature\" to \"nongreen creature\" or \"forestwalk\" to \"islandwalk.\" This effect lasts indefinitely.)"
"text": "Change the text of target permanent by replacing all instances of one color word with another or one basic land type with another. (For example, you may change \"nonblack creature\" to \"nongreen creature\" or \"forestwalk\" to \"islandwalk.\" This effect lasts indefinitely.)",
"count": 2
},
"a340af37-c0a7-4f26-974b-95397b5c32f7": {
{
"id": "{a340af37-c0a7-4f26-974b-95397b5c32f7}",
"name": "Remote Isle",
"png": "https://cards.scryfall.io/png/front/a/3/a340af37-c0a7-4f26-974b-95397b5c32f7.png?1709139228",
"jpg": "https://cards.scryfall.io/small/front/a/3/a340af37-c0a7-4f26-974b-95397b5c32f7.jpg?1709139228",
"text": "Remote Isle enters tapped.\n{T}: Add {U}.\nCycling {2} ({2}, Discard this card: Draw a card.)"
"text": "Remote Isle enters tapped.\n{T}: Add {U}.\nCycling {2} ({2}, Discard this card: Draw a card.)",
"count": 2
},
"8eafb2bb-58bf-4c6b-ae8f-91bcea12c7d2": {
{
"id": "{8eafb2bb-58bf-4c6b-ae8f-91bcea12c7d2}",
"name": "Insidious Will",
"png": "https://cards.scryfall.io/png/front/8/e/8eafb2bb-58bf-4c6b-ae8f-91bcea12c7d2.png?1576381260",
"jpg": "https://cards.scryfall.io/small/front/8/e/8eafb2bb-58bf-4c6b-ae8f-91bcea12c7d2.jpg?1576381260",
"text": "Choose one —\n• Counter target spell.\n• You may choose new targets for target spell.\n• Copy target instant or sorcery spell. You may choose new targets for the copy."
"text": "Choose one —\n• Counter target spell.\n• You may choose new targets for target spell.\n• Copy target instant or sorcery spell. You may choose new targets for the copy.",
"count": 2
},
"bfac9395-7ca5-48dd-ab83-7c26ada12f61": {
{
"id": "{bfac9395-7ca5-48dd-ab83-7c26ada12f61}",
"name": "Izzet Boilerworks",
"png": "https://cards.scryfall.io/png/front/b/f/bfac9395-7ca5-48dd-ab83-7c26ada12f61.png?1712355049",
"jpg": "https://cards.scryfall.io/small/front/b/f/bfac9395-7ca5-48dd-ab83-7c26ada12f61.jpg?1712355049",
"text": "Izzet Boilerworks enters tapped.\nWhen Izzet Boilerworks enters, return a land you control to its owner's hand.\n{T}: Add {U}{R}."
"text": "Izzet Boilerworks enters tapped.\nWhen Izzet Boilerworks enters, return a land you control to its owner's hand.\n{T}: Add {U}{R}.",
"count": 2
},
"349ac7e6-af38-4dc3-abfe-369564c75630": {
{
"id": "{349ac7e6-af38-4dc3-abfe-369564c75630}",
"name": "Predict",
"png": "https://cards.scryfall.io/png/front/3/4/349ac7e6-af38-4dc3-abfe-369564c75630.png?1592710621",
"jpg": "https://cards.scryfall.io/small/front/3/4/349ac7e6-af38-4dc3-abfe-369564c75630.jpg?1592710621",
"text": "Choose a card name, then target player mills a card. If a card with the chosen name was milled this way, you draw two cards. Otherwise, you draw a card."
"text": "Choose a card name, then target player mills a card. If a card with the chosen name was milled this way, you draw two cards. Otherwise, you draw a card.",
"count": 2
},
"f9ed455f-95cd-48ca-8b0d-4db259347bb6": {
{
"id": "{f9ed455f-95cd-48ca-8b0d-4db259347bb6}",
"name": "Diminishing Returns",
"png": "https://cards.scryfall.io/png/front/f/9/f9ed455f-95cd-48ca-8b0d-4db259347bb6.png?1580013930",
"jpg": "https://cards.scryfall.io/small/front/f/9/f9ed455f-95cd-48ca-8b0d-4db259347bb6.jpg?1580013930",
"text": "Each player shuffles their hand and graveyard into their library. You exile the top ten cards of your library. Then each player draws up to seven cards."
"text": "Each player shuffles their hand and graveyard into their library. You exile the top ten cards of your library. Then each player draws up to seven cards.",
"count": 2
},
"78b384d3-3adf-493a-8b89-bfe68fd1c3e2": {
{
"id": "{78b384d3-3adf-493a-8b89-bfe68fd1c3e2}",
"name": "Vision Charm",
"png": "https://cards.scryfall.io/png/front/7/8/78b384d3-3adf-493a-8b89-bfe68fd1c3e2.png?1562277700",
"jpg": "https://cards.scryfall.io/small/front/7/8/78b384d3-3adf-493a-8b89-bfe68fd1c3e2.jpg?1562277700",
"text": "Choose one —\n• Target player mills four cards.\n• Choose a land type and a basic land type. Each land of the first chosen type becomes the second chosen type until end of turn.\n• Target artifact phases out. (While it's phased out, it's treated as though it doesn't exist. It phases in before its controller untaps during their next untap step.)"
"text": "Choose one —\n• Target player mills four cards.\n• Choose a land type and a basic land type. Each land of the first chosen type becomes the second chosen type until end of turn.\n• Target artifact phases out. (While it's phased out, it's treated as though it doesn't exist. It phases in before its controller untaps during their next untap step.)",
"count": 2
},
"8798a4f1-34bb-449d-a8cc-faf8bda8e0ab": {
{
"id": "{8798a4f1-34bb-449d-a8cc-faf8bda8e0ab}",
"name": "Crystal Spray",
"png": "https://cards.scryfall.io/png/front/8/7/8798a4f1-34bb-449d-a8cc-faf8bda8e0ab.png?1562922403",
"jpg": "https://cards.scryfall.io/small/front/8/7/8798a4f1-34bb-449d-a8cc-faf8bda8e0ab.jpg?1562922403",
"text": "Change the text of target spell or permanent by replacing all instances of one color word with another or one basic land type with another until end of turn.\nDraw a card."
"text": "Change the text of target spell or permanent by replacing all instances of one color word with another or one basic land type with another until end of turn.\nDraw a card.",
"count": 2
},
"63eb18e0-c723-4de4-8498-c5362c75b2b4": {
{
"id": "{63eb18e0-c723-4de4-8498-c5362c75b2b4}",
"name": "Halimar Depths",
"png": "https://cards.scryfall.io/png/front/6/3/63eb18e0-c723-4de4-8498-c5362c75b2b4.png?1726285434",
"jpg": "https://cards.scryfall.io/small/front/6/3/63eb18e0-c723-4de4-8498-c5362c75b2b4.jpg?1726285434",
"text": "Halimar Depths enters tapped.\nWhen Halimar Depths enters, look at the top three cards of your library, then put them back in any order.\n{T}: Add {U}."
"text": "Halimar Depths enters tapped.\nWhen Halimar Depths enters, look at the top three cards of your library, then put them back in any order.\n{T}: Add {U}.",
"count": 2
},
"a0f0c20c-184e-4d27-ae8b-933abb6fee0c": {
{
"id": "{a0f0c20c-184e-4d27-ae8b-933abb6fee0c}",
"name": "Metamorphose",
"png": "https://cards.scryfall.io/png/front/a/0/a0f0c20c-184e-4d27-ae8b-933abb6fee0c.png?1562533013",
"jpg": "https://cards.scryfall.io/small/front/a/0/a0f0c20c-184e-4d27-ae8b-933abb6fee0c.jpg?1562533013",
"text": "Put target permanent an opponent controls on top of its owner's library. That opponent may put an artifact, creature, enchantment, or land card from their hand onto the battlefield."
"text": "Put target permanent an opponent controls on top of its owner's library. That opponent may put an artifact, creature, enchantment, or land card from their hand onto the battlefield.",
"count": 2
},
"67652446-6d12-4e2a-bb51-ba685f2e79d1": {
{
"id": "{67652446-6d12-4e2a-bb51-ba685f2e79d1}",
"name": "Mystic Sanctuary",
"png": "https://cards.scryfall.io/png/front/6/7/67652446-6d12-4e2a-bb51-ba685f2e79d1.png?1706241201",
"jpg": "https://cards.scryfall.io/small/front/6/7/67652446-6d12-4e2a-bb51-ba685f2e79d1.jpg?1706241201",
"text": "({T}: Add {U}.)\nMystic Sanctuary enters tapped unless you control three or more other Islands.\nWhen Mystic Sanctuary enters untapped, you may put target instant or sorcery card from your graveyard on top of your library."
"text": "({T}: Add {U}.)\nMystic Sanctuary enters tapped unless you control three or more other Islands.\nWhen Mystic Sanctuary enters untapped, you may put target instant or sorcery card from your graveyard on top of your library.",
"count": 2
},
"5833825f-aeb0-41bb-92a4-13e869765295": {
{
"id": "{5833825f-aeb0-41bb-92a4-13e869765295}",
"name": "Lonely Sandbar",
"png": "https://cards.scryfall.io/png/front/5/8/5833825f-aeb0-41bb-92a4-13e869765295.png?1708054955",
"jpg": "https://cards.scryfall.io/small/front/5/8/5833825f-aeb0-41bb-92a4-13e869765295.jpg?1708054955",
"text": "Lonely Sandbar enters tapped.\n{T}: Add {U}.\nCycling {U} ({U}, Discard this card: Draw a card.)"
"text": "Lonely Sandbar enters tapped.\n{T}: Add {U}.\nCycling {U} ({U}, Discard this card: Draw a card.)",
"count": 2
},
"224e8255-7bc6-44a2-86af-14f8446f4f77": {
{
"id": "{224e8255-7bc6-44a2-86af-14f8446f4f77}",
"name": "Temple of Epiphany",
"png": "https://cards.scryfall.io/png/front/2/2/224e8255-7bc6-44a2-86af-14f8446f4f77.png?1730491248",
"jpg": "https://cards.scryfall.io/small/front/2/2/224e8255-7bc6-44a2-86af-14f8446f4f77.jpg?1730491248",
"text": "This land enters tapped.\nWhen this land enters, scry 1. (Look at the top card of your library. You may put that card on the bottom.)\n{T}: Add {U} or {R}."
}
"text": "This land enters tapped.\nWhen this land enters, scry 1. (Look at the top card of your library. You may put that card on the bottom.)\n{T}: Add {U} or {R}.",
"count": 2
}
]

1
src/cards_nuts.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -47,7 +47,7 @@ enum Event {
Shuffle(Player),
Draw(Player, usize),
Pass(Player, Player),
ChangeLifeTotal(Player, i32, i32),
ChangeLifeTotal(Player, isize, isize),
FadeFromHand(Player),
PlayFromHand(Player),
Bounce(Player),
@ -69,6 +69,15 @@ struct CountedEvent {
event: Event,
}
macro_rules! gen_event {
($list:expr,$event:expr) => {
$list.push(CountedEvent {
id: $list.len(),
event: $event,
})
};
}
#[derive(Clone, Debug)]
pub struct GameState {
deck: VecDeque<Uuid>,
@ -76,7 +85,7 @@ pub struct GameState {
shadow_realm: Vec<Uuid>,
play: HashMap<Uuid, InPlay>,
hands: Vec<Hand>,
life_totals: Vec<i32>,
life_totals: Vec<isize>,
turn_player: Player,
events: Vec<CountedEvent>,
}
@ -87,7 +96,7 @@ pub struct OnePlayerGameState {
shadow_realm: Vec<Uuid>,
play: Vec<InPlay>,
hand: Vec<Uuid>,
life_totals: Vec<i32>,
life_totals: Vec<isize>,
turn_player: Player,
opponent_cards_in_hand: usize,
you: Player,
@ -150,55 +159,60 @@ pub fn new() -> GameState {
}
}
pub fn draw(game_state: &mut GameState, count: usize, player: Player) {
pub fn draw(game_state: &mut GameState, count: usize, player: Player) -> Result<(), String> {
let player_hand = match player {
Player::A => &mut game_state.hands[0],
_ => &mut game_state.hands[1],
Player::B => &mut game_state.hands[1],
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Draw(player.clone(), count.clone()),
});
player_hand.cards.extend_from_slice(
game_state
.deck
.split_off(game_state.deck.len() - count)
.make_contiguous(),
let remaining_cards =
std::cmp::max(0, game_state.deck.len() as isize - count as isize) as usize;
gen_event!(
game_state.events,
Event::Draw(player.clone(), count.clone())
);
}
pub fn yoink(game_state: &mut GameState, deck_index: usize, player: Player) {
let player_hand = match player {
Player::A => &mut game_state.hands[0],
_ => &mut game_state.hands[1],
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Yoink(player.clone()),
});
player_hand
.cards
.push(game_state.deck.remove(deck_index).unwrap());
.extend_from_slice(game_state.deck.split_off(remaining_cards).make_contiguous());
Ok(())
}
pub fn yoink_mill(game_state: &mut GameState, deck_index: usize, shadow: bool) {
let card = game_state.deck.remove(deck_index).unwrap();
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::YoinkMill(card.clone()),
});
pub fn yoink(game_state: &mut GameState, deck_index: usize, player: Player) -> Result<(), String> {
let player_hand = match player {
Player::A => &mut game_state.hands[0],
Player::B => &mut game_state.hands[1],
};
gen_event!(game_state.events, Event::Yoink(player.clone()));
match game_state.deck.remove(deck_index) {
Some(card) => Ok(player_hand.cards.push(card)),
None => Err(format!("Yoink index out of bounds: {}", deck_index)),
}
}
pub fn yoink_mill(
game_state: &mut GameState,
deck_index: usize,
shadow: bool,
) -> Result<(), String> {
let card = match game_state.deck.remove(deck_index) {
Some(card) => card,
None => {
return Err(format!(
"Yoinkmill index out of bounds: {} (shadow: {})",
deck_index, shadow
))
}
};
gen_event!(game_state.events, Event::YoinkMill(card.clone()));
if shadow {
game_state.shadow_realm.push(card);
} else {
game_state.discard_pile.push(card);
}
Ok(())
}
pub fn shuffle(game_state: &mut GameState, player: Player) {
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Shuffle(player),
});
gen_event!(game_state.events, Event::Shuffle(player));
game_state.deck.make_contiguous().shuffle(&mut rng());
}
@ -216,22 +230,22 @@ pub fn pass(game_state: &mut GameState) {
Player::A => Player::B,
Player::B => Player::A,
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Pass(*current_player, new_player.clone()),
});
gen_event!(
game_state.events,
Event::Pass(*current_player, new_player.clone())
);
game_state.turn_player = new_player;
}
pub fn change_life(game_state: &mut GameState, diff: i32, player: Player) {
pub fn change_life(game_state: &mut GameState, diff: isize, player: Player) {
let mut player_life = match player {
Player::A => game_state.life_totals[0].clone(),
Player::B => game_state.life_totals[1].clone(),
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::ChangeLifeTotal(player, player_life.clone(), player_life.clone() + diff),
});
gen_event!(
game_state.events,
Event::ChangeLifeTotal(player, player_life.clone(), player_life.clone() + diff)
);
player_life += diff;
match player {
Player::A => game_state.life_totals[0] = player_life,
@ -239,32 +253,43 @@ pub fn change_life(game_state: &mut GameState, diff: i32, player: Player) {
};
}
pub fn fade_from_hand(game_state: &mut GameState, hand_index: usize, player: Player, bottom: bool) {
pub fn fade_from_hand(
game_state: &mut GameState,
hand_index: usize,
player: Player,
bottom: bool,
) -> Result<(), String> {
let player_hand = match player {
Player::A => &mut game_state.hands[0],
Player::B => &mut game_state.hands[1],
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::FadeFromHand(player.clone()),
});
gen_event!(game_state.events, Event::FadeFromHand(player.clone()));
if None == player_hand.cards.get(hand_index) {
return Err(format!("Fade index out of bounds: {}", hand_index));
}
let card = player_hand.cards.remove(hand_index);
if bottom {
game_state.deck.push_front(card);
} else {
game_state.deck.push_back(card);
}
Ok(())
}
pub fn play_from_hand(game_state: &mut GameState, hand_index: usize, player: Player) {
pub fn play_from_hand(
game_state: &mut GameState,
hand_index: usize,
player: Player,
) -> Result<(), String> {
let player_hand = match player {
Player::A => &mut game_state.hands[0],
Player::B => &mut game_state.hands[1],
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::PlayFromHand(player.clone()),
});
gen_event!(game_state.events, Event::PlayFromHand(player.clone()));
if None == player_hand.cards.get(hand_index) {
return Err(format!("Play index out of bounds: {}", hand_index));
}
let card = player_hand.cards.remove(hand_index);
let play_uuid = Uuid::new_v4();
game_state.play.insert(
@ -278,95 +303,138 @@ pub fn play_from_hand(game_state: &mut GameState, hand_index: usize, player: Pla
play_id: play_uuid,
},
);
Ok(())
}
pub fn bounce(game_state: &mut GameState, play_id: Uuid) {
let played_card = game_state.play.remove(&play_id).unwrap();
pub fn bounce(game_state: &mut GameState, play_id: Uuid) -> Result<(), String> {
let played_card = match game_state.play.remove(&play_id) {
Some(played_card) => played_card,
None => return Err(format!("Nonexistant play id: {}", play_id)),
};
let player_hand = match played_card.owner {
Player::A => &mut game_state.hands[0],
Player::B => &mut game_state.hands[1],
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Bounce(played_card.owner),
});
player_hand.cards.push(played_card.id);
gen_event!(game_state.events, Event::Bounce(played_card.owner));
Ok(player_hand.cards.push(played_card.id))
}
pub fn tap(game_state: &mut GameState, play_id: Uuid) {
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Tap(play_id.clone()),
});
let played_card = game_state.play.get_mut(&play_id).unwrap();
pub fn tap(game_state: &mut GameState, play_id: Uuid) -> Result<(), String> {
gen_event!(game_state.events, Event::Tap(play_id.clone()));
match game_state.play.get_mut(&play_id) {
Some(played_card) => {
played_card.tapped = !played_card.tapped;
Ok(())
}
None => return Err(format!("Nonexistant play id: {}", play_id)),
}
}
pub fn move_played_card(game_state: &mut GameState, play_id: Uuid, position_x: u8, position_y: u8) {
if let Some(played_card) = game_state.play.get_mut(&play_id) {
pub fn move_played_card(
game_state: &mut GameState,
play_id: Uuid,
position_x: u8,
position_y: u8,
) -> Result<(), String> {
// no event made, intentionally
match game_state.play.get_mut(&play_id) {
Some(played_card) => {
played_card.position_x = position_x;
played_card.position_y = position_y;
Ok(())
}
None => return Err(format!("Nonexistant play id: {}", play_id)),
}
}
pub fn discard(game_state: &mut GameState, hand_index: usize, player: Player, shadow: bool) {
pub fn discard(
game_state: &mut GameState,
hand_index: usize,
player: Player,
shadow: bool,
) -> Result<(), String> {
let player_hand = match player {
Player::A => &mut game_state.hands[0],
Player::B => &mut game_state.hands[1],
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Discard(player.clone()),
});
gen_event!(game_state.events, Event::Discard(player.clone()));
if None == player_hand.cards.get(hand_index) {
return Err(format!("Discard index out of bounds: {}", hand_index));
}
let card = player_hand.cards.remove(hand_index);
if shadow {
game_state.shadow_realm.push(card);
} else {
game_state.discard_pile.push(card);
}
Ok(())
}
pub fn undiscard(game_state: &mut GameState, pile_index: usize, player: Player, shadow: bool) {
pub fn undiscard(
game_state: &mut GameState,
pile_index: usize,
player: Player,
shadow: bool,
) -> Result<(), String> {
let player_hand = match player {
Player::A => &mut game_state.hands[0],
Player::B => &mut game_state.hands[1],
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Undiscard(player.clone()),
});
let card = if shadow {
game_state.shadow_realm.remove(pile_index)
let pile = if shadow {
&mut game_state.shadow_realm
} else {
game_state.discard_pile.remove(pile_index)
&mut game_state.discard_pile
};
player_hand.cards.push(card);
if None == pile.get(pile_index) {
return Err(format!("Discard index out of bounds: {}", pile_index));
}
gen_event!(game_state.events, Event::Undiscard(player.clone()));
player_hand.cards.push(pile.remove(pile_index));
Ok(())
}
pub fn kill(game_state: &mut GameState, play_id: Uuid, shadow: bool) {
let played_card = game_state.play.remove(&play_id).unwrap();
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Kill(played_card.id.clone(), shadow),
});
pub fn kill(game_state: &mut GameState, play_id: Uuid, shadow: bool) -> Result<(), String> {
let played_card = match game_state.play.remove(&play_id) {
Some(played_card) => played_card,
None => return Err(format!("Nonexistant play id: {}", play_id)),
};
gen_event!(
game_state.events,
Event::Kill(played_card.id.clone(), shadow)
);
if shadow {
game_state.shadow_realm.push(played_card.id);
} else {
game_state.discard_pile.push(played_card.id);
}
Ok(())
}
pub fn unkill(game_state: &mut GameState, player: Player, pile_index: usize, shadow: bool) {
let card = if shadow {
game_state.shadow_realm.remove(pile_index)
pub fn unkill(
game_state: &mut GameState,
player: Player,
pile_index: usize,
shadow: bool,
) -> Result<(), String> {
let pile = if shadow {
&mut game_state.shadow_realm
} else {
game_state.discard_pile.remove(pile_index)
&mut game_state.discard_pile
};
if None == pile.get(pile_index) {
let pile_name = if shadow {
"shadow realm"
} else {
"discard pile"
};
return Err(format!(
"Transfer index out of bounds: {} ({})",
pile_index, pile_name
));
}
let card = pile.remove(pile_index);
gen_event!(game_state.events, Event::Unkill(card, shadow));
let play_uuid = Uuid::new_v4();
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::Unkill(card, shadow),
});
game_state.play.insert(
play_uuid,
InPlay {
@ -378,31 +446,43 @@ pub fn unkill(game_state: &mut GameState, player: Player, pile_index: usize, sha
play_id: play_uuid,
},
);
Ok(())
}
pub fn transfer_dead_card(game_state: &mut GameState, pile_index: usize, shadow_to_discard: bool) {
let card_id = if shadow_to_discard {
let card = game_state.shadow_realm.remove(pile_index);
let ret = card.clone();
game_state.discard_pile.push(card);
ret
pub fn transfer_dead_card(
game_state: &mut GameState,
pile_index: usize,
shadow_to_discard: bool,
) -> Result<(), String> {
let (source, target) = if shadow_to_discard {
(&mut game_state.shadow_realm, &mut game_state.discard_pile)
} else {
let card = game_state.discard_pile.remove(pile_index);
let ret = card.clone();
game_state.shadow_realm.push(card);
ret
(&mut game_state.discard_pile, &mut game_state.shadow_realm)
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::TransferDeadCard(card_id, shadow_to_discard),
});
if None == source.get(pile_index) {
let direction = if shadow_to_discard {
"shadow realm -> discard pile"
} else {
"discard pile -> shadow realm"
};
return Err(format!(
"Transfer index out of bounds: {} ({})",
pile_index, direction
));
}
let card = source.remove(pile_index);
let card_id = card.clone();
gen_event!(
game_state.events,
Event::TransferDeadCard(card_id, shadow_to_discard)
);
target.push(card);
Ok(())
}
pub fn untap_all(game_state: &mut GameState, player: Player) {
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::UntapAll(player),
});
gen_event!(game_state.events, Event::UntapAll(player));
for (_, card) in game_state.play.iter_mut() {
if card.owner == player {
card.tapped = false;
@ -411,10 +491,7 @@ pub fn untap_all(game_state: &mut GameState, player: Player) {
}
pub fn get_deck(game_state: &mut GameState, player: Player) -> String {
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::ViewDeck(player),
});
gen_event!(game_state.events, Event::ViewDeck(player));
let deck_copy = game_state.deck.clone();
serde_json::to_string(&deck_copy).unwrap()
}

View File

@ -4,26 +4,82 @@ mod game;
use game::GameState;
use game::Player;
use rocket::fs::{relative, FileServer};
use rocket::http::{ContentType, Status};
use rocket::response::content;
use rocket::response::status::BadRequest;
use rocket::State;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use uuid::{uuid, Uuid};
macro_rules! assert_player {
($player_uuids:expr,$uuid:expr) => {
match $player_uuids.map.get(&$uuid) {
Some(_) => (),
None => {
return (
Status::Unauthorized,
(ContentType::Plain, format!("Invalid player {}.", $uuid)),
)
}
}
};
}
macro_rules! get_player {
($player_uuids:expr,$uuid:expr) => {
match $player_uuids.map.get(&$uuid) {
Some(player) => player,
None => {
return (
Status::Unauthorized,
(ContentType::Plain, format!("Invalid player {}.", $uuid)),
)
}
}
};
}
macro_rules! respond_ok {
() => {
(Status::Ok, (ContentType::Plain, "Ok!".to_string()))
};
}
macro_rules! respond {
($state:expr) => {
match $state {
Ok(()) => respond_ok!(),
Err(err_string) => (Status::BadRequest, (ContentType::Plain, err_string)),
}
};
}
macro_rules! unlock_state {
($arc:expr,$mutex:ident,$name:ident) => {
let $mutex = Arc::clone(&$arc.state);
let $name = $mutex.lock().unwrap();
};
}
macro_rules! unlock_state_mut {
($arc:expr,$mutex:ident,$name:ident) => {
let $mutex = Arc::clone(&$arc.state);
let mut $name = $mutex.lock().unwrap();
};
}
#[get("/")]
fn index(player_uuids: &State<PlayerUuids>) -> content::RawHtml<String> {
content::RawHtml(format!(
"<a href=\"localhost:8000/{}/\">localhost:8000/{}</a><br /><a href=\"localhost:8000/{}/\">localhost:8000/{}</a>",
"<a href=\"/{}/\">/{}</a><br /><a href=\"/{}/\">/{}</a>",
player_uuids.a, player_uuids.a, player_uuids.b, player_uuids.b
))
}
#[get("/get_events")]
fn get_events(game_state_arc: &State<ArcMutexGameState>) -> String {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let game_state = game_state_mutex.lock().unwrap();
format!("{}", game::get_events(&game_state))
fn get_events(game_state_arc: &State<ArcMutexGameState>) -> content::RawJson<String> {
unlock_state!(game_state_arc, mutex, game_state);
content::RawJson(format!("{}", game::get_events(&game_state)))
}
#[post("/<uuid>/shuffle")]
@ -31,15 +87,11 @@ fn shuffle(
uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
game::shuffle(&mut game_state, player.clone());
Ok(format!("Deck Shuffled!"))
respond_ok!()
}
#[post("/<uuid>/pass")]
@ -47,15 +99,11 @@ fn pass(
uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
game::pass(&mut game_state);
Ok(format!("{}", game::get_events(&game_state)))
respond_ok!()
}
#[post("/<uuid>/bounce/<play_id>")]
@ -64,15 +112,10 @@ fn bounce(
play_id: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::bounce(&mut game_state, play_id);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::bounce(&mut game_state, play_id))
}
#[post("/<uuid>/move/<play_id>/<x>/<y>")]
@ -83,15 +126,10 @@ fn move_card(
y: u8,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::move_played_card(&mut game_state, play_id, x, y);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::move_played_card(&mut game_state, play_id, x, y))
}
#[post("/<uuid>/tap/<play_id>")]
@ -100,15 +138,10 @@ fn tap(
play_id: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::tap(&mut game_state, play_id);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::tap(&mut game_state, play_id))
}
#[post("/<uuid>/play/<index>")]
@ -117,15 +150,10 @@ fn play(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::play_from_hand(&mut game_state, index, player.clone());
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::play_from_hand(&mut game_state, index, player.clone()))
}
#[post("/<uuid>/unkill/<index>")]
@ -134,15 +162,10 @@ fn unkill(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::unkill(&mut game_state, player.clone(), index, false);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::unkill(&mut game_state, player.clone(), index, false))
}
#[post("/<uuid>/unbanish/<index>")]
@ -151,15 +174,10 @@ fn unbanish(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::unkill(&mut game_state, player.clone(), index, true);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::unkill(&mut game_state, player.clone(), index, true))
}
#[post("/<uuid>/discard/<index>")]
@ -168,15 +186,10 @@ fn discard(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::discard(&mut game_state, index, player.clone(), false);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::discard(&mut game_state, index, player.clone(), false))
}
#[post("/<uuid>/forget/<index>")]
@ -185,15 +198,10 @@ fn forget(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::discard(&mut game_state, index, player.clone(), true);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::discard(&mut game_state, index, player.clone(), true))
}
#[post("/<uuid>/kill/<play_id>")]
@ -202,15 +210,10 @@ fn kill(
play_id: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::kill(&mut game_state, play_id, false);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::kill(&mut game_state, play_id, false))
}
#[post("/<uuid>/banish/<play_id>")]
@ -219,15 +222,10 @@ fn banish(
play_id: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::kill(&mut game_state, play_id, true);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::kill(&mut game_state, play_id, true))
}
#[post("/<uuid>/unshadow/<index>")]
@ -236,15 +234,10 @@ fn unshadow(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::transfer_dead_card(&mut game_state, index, true);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::transfer_dead_card(&mut game_state, index, true))
}
#[post("/<uuid>/yoink/<index>")]
@ -253,15 +246,10 @@ fn yoink(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::yoink(&mut game_state, index, player.clone());
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::yoink(&mut game_state, index, player.clone()))
}
#[post("/<uuid>/yoink_mill/<index>")]
@ -270,15 +258,10 @@ fn yoink_mill(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::yoink_mill(&mut game_state, index, false);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::yoink_mill(&mut game_state, index, false))
}
#[post("/<uuid>/yoink_xmill/<index>")]
@ -287,15 +270,10 @@ fn yoink_xmill(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::yoink_mill(&mut game_state, index, true);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::yoink_mill(&mut game_state, index, true))
}
#[post("/<uuid>/undiscard/<index>")]
@ -304,15 +282,15 @@ fn undiscard(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::undiscard(&mut game_state, index, player.clone(), false);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::undiscard(
&mut game_state,
index,
player.clone(),
false
))
}
#[post("/<uuid>/remember/<index>")]
@ -321,15 +299,15 @@ fn remember(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::undiscard(&mut game_state, index, player.clone(), true);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::undiscard(
&mut game_state,
index,
player.clone(),
true
))
}
#[post("/<uuid>/shadow/<index>")]
@ -338,15 +316,10 @@ fn shadow(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
match player_uuids.map.get(&uuid) {
Some(_) => (),
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
game::transfer_dead_card(&mut game_state, index, false);
Ok(format!("{}", game::get_events(&game_state)))
) -> (Status, (ContentType, String)) {
assert_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::transfer_dead_card(&mut game_state, index, false))
}
#[get("/<uuid>/get_state")]
@ -354,17 +327,16 @@ fn get_state(
uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
Ok(format!(
"{}",
game::get_game_one_player(&game_state, player.clone())
))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state!(game_state_arc, mutex, game_state);
(
Status::Ok,
(
ContentType::JSON,
format!("{}", game::get_game_one_player(&game_state, player.clone())),
),
)
}
#[post("/<uuid>/get_deck")]
@ -372,17 +344,16 @@ fn get_deck(
uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
Ok(format!(
"{}",
game::get_deck(&mut game_state, player.clone())
))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
(
Status::Ok,
(
ContentType::JSON,
format!("{}", game::get_deck(&mut game_state, player.clone())),
),
)
}
#[post("/<uuid>/untap_all")]
@ -390,18 +361,11 @@ fn untap_all(
uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
game::untap_all(&mut game_state, player.clone());
Ok(format!(
"{}",
game::get_game_one_player(&game_state, player.clone())
))
respond_ok!()
}
#[post("/<uuid>/draw/<count>")]
@ -410,18 +374,10 @@ fn draw(
count: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
game::draw(&mut game_state, count, player.clone());
Ok(format!(
"{}",
game::get_game_one_player(&game_state, player.clone())
))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::draw(&mut game_state, count, player.clone()))
}
#[post("/<uuid>/fade/<index>")]
@ -430,58 +386,45 @@ fn fade(
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
game::fade_from_hand(&mut game_state, index, player.clone(), false);
Ok(format!(
"{}",
game::get_game_one_player(&game_state, player.clone())
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::fade_from_hand(
&mut game_state,
index,
player.clone(),
false
))
}
#[post("/<uuid>/fade-bottom/<index>")]
#[post("/<uuid>/fade_bottom/<index>")]
fn fade_bottom(
uuid: Uuid,
index: usize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
game::fade_from_hand(&mut game_state, index, player.clone(), true);
Ok(format!(
"{}",
game::get_game_one_player(&game_state, player.clone())
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::fade_from_hand(
&mut game_state,
index,
player.clone(),
true
))
}
#[post("/<uuid>/life/<count>")]
fn life(
uuid: Uuid,
count: i32,
count: isize,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
game::change_life(&mut game_state, count, player.clone());
Ok(format!(
"{}",
game::get_game_one_player(&game_state, player.clone())
))
respond_ok!()
}
struct ArcMutexGameState {
@ -500,13 +443,12 @@ fn rocket() -> _ {
let game_state_arc = Arc::new(Mutex::new(game_state));
#[cfg(debug_assertions)]
let a_uuid: Uuid = uuid!("9b0a2a95-72a9-4e03-930e-a9583d2a2a5a");
let (a_uuid, b_uuid) = (
uuid!("9b0a2a95-72a9-4e03-930e-a9583d2a2a5a"),
uuid!("2efc0332-975d-4f71-9dd0-ffc9213098a5"),
);
#[cfg(not(debug_assertions))]
let a_uuid: Uuid = Uuid::new_v4();
#[cfg(debug_assertions)]
let b_uuid: Uuid = uuid!("2efc0332-975d-4f71-9dd0-ffc9213098a5");
#[cfg(not(debug_assertions))]
let b_uuid: Uuid = Uuid::new_v4();
let (a_uuid, b_uuid) = (Uuid::new_v4(), Uuid::new_v4());
let uuid_map = HashMap::from([(a_uuid, Player::A), (b_uuid, Player::B)]);
println!("A: {}", a_uuid);

View File

@ -6,6 +6,7 @@
console.log it
it
) .catch err
window.fetch-post = fetch-post
const $opponent-hand = document.query-selector '#opponent-hand'
const $own-hand = document.query-selector '#own-hand'
const $view-card = document.query-selector '#view-card'
@ -51,7 +52,8 @@
const get-play-size = -> $play.get-bounding-client-rect!
const gen-array = -> Array.from { length: it }, (_, i) -> i
const gen-array-of = (it, val) -> Array.from { length: it }, -> val
const cards = await fetch \./cards.json .then (.json!)
const cards = await fetch \/cards.json .then (.json!)
window.cards = cards
const $make-card = ->
$img = document.create-element \img
$img.src = it