From 0f9ac51ba5e38390d26f38eafd6cc5844b9b2562 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 21 Apr 2023 21:36:44 +0200 Subject: Support multiple raid markers in one space. --- play.js | 44 +++++++++++++++++++++++++++++++++++++++++++- rules.js | 3 ++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/play.js b/play.js index 7e2e764..538e69d 100644 --- a/play.js +++ b/play.js @@ -854,6 +854,24 @@ function destroy_fieldworks_marker(space_id) { } } +function build_raid_marker(space_id, raid_id, faction) { + let list = markers[faction].raids + let marker = list.find(e => e.space_id === space_id && e.raid_id === raid_id) + if (marker) + return marker.element + marker = { space_id: space_id, raid_id: raid_id, name: marker_info[faction].raids.name, faction: faction, type: "raid", element: null } + let elt = marker.element = document.createElement("div") + elt.marker = marker + elt.className = marker_info[faction].raids.counter + elt.addEventListener("mousedown", on_click_marker) + elt.addEventListener("mouseenter", on_focus_marker) + elt.addEventListener("mouseleave", on_blur_marker) + elt.my_size = 36 + list.push(marker) + ui.markers.appendChild(elt) + return marker.element +} + function build_faction_marker(space_id, faction, what) { let list = markers[faction][what] let marker = list.find(e => e.space_id === space_id) @@ -884,6 +902,15 @@ function destroy_faction_marker(space_id, faction, what) { } } +function destroy_raid_markers(space_id, last_used, faction) { + let list = markers[faction].raids + let ix + while ((ix = list.findIndex(e => e.space_id === space_id && e.raid_id > last_used)) >= 0) { + list[ix].element.remove() + list.splice(ix, 1) + } +} + function build_space(id) { let space = spaces[id] @@ -1219,7 +1246,22 @@ function update_space(s) { destroy_siege_marker(s) } - marker("raids"); // TODO: more than one raid marker? + // raids + let x = 0 + if (view.british.raids.includes(s)) { + for (let m of view.british.raids) + if (m === s) + push_stack(bstack, 0, build_raid_marker(s, ++x, 'british')) + } + destroy_raid_markers(s, x, 'british') + + x = 0 + if (view.french.raids.includes(s)) { + for (let m of view.french.raids) + if (m === s) + push_stack(fstack, 0, build_raid_marker(s, ++x, 'french')) + } + destroy_raid_markers(s, x, 'french') for_each_piece_in_space(s, p => { if (view.location[p] >= 0) { diff --git a/rules.js b/rules.js index 235dcaf..b9eb743 100644 --- a/rules.js +++ b/rules.js @@ -1153,7 +1153,8 @@ function remove_fieldworks(s) { function place_friendly_raided_marker(s) { log(`Placed raided marker at %${s}.`) - set_add(player.raids, s) + player.raids.push(s) + player.raids.sort((a,b)=>a-b) } function has_friendly_raided_marker(s) { -- cgit v1.2.3