From e9a84ae8f28b98981b5af247731cc3c8949a0544 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 9 Nov 2024 13:04:14 +0100 Subject: fix display of conquest/victory/retroactive marker stacking --- play.html | 4 ++-- play.js | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/play.html b/play.html index bd8cb5b..683ff54 100644 --- a/play.html +++ b/play.html @@ -38,8 +38,8 @@ -
  • Propose subsidy contract -
  • Cancel subsidy contract +
  • Propose subsidy +
  • Cancel subsidy
  • Propose deal
  • diff --git a/play.js b/play.js index 9ad4ede..6f7f17e 100644 --- a/play.js +++ b/play.js @@ -4,6 +4,9 @@ /* globals data, view, action_button, action_button_with_argument, confirm_action_button, send_action, params */ +// TODO: animate_position on pieces instead of top/left transition +// TODO: animate_position on political markers instead of top/left transition + function toggle_pieces() { // Cycle between showing everything, only pieces, and nothing. let hidden_pieces = ui.pieces_element.classList.contains("hide") @@ -1475,16 +1478,19 @@ function on_update() { ui.markers_element.replaceChildren() - for (let i = 0; i < view.victory.length; i += 2) - layout_victory(view.victory[i], view.victory[i+1]) for (let i = 0; i < view.retro.length; i += 2) layout_retro(view.retro[i], view.retro[i+1]) + for (let i = 0; i < view.victory.length; i += 2) + if (!map_has(view.retro, view.victory[i])) + layout_victory(view.victory[i], view.victory[i+1]) + if (!is_intro()) { update_political() for (let i = 0; i < view.elector.length; i += 2) - layout_elector(view.elector[i], view.elector[i+1]) + if (!map_has(view.retro, view.elector[i])) + layout_elector(view.elector[i], view.elector[i+1]) layout_electoral_college(0, P_PRAGMATIC) for (let i = 0; i < all_electoral_colleges.length; ++i) { @@ -1889,6 +1895,22 @@ function set_intersect(one, two) { return set } +function map_has(map, key) { + let a = 0 + let b = (map.length >> 1) - 1 + while (a <= b) { + let m = (a + b) >> 1 + let x = map[m<<1] + if (key < x) + b = m - 1 + else if (key > x) + a = m + 1 + else + return true + } + return false +} + function map_get(map, key, missing) { let a = 0 let b = (map.length >> 1) - 1 -- cgit v1.2.3