Start of major refactor

This commit is contained in:
Seoxi Ryouko
2025-03-01 19:55:15 -06:00
parent e0eb67b299
commit e329b1f223
8 changed files with 349 additions and 529 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

@ -153,7 +153,7 @@ pub fn new() -> GameState {
pub fn draw(game_state: &mut GameState, count: usize, player: Player) {
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(),
@ -167,22 +167,35 @@ pub fn draw(game_state: &mut GameState, count: usize, player: Player) {
);
}
pub fn yoink(game_state: &mut GameState, deck_index: usize, player: Player) {
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],
_ => &mut game_state.hands[1],
Player::B => &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());
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) {
let card = game_state.deck.remove(deck_index).unwrap();
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
))
}
};
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::YoinkMill(card.clone()),
@ -192,6 +205,7 @@ pub fn yoink_mill(game_state: &mut GameState, deck_index: usize, shadow: bool) {
} else {
game_state.discard_pile.push(card);
}
Ok(())
}
pub fn shuffle(game_state: &mut GameState, player: Player) {
@ -256,7 +270,11 @@ pub fn fade_from_hand(game_state: &mut GameState, hand_index: usize, player: Pla
}
}
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],
@ -265,6 +283,9 @@ pub fn play_from_hand(game_state: &mut GameState, hand_index: usize, player: Pla
id: game_state.events.len(),
event: Event::PlayFromHand(player.clone()),
});
if None == player_hand.cards.get(hand_index) {
return Err(format!("Yoink 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,10 +299,14 @@ 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],
@ -290,22 +315,36 @@ pub fn bounce(game_state: &mut GameState, play_id: Uuid) {
id: game_state.events.len(),
event: Event::Bounce(played_card.owner),
});
player_hand.cards.push(played_card.id);
Ok(player_hand.cards.push(played_card.id))
}
pub fn tap(game_state: &mut GameState, play_id: Uuid) {
pub fn tap(game_state: &mut GameState, play_id: Uuid) -> Result<(), String> {
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();
played_card.tapped = !played_card.tapped;
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) {
played_card.position_x = position_x;
played_card.position_y = position_y;
pub fn move_played_card(
game_state: &mut GameState,
play_id: Uuid,
position_x: u8,
position_y: u8,
) -> Result<(), String> {
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)),
}
}

View File

@ -4,26 +4,76 @@ 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 {
($state:expr) => {
match $state {
Ok(()) => (Status::Ok, (ContentType::Plain, "Ok!".to_string())),
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 +81,10 @@ 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))),
};
game::shuffle(&mut game_state, player.clone());
Ok(format!("Deck Shuffled!"))
) -> (Status, (ContentType, String)) {
let player = get_player!(player_uuids, uuid);
unlock_state_mut!(game_state_arc, mutex, game_state);
respond!(game::shuffle(&mut game_state, player.clone()))
}
#[post("/<uuid>/pass")]
@ -47,15 +92,10 @@ 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();
game::pass(&mut game_state);
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::pass(&mut game_state))
}
#[post("/<uuid>/bounce/<play_id>")]
@ -64,15 +104,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 +118,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 +130,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 +142,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 +154,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 +166,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 +178,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 +190,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 +202,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 +214,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 +226,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 +238,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 +250,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 +262,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 +274,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 +291,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 +308,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 +319,13 @@ 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!(
) -> (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 +333,13 @@ 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!(
) -> (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 +347,10 @@ 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))),
};
game::untap_all(&mut game_state, 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::untap_all(&mut game_state, player.clone()))
}
#[post("/<uuid>/draw/<count>")]
@ -410,18 +359,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,37 +371,31 @@ 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
))
}
@ -470,18 +405,10 @@ fn life(
count: i32,
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::change_life(&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::change_life(&mut game_state, count, player.clone()))
}
struct ArcMutexGameState {

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