summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-06-12 00:02:31 +0200
committerTor Andersson <tor@ccxvii.net>2024-08-21 00:28:20 +0200
commitd590b20d6167972993ee6ce4f0ead6db1e10209a (patch)
tree5689079b524c92cb4991aa7669792ac7629ca282
parentd1aa69a2996a2ba397478a0d61d45e1973ac5747 (diff)
downloadwashingtons-war-d590b20d6167972993ee6ce4f0ead6db1e10209a.tar.gz
animate
-rw-r--r--play.js48
1 files changed, 25 insertions, 23 deletions
diff --git a/play.js b/play.js
index e4a6783..659a335 100644
--- a/play.js
+++ b/play.js
@@ -107,8 +107,11 @@ function count_french_cu(s) {
/* ANIMATION */
+var animation_list = []
+
function remember_position(e) {
if (e.parentElement) {
+ animation_list.push(e)
let rect = e.getBoundingClientRect()
e.my_parent = e.parentElement
e.my_x = rect.x
@@ -120,23 +123,26 @@ function remember_position(e) {
}
}
-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: 333, easing: "ease" }
- )
+function animate_positions() {
+ for (let e of animation_list) {
+ 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: 333, easing: "ease" }
+ )
+ }
}
}
}
+ animation_list.length = 0
}
/* BUILD UI */
@@ -491,25 +497,27 @@ function on_update() {
e = document.getElementById("played_british_reinforcements")
if (view.reinforcements[0] > 0)
- e.className = "ops_" + CARDS[view.reinforcements[0]].count
+ e.className = "reinforcements ops_" + CARDS[view.reinforcements[0]].count
else
e.className = ""
e = document.getElementById("played_american_reinforcements_1")
if (view.reinforcements[1] > 0)
- e.className = "ops_" + CARDS[view.reinforcements[1]].count
+ e.className = "reinforcements ops_" + CARDS[view.reinforcements[1]].count
else
e.className = ""
e = document.getElementById("played_american_reinforcements_2")
if (view.reinforcements[2] > 0)
- e.className = "ops_" + CARDS[view.reinforcements[2]].count
+ e.className = "reinforcements ops_" + CARDS[view.reinforcements[2]].count
else
e.className = ""
for (let e of action_register)
e.classList.toggle("action", is_action(e.my_action, e.my_id))
+ animate_positions()
+
action_button("pickup_french_cu", "Take French CU")
action_button("pickup_british_cu", "Take CU")
action_button("pickup_american_cu", "Take CU")
@@ -525,12 +533,6 @@ function on_update() {
action_button("pass", "Pass")
action_button("undo", "Undo")
- animate_position(ui.b_mcu)
- animate_position(ui.a_mcu)
- animate_position(ui.f_mcu)
- for (let g = 0; g < general_count; ++g)
- animate_position(ui.generals[g])
-
}
/* POPUP MENU */