diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 54 |
1 files changed, 53 insertions, 1 deletions
@@ -93,6 +93,46 @@ let ui = { for (let a of AREAS) a.nbname = a.name.replace(/ /g, "\xa0") +function remember_position(e) { + if (e.classList.contains("show")) { + let rect = e.getBoundingClientRect() + e.my_parent = true + e.my_x = rect.x + e.my_y = rect.y + } else { + e.my_parent = false + e.my_x = 0 + e.my_y = 0 + } +} + +function animate_position(e) { + if (e.parentElement) { + if (e.my_parent) { + let rect = e.getBoundingClientRect() + let dx = e.my_x - rect.x + let dy = e.my_y - rect.y + if (dx !== 0 || dy !== 0) { + e.animate( + [ + { transform: `translate(${dx}px, ${dy}px)`, }, + { transform: "translate(0, 0)", }, + ], + { duration: 250, easing: "ease" } + ) + } + } else { + e.animate( + [ + { opacity: 0 }, + { opacity: 1 } + ], + { duration: 250, easing: "ease" } + ) + } + } +} + function on_focus_space_tip(x) { ui.areas[x].classList.add("tip") } @@ -766,17 +806,29 @@ function on_update() { action_button("pass", "Pass") action_button("undo", "Undo") + for (let c = 1; c <= 25; ++c) + remember_position(ui.cards[c]) + update_cards() update_map() if (view.battle) { document.getElementById("battle_header").textContent = view.battle.title document.getElementById("battle_message").textContent = view.battle.flash - document.getElementById("battle").classList.add("show") + if (!document.getElementById("battle").classList.contains("show")) { + document.getElementById("battle").classList.add("show") + document.getElementById("battle").scrollIntoView({ + block:"center", inline:"center", behavior:"smooth" + }) + + } update_battle() } else { document.getElementById("battle").classList.remove("show") } + + for (let c = 1; c <= 25; ++c) + animate_position(ui.cards[c]) } build_map() |