From e0eb67b29984f6946ac91f0a9d918450314ff764 Mon Sep 17 00:00:00 2001 From: Seoxi Ryouko <3-Seoxi@users.noreply.git.starbit.dev> Date: Fri, 28 Feb 2025 07:49:21 -0600 Subject: [PATCH] =?UTF-8?q?Switched=20to=20using=20POST,=20bugfixes?= =?UTF-8?q?=F0=9F=93=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game.rs | 5 ++-- src/main.rs | 50 +++++++++++++++++++-------------------- web/src/script.ls | 59 ++++++++++++++++++++++++----------------------- 3 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/game.rs b/src/game.rs index fb1c49e..fffa604 100644 --- a/src/game.rs +++ b/src/game.rs @@ -176,7 +176,9 @@ pub fn yoink(game_state: &mut GameState, deck_index: usize, player: Player) { id: game_state.events.len(), 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) { @@ -190,7 +192,6 @@ pub fn yoink_mill(game_state: &mut GameState, deck_index: usize, shadow: bool) { } else { game_state.discard_pile.push(card); } - } pub fn shuffle(game_state: &mut GameState, player: Player) { diff --git a/src/main.rs b/src/main.rs index 29d9360..ef196ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ fn get_events(game_state_arc: &State) -> String { format!("{}", game::get_events(&game_state)) } -#[get("//shuffle")] +#[post("//shuffle")] fn shuffle( uuid: Uuid, game_state_arc: &State, @@ -42,7 +42,7 @@ fn shuffle( Ok(format!("Deck Shuffled!")) } -#[get("//pass")] +#[post("//pass")] fn pass( uuid: Uuid, game_state_arc: &State, @@ -58,7 +58,7 @@ fn pass( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//bounce/")] +#[post("//bounce/")] fn bounce( uuid: Uuid, play_id: Uuid, @@ -75,7 +75,7 @@ fn bounce( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//move///")] +#[post("//move///")] fn move_card( uuid: Uuid, play_id: Uuid, @@ -94,7 +94,7 @@ fn move_card( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//tap/")] +#[post("//tap/")] fn tap( uuid: Uuid, play_id: Uuid, @@ -111,7 +111,7 @@ fn tap( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//play/")] +#[post("//play/")] fn play( uuid: Uuid, index: usize, @@ -128,7 +128,7 @@ fn play( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//unkill/")] +#[post("//unkill/")] fn unkill( uuid: Uuid, index: usize, @@ -145,7 +145,7 @@ fn unkill( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//unbanish/")] +#[post("//unbanish/")] fn unbanish( uuid: Uuid, index: usize, @@ -162,7 +162,7 @@ fn unbanish( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//discard/")] +#[post("//discard/")] fn discard( uuid: Uuid, index: usize, @@ -179,7 +179,7 @@ fn discard( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//forget/")] +#[post("//forget/")] fn forget( uuid: Uuid, index: usize, @@ -196,7 +196,7 @@ fn forget( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//kill/")] +#[post("//kill/")] fn kill( uuid: Uuid, play_id: Uuid, @@ -213,7 +213,7 @@ fn kill( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//banish/")] +#[post("//banish/")] fn banish( uuid: Uuid, play_id: Uuid, @@ -230,7 +230,7 @@ fn banish( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//unshadow/")] +#[post("//unshadow/")] fn unshadow( uuid: Uuid, index: usize, @@ -247,7 +247,7 @@ fn unshadow( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//yoink/")] +#[post("//yoink/")] fn yoink( uuid: Uuid, index: usize, @@ -264,7 +264,7 @@ fn yoink( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//yoink_mill/")] +#[post("//yoink_mill/")] fn yoink_mill( uuid: Uuid, index: usize, @@ -281,7 +281,7 @@ fn yoink_mill( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//yoink_xmill/")] +#[post("//yoink_xmill/")] fn yoink_xmill( uuid: Uuid, index: usize, @@ -298,7 +298,7 @@ fn yoink_xmill( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//undiscard/")] +#[post("//undiscard/")] fn undiscard( uuid: Uuid, index: usize, @@ -315,7 +315,7 @@ fn undiscard( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//remember/")] +#[post("//remember/")] fn remember( uuid: Uuid, index: usize, @@ -332,7 +332,7 @@ fn remember( Ok(format!("{}", game::get_events(&game_state))) } -#[get("//shadow/")] +#[post("//shadow/")] fn shadow( uuid: Uuid, index: usize, @@ -367,7 +367,7 @@ fn get_state( )) } -#[get("//get_deck")] +#[post("//get_deck")] fn get_deck( uuid: Uuid, game_state_arc: &State, @@ -385,7 +385,7 @@ fn get_deck( )) } -#[get("//untap_all")] +#[post("//untap_all")] fn untap_all( uuid: Uuid, game_state_arc: &State, @@ -404,7 +404,7 @@ fn untap_all( )) } -#[get("//draw/")] +#[post("//draw/")] fn draw( uuid: Uuid, count: usize, @@ -424,7 +424,7 @@ fn draw( )) } -#[get("//fade/")] +#[post("//fade/")] fn fade( uuid: Uuid, index: usize, @@ -444,7 +444,7 @@ fn fade( )) } -#[get("//fade-bottom/")] +#[post("//fade-bottom/")] fn fade_bottom( uuid: Uuid, index: usize, @@ -464,7 +464,7 @@ fn fade_bottom( )) } -#[get("//life/")] +#[post("//life/")] fn life( uuid: Uuid, count: i32, diff --git a/web/src/script.ls b/web/src/script.ls index 57dbb26..3c54c11 100644 --- a/web/src/script.ls +++ b/web/src/script.ls @@ -1,7 +1,8 @@ (->> const err = -> console.error it - const fetch-log = -> - fetch it .then (-> + const fetch-post = -> + const req = new Request it, { method: \POST } + fetch req .then (-> console.log it it ) .catch err @@ -50,7 +51,7 @@ 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-log \./cards.json .then (.json!) + const cards = await fetch \./cards.json .then (.json!) const $make-card = -> $img = document.create-element \img $img.src = it @@ -109,8 +110,8 @@ | \discard => player-state.discard_pile | \shadow => player-state.shadow_realm | \deck => gen-array-of state.player-state.deck_size, null - | \deck-revealed => await fetch-log \./get_deck .then (.json!) - | _ => (console.error that) || [] + | \deck-revealed => await fetch-post \./get_deck .then (.json!) + | _ => (err that) || [] open-list list, $extra.get-attribute \data-pile-type if player-state.hand.length != $own-hand.children.length $own-hand.innerHTML = '' @@ -172,7 +173,7 @@ absolute-y = y else 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-id-list := next-play-id-list else @@ -239,82 +240,82 @@ $current-mouse-node = [...document.query-selector-all \:hover][* - 1] switch it.key.to-lower-case! | \v => - fetch-log \./shuffle + fetch-post \./shuffle if $extra.has-attribute \data-pile-type and \deck-revealed == $extra.get-attribute \data-pile-type $extra.class-list.add \hidden - | \c => fetch-log "./draw/#{pop-param!}" - | \e => fetch-log \./pass + | \c => fetch-post "./draw/#{pop-param!}" + | \e => fetch-post \./pass | \0 \1 \2 \3 \4 \5 \6 \7 \8 \9 => push-param that | \t => 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 => 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 - 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 if \true == $current-mouse-node.get-attribute \data-tapped $current-mouse-node.set-attribute \data-tapped \false else $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 switch $current-mouse-node.get-attribute \data-list-type | \discard - fetch-log "./unkill/#{$current-mouse-node.get-attribute \data-index}" + fetch-post "./unkill/#{$current-mouse-node.get-attribute \data-index}" | \deck , \deck-revealed return # will add play button | \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 if !$extra.child-element-count $extra.class-list.add \hidden $extra.remove-attribute \data-pile-type | \r => 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 switch $current-mouse-node.get-attribute \data-list-type | \discard - fetch-log "./undiscard/#{$current-mouse-node.get-attribute \data-index}" + fetch-post "./undiscard/#{$current-mouse-node.get-attribute \data-index}" | \deck , \deck-revealed - fetch-log "./yoink/#{$current-mouse-node.get-attribute \data-index}" + fetch-post "./yoink/#{$current-mouse-node.get-attribute \data-index}" | \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 if !$extra.child-element-count $extra.class-list.add \hidden $extra.remove-attribute \data-pile-type | \d => 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 - 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 switch $current-mouse-node.get-attribute \data-list-type | \discard return | \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 - 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 if !$extra.child-element-count $extra.class-list.add \hidden $extra.remove-attribute \data-pile-type | \s => 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 - 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 switch $current-mouse-node.get-attribute \data-list-type | \discard - fetch-log "./shadow/#{$current-mouse-node.get-attribute \data-index}" + fetch-post "./shadow/#{$current-mouse-node.get-attribute \data-index}" | \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 return $current-mouse-node.parent-element.remove-child $current-mouse-node @@ -326,12 +327,12 @@ $extra.remove-attribute \data-pile-type | \x => if it.shift-key || state.player-state.turn_player == state.player-state.you - fetch-log \./untap_all + fetch-post \./untap_all [...$play.children] .filter -> \true == it.get-attribute \data-owned .for-each -> it.set-attribute \data-tapped false | \f => - fetch-log \./get_deck .then ->> + fetch-post \./get_deck .then ->> const deck = await it.json! open-list deck, \deck-revealed )!