diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-12-14 20:18:30 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-01-08 16:36:48 +0100 |
commit | d0ba4e8521279c815368a6a1bf3ecbe6bf6fcd7f (patch) | |
tree | dd0d5ede9abe84afb9046917e08249c5e2bc72f1 | |
parent | 7c197b11879d69a1dc84d601350d2ce129a5c671 (diff) | |
download | table-battles-d0ba4e8521279c815368a6a1bf3ecbe6bf6fcd7f.tar.gz |
WIP animate morale cubes
-rw-r--r-- | play.js | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -25,7 +25,8 @@ let ui = { dice: [], sticks: [], hit_sticks: [], - cubes: [], + mcubes: [], + ccubes: [], } let animation_registry = [] @@ -260,7 +261,7 @@ function fill_card_row(top, parent, list) { n = map_get(view.cubes, id, 0) for (let i = 0; i < n; ++i) - add_cube(ui.slot_cubes[id]) + add_ccube(ui.slot_cubes[id]) n = map_get(view.sticks, id, 0) x = 0 @@ -277,10 +278,20 @@ function fill_card_row(top, parent, list) { } } -function add_cube(parent) { +function add_mcube(parent) { for (let i = 0; i < 10; ++i) { - if (ui.cubes[i].parentElement === null) { - parent.appendChild(ui.cubes[i]) + if (ui.mcubes[i].parentElement === null) { + parent.appendChild(ui.mcubes[i]) + return + } + } + throw Error("OUT OF CUBES ERROR") +} + +function add_ccube(parent) { + for (let i = 0; i < 10; ++i) { + if (ui.ccubes[i].parentElement === null) { + parent.appendChild(ui.ccubes[i]) return } } @@ -338,7 +349,9 @@ function on_update() { for (let e of animation_registry) remember_position(e) - for (let e of ui.cubes) + for (let e of ui.mcubes) + e.remove() + for (let e of ui.ccubes) e.remove() for (let e of ui.sticks) e.remove() @@ -346,10 +359,10 @@ function on_update() { e.remove() for (let i = 0; i < view.morale[0]; ++i) - add_cube(ui.morale[p1]) + add_mcube(ui.morale[p1]) for (let i = 0; i < view.morale[1]; ++i) - add_cube(ui.morale[p2]) + add_mcube(ui.morale[p2]) fill_card_row(p2, ui.reserve[p1], view.reserve[0]) fill_card_row(p2, ui.front[p1], view.front[0]) @@ -397,8 +410,9 @@ function on_update() { } for (let i = 0; i < 10; ++i) { - ui.cubes[i] = create_div("cube") - // register_animation(ui.cubes[i], 500) + ui.ccubes[i] = create_div("cube") + ui.mcubes[i] = create_div("cube") + register_animation(ui.mcubes[i], 750) } for (let i = 0; i < 80; ++i) { |