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

@ -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
)!