Switched to using POST, bugfixes📨

This commit is contained in:
Seoxi Ryouko
2025-02-28 07:49:21 -06:00
parent 066a9472ac
commit e0eb67b299
3 changed files with 58 additions and 56 deletions

View File

@ -176,7 +176,9 @@ pub fn yoink(game_state: &mut GameState, deck_index: usize, player: Player) {
id: game_state.events.len(), id: game_state.events.len(),
event: Event::Yoink(player.clone()), event: Event::Yoink(player.clone()),
}); });
player_hand.cards.push(game_state.deck.remove(deck_index).unwrap()); player_hand
.cards
.push(game_state.deck.remove(deck_index).unwrap());
} }
pub fn yoink_mill(game_state: &mut GameState, deck_index: usize, shadow: bool) { pub fn yoink_mill(game_state: &mut GameState, deck_index: usize, shadow: bool) {
@ -190,7 +192,6 @@ pub fn yoink_mill(game_state: &mut GameState, deck_index: usize, shadow: bool) {
} else { } else {
game_state.discard_pile.push(card); game_state.discard_pile.push(card);
} }
} }
pub fn shuffle(game_state: &mut GameState, player: Player) { pub fn shuffle(game_state: &mut GameState, player: Player) {

View File

@ -26,7 +26,7 @@ fn get_events(game_state_arc: &State<ArcMutexGameState>) -> String {
format!("{}", game::get_events(&game_state)) format!("{}", game::get_events(&game_state))
} }
#[get("/<uuid>/shuffle")] #[post("/<uuid>/shuffle")]
fn shuffle( fn shuffle(
uuid: Uuid, uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>, game_state_arc: &State<ArcMutexGameState>,
@ -42,7 +42,7 @@ fn shuffle(
Ok(format!("Deck Shuffled!")) Ok(format!("Deck Shuffled!"))
} }
#[get("/<uuid>/pass")] #[post("/<uuid>/pass")]
fn pass( fn pass(
uuid: Uuid, uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>, game_state_arc: &State<ArcMutexGameState>,
@ -58,7 +58,7 @@ fn pass(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/bounce/<play_id>")] #[post("/<uuid>/bounce/<play_id>")]
fn bounce( fn bounce(
uuid: Uuid, uuid: Uuid,
play_id: Uuid, play_id: Uuid,
@ -75,7 +75,7 @@ fn bounce(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/move/<play_id>/<x>/<y>")] #[post("/<uuid>/move/<play_id>/<x>/<y>")]
fn move_card( fn move_card(
uuid: Uuid, uuid: Uuid,
play_id: Uuid, play_id: Uuid,
@ -94,7 +94,7 @@ fn move_card(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/tap/<play_id>")] #[post("/<uuid>/tap/<play_id>")]
fn tap( fn tap(
uuid: Uuid, uuid: Uuid,
play_id: Uuid, play_id: Uuid,
@ -111,7 +111,7 @@ fn tap(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/play/<index>")] #[post("/<uuid>/play/<index>")]
fn play( fn play(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -128,7 +128,7 @@ fn play(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/unkill/<index>")] #[post("/<uuid>/unkill/<index>")]
fn unkill( fn unkill(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -145,7 +145,7 @@ fn unkill(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/unbanish/<index>")] #[post("/<uuid>/unbanish/<index>")]
fn unbanish( fn unbanish(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -162,7 +162,7 @@ fn unbanish(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/discard/<index>")] #[post("/<uuid>/discard/<index>")]
fn discard( fn discard(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -179,7 +179,7 @@ fn discard(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/forget/<index>")] #[post("/<uuid>/forget/<index>")]
fn forget( fn forget(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -196,7 +196,7 @@ fn forget(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/kill/<play_id>")] #[post("/<uuid>/kill/<play_id>")]
fn kill( fn kill(
uuid: Uuid, uuid: Uuid,
play_id: Uuid, play_id: Uuid,
@ -213,7 +213,7 @@ fn kill(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/banish/<play_id>")] #[post("/<uuid>/banish/<play_id>")]
fn banish( fn banish(
uuid: Uuid, uuid: Uuid,
play_id: Uuid, play_id: Uuid,
@ -230,7 +230,7 @@ fn banish(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/unshadow/<index>")] #[post("/<uuid>/unshadow/<index>")]
fn unshadow( fn unshadow(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -247,7 +247,7 @@ fn unshadow(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/yoink/<index>")] #[post("/<uuid>/yoink/<index>")]
fn yoink( fn yoink(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -264,7 +264,7 @@ fn yoink(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/yoink_mill/<index>")] #[post("/<uuid>/yoink_mill/<index>")]
fn yoink_mill( fn yoink_mill(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -281,7 +281,7 @@ fn yoink_mill(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/yoink_xmill/<index>")] #[post("/<uuid>/yoink_xmill/<index>")]
fn yoink_xmill( fn yoink_xmill(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -298,7 +298,7 @@ fn yoink_xmill(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/undiscard/<index>")] #[post("/<uuid>/undiscard/<index>")]
fn undiscard( fn undiscard(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -315,7 +315,7 @@ fn undiscard(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/remember/<index>")] #[post("/<uuid>/remember/<index>")]
fn remember( fn remember(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -332,7 +332,7 @@ fn remember(
Ok(format!("{}", game::get_events(&game_state))) Ok(format!("{}", game::get_events(&game_state)))
} }
#[get("/<uuid>/shadow/<index>")] #[post("/<uuid>/shadow/<index>")]
fn shadow( fn shadow(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -367,7 +367,7 @@ fn get_state(
)) ))
} }
#[get("/<uuid>/get_deck")] #[post("/<uuid>/get_deck")]
fn get_deck( fn get_deck(
uuid: Uuid, uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>, game_state_arc: &State<ArcMutexGameState>,
@ -385,7 +385,7 @@ fn get_deck(
)) ))
} }
#[get("/<uuid>/untap_all")] #[post("/<uuid>/untap_all")]
fn untap_all( fn untap_all(
uuid: Uuid, uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>, game_state_arc: &State<ArcMutexGameState>,
@ -404,7 +404,7 @@ fn untap_all(
)) ))
} }
#[get("/<uuid>/draw/<count>")] #[post("/<uuid>/draw/<count>")]
fn draw( fn draw(
uuid: Uuid, uuid: Uuid,
count: usize, count: usize,
@ -424,7 +424,7 @@ fn draw(
)) ))
} }
#[get("/<uuid>/fade/<index>")] #[post("/<uuid>/fade/<index>")]
fn fade( fn fade(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -444,7 +444,7 @@ fn fade(
)) ))
} }
#[get("/<uuid>/fade-bottom/<index>")] #[post("/<uuid>/fade-bottom/<index>")]
fn fade_bottom( fn fade_bottom(
uuid: Uuid, uuid: Uuid,
index: usize, index: usize,
@ -464,7 +464,7 @@ fn fade_bottom(
)) ))
} }
#[get("/<uuid>/life/<count>")] #[post("/<uuid>/life/<count>")]
fn life( fn life(
uuid: Uuid, uuid: Uuid,
count: i32, count: i32,

View File

@ -1,7 +1,8 @@
(->> (->>
const err = -> console.error it const err = -> console.error it
const fetch-log = -> const fetch-post = ->
fetch it .then (-> const req = new Request it, { method: \POST }
fetch req .then (->
console.log it console.log it
it it
) .catch err ) .catch err
@ -50,7 +51,7 @@
const get-play-size = -> $play.get-bounding-client-rect! const get-play-size = -> $play.get-bounding-client-rect!
const gen-array = -> Array.from { length: it }, (_, i) -> i const gen-array = -> Array.from { length: it }, (_, i) -> i
const gen-array-of = (it, val) -> Array.from { length: it }, -> val const gen-array-of = (it, val) -> Array.from { length: it }, -> val
const cards = await fetch-log \./cards.json .then (.json!) const cards = await fetch \./cards.json .then (.json!)
const $make-card = -> const $make-card = ->
$img = document.create-element \img $img = document.create-element \img
$img.src = it $img.src = it
@ -109,8 +110,8 @@
| \discard => player-state.discard_pile | \discard => player-state.discard_pile
| \shadow => player-state.shadow_realm | \shadow => player-state.shadow_realm
| \deck => gen-array-of state.player-state.deck_size, null | \deck => gen-array-of state.player-state.deck_size, null
| \deck-revealed => await fetch-log \./get_deck .then (.json!) | \deck-revealed => await fetch-post \./get_deck .then (.json!)
| _ => (console.error that) || [] | _ => (err that) || []
open-list list, $extra.get-attribute \data-pile-type open-list list, $extra.get-attribute \data-pile-type
if player-state.hand.length != $own-hand.children.length if player-state.hand.length != $own-hand.children.length
$own-hand.innerHTML = '' $own-hand.innerHTML = ''
@ -172,7 +173,7 @@
absolute-y = y absolute-y = y
else else
absolute-y = 100 - y absolute-y = 100 - y
fetch-log "./move/#{it.target.get-attribute \data-play-id}/#x/#absolute-y" fetch-post "./move/#{it.target.get-attribute \data-play-id}/#x/#absolute-y"
$play.append-child img $play.append-child img
play-id-list := next-play-id-list play-id-list := next-play-id-list
else else
@ -239,82 +240,82 @@
$current-mouse-node = [...document.query-selector-all \:hover][* - 1] $current-mouse-node = [...document.query-selector-all \:hover][* - 1]
switch it.key.to-lower-case! switch it.key.to-lower-case!
| \v => | \v =>
fetch-log \./shuffle fetch-post \./shuffle
if $extra.has-attribute \data-pile-type and \deck-revealed == $extra.get-attribute \data-pile-type if $extra.has-attribute \data-pile-type and \deck-revealed == $extra.get-attribute \data-pile-type
$extra.class-list.add \hidden $extra.class-list.add \hidden
| \c => fetch-log "./draw/#{pop-param!}" | \c => fetch-post "./draw/#{pop-param!}"
| \e => fetch-log \./pass | \e => fetch-post \./pass
| \0 \1 \2 \3 \4 \5 \6 \7 \8 \9 => push-param that | \0 \1 \2 \3 \4 \5 \6 \7 \8 \9 => push-param that
| \t => | \t =>
if $current-mouse-node?.has-attribute \data-hand-index if $current-mouse-node?.has-attribute \data-hand-index
fetch-log "./fade/#{$current-mouse-node.get-attribute \data-hand-index}" fetch-post "./fade/#{$current-mouse-node.get-attribute \data-hand-index}"
| \y => | \y =>
if $current-mouse-node?.has-attribute \data-hand-index if $current-mouse-node?.has-attribute \data-hand-index
fetch-log "./fade_bottom/#{$current-mouse-node.get-attribute \data-hand-index}" fetch-post "./fade_bottom/#{$current-mouse-node.get-attribute \data-hand-index}"
| ' ' => | ' ' =>
if $current-mouse-node?.has-attribute \data-hand-index if $current-mouse-node?.has-attribute \data-hand-index
fetch-log "./play/#{$current-mouse-node.get-attribute \data-hand-index}" fetch-post "./play/#{$current-mouse-node.get-attribute \data-hand-index}"
else if $current-mouse-node?.has-attribute \data-play-id else if $current-mouse-node?.has-attribute \data-play-id
if \true == $current-mouse-node.get-attribute \data-tapped if \true == $current-mouse-node.get-attribute \data-tapped
$current-mouse-node.set-attribute \data-tapped \false $current-mouse-node.set-attribute \data-tapped \false
else else
$current-mouse-node.set-attribute \data-tapped \true $current-mouse-node.set-attribute \data-tapped \true
fetch-log "./tap/#{$current-mouse-node.get-attribute \data-play-id}" fetch-post "./tap/#{$current-mouse-node.get-attribute \data-play-id}"
else if $current-mouse-node?.has-attribute \data-list-type else if $current-mouse-node?.has-attribute \data-list-type
switch $current-mouse-node.get-attribute \data-list-type switch $current-mouse-node.get-attribute \data-list-type
| \discard | \discard
fetch-log "./unkill/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./unkill/#{$current-mouse-node.get-attribute \data-index}"
| \deck , \deck-revealed | \deck , \deck-revealed
return # will add play button return # will add play button
| \shadow | \shadow
fetch-log "./unbanish/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./unbanish/#{$current-mouse-node.get-attribute \data-index}"
$current-mouse-node.parent-element.remove-child $current-mouse-node $current-mouse-node.parent-element.remove-child $current-mouse-node
if !$extra.child-element-count if !$extra.child-element-count
$extra.class-list.add \hidden $extra.class-list.add \hidden
$extra.remove-attribute \data-pile-type $extra.remove-attribute \data-pile-type
| \r => | \r =>
if $current-mouse-node?.has-attribute \data-play-id if $current-mouse-node?.has-attribute \data-play-id
fetch-log "./bounce/#{$current-mouse-node.get-attribute \data-play-id}" fetch-post "./bounce/#{$current-mouse-node.get-attribute \data-play-id}"
else if $current-mouse-node?.has-attribute \data-list-type else if $current-mouse-node?.has-attribute \data-list-type
switch $current-mouse-node.get-attribute \data-list-type switch $current-mouse-node.get-attribute \data-list-type
| \discard | \discard
fetch-log "./undiscard/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./undiscard/#{$current-mouse-node.get-attribute \data-index}"
| \deck , \deck-revealed | \deck , \deck-revealed
fetch-log "./yoink/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./yoink/#{$current-mouse-node.get-attribute \data-index}"
| \shadow | \shadow
fetch-log "./remember/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./remember/#{$current-mouse-node.get-attribute \data-index}"
$current-mouse-node.parent-element.remove-child $current-mouse-node $current-mouse-node.parent-element.remove-child $current-mouse-node
if !$extra.child-element-count if !$extra.child-element-count
$extra.class-list.add \hidden $extra.class-list.add \hidden
$extra.remove-attribute \data-pile-type $extra.remove-attribute \data-pile-type
| \d => | \d =>
if $current-mouse-node?.has-attribute \data-hand-index if $current-mouse-node?.has-attribute \data-hand-index
fetch-log "./discard/#{$current-mouse-node.get-attribute \data-hand-index}" fetch-post "./discard/#{$current-mouse-node.get-attribute \data-hand-index}"
else if $current-mouse-node?.has-attribute \data-play-id else if $current-mouse-node?.has-attribute \data-play-id
fetch-log "./kill/#{$current-mouse-node.get-attribute \data-play-id}" fetch-post "./kill/#{$current-mouse-node.get-attribute \data-play-id}"
else if $current-mouse-node?.has-attribute \data-list-type else if $current-mouse-node?.has-attribute \data-list-type
switch $current-mouse-node.get-attribute \data-list-type switch $current-mouse-node.get-attribute \data-list-type
| \discard | \discard
return return
| \deck , \deck-revealed | \deck , \deck-revealed
fetch-log "./yoink_mill/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./yoink_mill/#{$current-mouse-node.get-attribute \data-index}"
| \shadow | \shadow
fetch-log "./undiscard/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./unshadow/#{$current-mouse-node.get-attribute \data-index}"
$current-mouse-node.parent-element.remove-child $current-mouse-node $current-mouse-node.parent-element.remove-child $current-mouse-node
if !$extra.child-element-count if !$extra.child-element-count
$extra.class-list.add \hidden $extra.class-list.add \hidden
$extra.remove-attribute \data-pile-type $extra.remove-attribute \data-pile-type
| \s => | \s =>
if $current-mouse-node?.has-attribute \data-hand-index if $current-mouse-node?.has-attribute \data-hand-index
fetch-log "./forget/#{$current-mouse-node.get-attribute \data-hand-index}" fetch-post "./forget/#{$current-mouse-node.get-attribute \data-hand-index}"
else if $current-mouse-node?.has-attribute \data-play-id else if $current-mouse-node?.has-attribute \data-play-id
fetch-log "./banish/#{$current-mouse-node.get-attribute \data-play-id}" fetch-post "./banish/#{$current-mouse-node.get-attribute \data-play-id}"
else if $current-mouse-node?.has-attribute \data-list-type else if $current-mouse-node?.has-attribute \data-list-type
switch $current-mouse-node.get-attribute \data-list-type switch $current-mouse-node.get-attribute \data-list-type
| \discard | \discard
fetch-log "./shadow/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./shadow/#{$current-mouse-node.get-attribute \data-index}"
| \deck , \deck-revealed | \deck , \deck-revealed
fetch-log "./yoink_xmill/#{$current-mouse-node.get-attribute \data-index}" fetch-post "./yoink_xmill/#{$current-mouse-node.get-attribute \data-index}"
| \shadow | \shadow
return return
$current-mouse-node.parent-element.remove-child $current-mouse-node $current-mouse-node.parent-element.remove-child $current-mouse-node
@ -326,12 +327,12 @@
$extra.remove-attribute \data-pile-type $extra.remove-attribute \data-pile-type
| \x => | \x =>
if it.shift-key || state.player-state.turn_player == state.player-state.you if it.shift-key || state.player-state.turn_player == state.player-state.you
fetch-log \./untap_all fetch-post \./untap_all
[...$play.children] [...$play.children]
.filter -> \true == it.get-attribute \data-owned .filter -> \true == it.get-attribute \data-owned
.for-each -> it.set-attribute \data-tapped false .for-each -> it.set-attribute \data-tapped false
| \f => | \f =>
fetch-log \./get_deck .then ->> fetch-post \./get_deck .then ->>
const deck = await it.json! const deck = await it.json!
open-list deck, \deck-revealed open-list deck, \deck-revealed
)! )!