Switched to using POST, bugfixes📨
This commit is contained in:
@ -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) {
|
||||
|
||||
50
src/main.rs
50
src/main.rs
@ -26,7 +26,7 @@ fn get_events(game_state_arc: &State<ArcMutexGameState>) -> String {
|
||||
format!("{}", game::get_events(&game_state))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/shuffle")]
|
||||
#[post("/<uuid>/shuffle")]
|
||||
fn shuffle(
|
||||
uuid: Uuid,
|
||||
game_state_arc: &State<ArcMutexGameState>,
|
||||
@ -42,7 +42,7 @@ fn shuffle(
|
||||
Ok(format!("Deck Shuffled!"))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/pass")]
|
||||
#[post("/<uuid>/pass")]
|
||||
fn pass(
|
||||
uuid: Uuid,
|
||||
game_state_arc: &State<ArcMutexGameState>,
|
||||
@ -58,7 +58,7 @@ fn pass(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/bounce/<play_id>")]
|
||||
#[post("/<uuid>/bounce/<play_id>")]
|
||||
fn bounce(
|
||||
uuid: Uuid,
|
||||
play_id: Uuid,
|
||||
@ -75,7 +75,7 @@ fn bounce(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/move/<play_id>/<x>/<y>")]
|
||||
#[post("/<uuid>/move/<play_id>/<x>/<y>")]
|
||||
fn move_card(
|
||||
uuid: Uuid,
|
||||
play_id: Uuid,
|
||||
@ -94,7 +94,7 @@ fn move_card(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/tap/<play_id>")]
|
||||
#[post("/<uuid>/tap/<play_id>")]
|
||||
fn tap(
|
||||
uuid: Uuid,
|
||||
play_id: Uuid,
|
||||
@ -111,7 +111,7 @@ fn tap(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/play/<index>")]
|
||||
#[post("/<uuid>/play/<index>")]
|
||||
fn play(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -128,7 +128,7 @@ fn play(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/unkill/<index>")]
|
||||
#[post("/<uuid>/unkill/<index>")]
|
||||
fn unkill(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -145,7 +145,7 @@ fn unkill(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/unbanish/<index>")]
|
||||
#[post("/<uuid>/unbanish/<index>")]
|
||||
fn unbanish(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -162,7 +162,7 @@ fn unbanish(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/discard/<index>")]
|
||||
#[post("/<uuid>/discard/<index>")]
|
||||
fn discard(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -179,7 +179,7 @@ fn discard(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/forget/<index>")]
|
||||
#[post("/<uuid>/forget/<index>")]
|
||||
fn forget(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -196,7 +196,7 @@ fn forget(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/kill/<play_id>")]
|
||||
#[post("/<uuid>/kill/<play_id>")]
|
||||
fn kill(
|
||||
uuid: Uuid,
|
||||
play_id: Uuid,
|
||||
@ -213,7 +213,7 @@ fn kill(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/banish/<play_id>")]
|
||||
#[post("/<uuid>/banish/<play_id>")]
|
||||
fn banish(
|
||||
uuid: Uuid,
|
||||
play_id: Uuid,
|
||||
@ -230,7 +230,7 @@ fn banish(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/unshadow/<index>")]
|
||||
#[post("/<uuid>/unshadow/<index>")]
|
||||
fn unshadow(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -247,7 +247,7 @@ fn unshadow(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/yoink/<index>")]
|
||||
#[post("/<uuid>/yoink/<index>")]
|
||||
fn yoink(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -264,7 +264,7 @@ fn yoink(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/yoink_mill/<index>")]
|
||||
#[post("/<uuid>/yoink_mill/<index>")]
|
||||
fn yoink_mill(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -281,7 +281,7 @@ fn yoink_mill(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/yoink_xmill/<index>")]
|
||||
#[post("/<uuid>/yoink_xmill/<index>")]
|
||||
fn yoink_xmill(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -298,7 +298,7 @@ fn yoink_xmill(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/undiscard/<index>")]
|
||||
#[post("/<uuid>/undiscard/<index>")]
|
||||
fn undiscard(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -315,7 +315,7 @@ fn undiscard(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/remember/<index>")]
|
||||
#[post("/<uuid>/remember/<index>")]
|
||||
fn remember(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -332,7 +332,7 @@ fn remember(
|
||||
Ok(format!("{}", game::get_events(&game_state)))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/shadow/<index>")]
|
||||
#[post("/<uuid>/shadow/<index>")]
|
||||
fn shadow(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -367,7 +367,7 @@ fn get_state(
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/get_deck")]
|
||||
#[post("/<uuid>/get_deck")]
|
||||
fn get_deck(
|
||||
uuid: Uuid,
|
||||
game_state_arc: &State<ArcMutexGameState>,
|
||||
@ -385,7 +385,7 @@ fn get_deck(
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/untap_all")]
|
||||
#[post("/<uuid>/untap_all")]
|
||||
fn untap_all(
|
||||
uuid: Uuid,
|
||||
game_state_arc: &State<ArcMutexGameState>,
|
||||
@ -404,7 +404,7 @@ fn untap_all(
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/draw/<count>")]
|
||||
#[post("/<uuid>/draw/<count>")]
|
||||
fn draw(
|
||||
uuid: Uuid,
|
||||
count: usize,
|
||||
@ -424,7 +424,7 @@ fn draw(
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/fade/<index>")]
|
||||
#[post("/<uuid>/fade/<index>")]
|
||||
fn fade(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -444,7 +444,7 @@ fn fade(
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/fade-bottom/<index>")]
|
||||
#[post("/<uuid>/fade-bottom/<index>")]
|
||||
fn fade_bottom(
|
||||
uuid: Uuid,
|
||||
index: usize,
|
||||
@ -464,7 +464,7 @@ fn fade_bottom(
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/<uuid>/life/<count>")]
|
||||
#[post("/<uuid>/life/<count>")]
|
||||
fn life(
|
||||
uuid: Uuid,
|
||||
count: i32,
|
||||
|
||||
@ -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
|
||||
)!
|
||||
|
||||
Reference in New Issue
Block a user