From b85e8f9ad08399e22445248ffe8703e6de7fe5a2 Mon Sep 17 00:00:00 2001 From: Mischa Untaga <99098079+MischaU8@users.noreply.github.com> Date: Mon, 13 May 2024 16:31:27 +0200 Subject: grow cubes array dynamically --- play.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/play.js b/play.js index bb80de7..623720c 100644 --- a/play.js +++ b/play.js @@ -503,13 +503,6 @@ function build_user_interface() { create_campaigner('red2', 6), ] - for (let i = 0; i < 190; ++i) { - elt = ui.cubes[i] = create("div", { - className: `piece cube`, - onmousedown: on_click_cube, - }) - } - for (let i = 0; i < green_check_count; ++i) { elt = ui.green_checks[i] = create("div", { className: `piece yes`, @@ -826,6 +819,12 @@ function on_update() { // eslint-disable-line no-unused-vars function place_cubes(state_cubes, us_state, count, color) { let others = colors.filter(c => c !== color) for (let c = 0; c < count; ++c) { + if (cube_idx >= ui.cubes.length) { + ui.cubes[cube_idx] = create("div", { + className: `piece cube`, + onmousedown: on_click_cube, + }) + } e = ui.cubes[cube_idx++] e.my_us_state = us_state e.my_cube_color = color -- cgit v1.2.3