summaryrefslogtreecommitdiff
path: root/ui.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2021-06-06 22:11:00 +0200
committerTor Andersson <tor@ccxvii.net>2023-02-18 12:12:42 +0100
commit5718d3695e0783ce8695aeb51f3af797d6037e60 (patch)
treed8eb8d09a7f8f617dd61c11fc1618b04d2c67707 /ui.js
parent7edd71f76123e10a15daa5918f7f3eae2dfbf062 (diff)
downloadshores-of-tripoli-5718d3695e0783ce8695aeb51f3af797d6037e60.tar.gz
tripoli: Naval bombardment and combat.
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js33
1 files changed, 28 insertions, 5 deletions
diff --git a/ui.js b/ui.js
index b9b8928..205d42c 100644
--- a/ui.js
+++ b/ui.js
@@ -12,6 +12,17 @@ function get_space_id(name) {
return SPACES.indexOf(name);
}
+function create_piece_list(n, name) {
+ let list = [];
+ for (let i = 1; i <= n; ++i)
+ list.push(get_piece_id(name + i));
+ return list;
+}
+
+const US_FRIGATES = create_piece_list(8, 'us_frigate_');
+const TR_FRIGATES = create_piece_list(2, 'tr_frigate_');
+const FRIGATES = US_FRIGATES.concat(TR_FRIGATES);
+
const ALEXANDRIA_HARBOR = get_space_id("Alexandria Harbor");
const ALGIERS_HARBOR = get_space_id("Algiers Harbor");
const ALGIERS_PATROL_ZONE = get_space_id("Algiers Patrol Zone");
@@ -44,12 +55,12 @@ let ui = {
}
function on_focus_space(evt) {
- let where = evt.target.space;
+ let where = SPACES[evt.target.space];
document.getElementById("status").textContent = where;
}
function on_focus_piece(evt) {
- let who = evt.target.piece;
+ let who = PIECES[evt.target.piece];
document.getElementById("status").textContent = who;
}
@@ -199,15 +210,27 @@ function update_pieces() {
layout_space(game.location, TANGIER_PATROL_ZONE, 125, 410, 3);
layout_space(game.location, TRIPOLI_PATROL_ZONE, 1575, 390, 6);
layout_space(game.location, TUNIS_PATROL_ZONE, 1300, 130, 3);
+
+ for (let p of FRIGATES) {
+ if (game.damaged.includes(p))
+ ui.pieces[p].classList.add("damaged");
+ else
+ ui.pieces[p].classList.remove("damaged");
+ }
}
function update_spaces() {
- for (let space in ui.spaces)
- ui.spaces[space].classList.remove('enabled');
+ for (let space in ui.spaces) {
+ ui.spaces[space].classList.remove('highlight');
+ ui.spaces[space].classList.remove('where');
+ }
+ if (game.where != null) {
+ ui.spaces[game.where].classList.add('where');
+ }
if (game.actions && game.actions.space) {
for (let space of game.actions.space) {
console.log("enable space " + space);
- ui.spaces[space].classList.add('enabled');
+ ui.spaces[space].classList.add('highlight');
}
}
}