summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-04-21 21:36:44 +0200
committerTor Andersson <tor@ccxvii.net>2023-05-03 10:28:23 +0200
commit0f9ac51ba5e38390d26f38eafd6cc5844b9b2562 (patch)
treec310b9367c6e88df9e0995e9b82120153b748093
parent27cb526ceaf0110780be38d90cb8817f250c38bc (diff)
downloadwilderness-war-0f9ac51ba5e38390d26f38eafd6cc5844b9b2562.tar.gz
Support multiple raid markers in one space.
-rw-r--r--play.js44
-rw-r--r--rules.js3
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) {