From d0ba4e8521279c815368a6a1bf3ecbe6bf6fcd7f Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 14 Dec 2023 20:18:30 +0100 Subject: WIP animate morale cubes --- play.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index 56f4b8e..138fdc1 100644 --- a/play.js +++ b/play.js @@ -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) { -- cgit v1.2.3