diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -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) { |