summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-05-21 13:26:14 +0200
committerTor Andersson <tor@ccxvii.net>2022-05-21 13:33:56 +0200
commit9be7f7d8beb3d037cc656b06d8289c7133d1249e (patch)
treec64e4f861a8243e2de534c2020737aaed678a845 /play.js
parentfaba28c7c3c55124f8be117cfee9d75b33ec1c7c (diff)
downloadwashingtons-war-9be7f7d8beb3d037cc656b06d8289c7133d1249e.tar.gz
Keep the bit rot away.
Diffstat (limited to 'play.js')
-rw-r--r--play.js81
1 files changed, 39 insertions, 42 deletions
diff --git a/play.js b/play.js
index 3e1e763..e5b2cc5 100644
--- a/play.js
+++ b/play.js
@@ -17,7 +17,7 @@ let ui = {
cu: [],
};
-create_log_entry = function (text) {
+function on_log(text) {
let p = document.createElement("div");
text = text.replace(/&/g, "&amp;");
text = text.replace(/</g, "&lt;");
@@ -193,21 +193,21 @@ function update_units() {
const cuX = 20;
const cuY = 10;
- update_marker(ui.turn, "Game Turn " + game.year);
- if (game.regulars)
+ update_marker(ui.turn, "Game Turn " + view.year);
+ if (view.regulars)
ui.turn.classList.remove("no-regulars");
else
ui.turn.classList.add("no-regulars");
- update_marker(ui.congress, game.congress);
+ update_marker(ui.congress, view.congress);
- update_marker(ui.french_alliance, "French Alliance Track " + game.french_alliance);
- if (game.european_war)
+ update_marker(ui.french_alliance, "French Alliance Track " + view.french_alliance);
+ if (view.european_war)
ui.french_alliance.classList.add("european-war");
else
ui.french_alliance.classList.remove("european-war");
- if (game.french_navy == "French Reinforcements") {
+ if (view.french_navy == "French Reinforcements") {
let x = BOXES["French Reinforcements"].x-130/2-10;
let y = BOXES["French Reinforcements"].y-32;
let w = 126/2;
@@ -215,11 +215,11 @@ function update_units() {
ui.french_navy.style.left = ((x-w/2)|0) + "px";
ui.french_navy.style.top = ((y-h/2)|0) + "px";
} else {
- update_marker(ui.french_navy, game.french_navy);
+ update_marker(ui.french_navy, view.french_navy);
}
for (let space in SPACES) {
- let space_pc = game.pc[space];
+ let space_pc = view.pc[space];
let e = document.getElementById(space+"-pc");
if (e) {
if (space_pc === BRITISH) {
@@ -238,9 +238,9 @@ function update_units() {
for (let c in COLONIES) {
let control = 0;
for (let space of COLONIES[c]) {
- if (game.pc[space] == BRITISH)
+ if (view.pc[space] == BRITISH)
--control;
- else if (game.pc[space] == AMERICAN)
+ else if (view.pc[space] == AMERICAN)
++control;
}
if (control < 0)
@@ -254,7 +254,7 @@ function update_units() {
let offset = {};
for (let g in GENERALS) {
let e = ui.generals[g];
- let unit = game.generals[g];
+ let unit = view.generals[g];
let space = SPACES[unit.location] || BOXES[unit.location];
if (space) {
let o = (offset[space.name]|0);
@@ -264,7 +264,7 @@ function update_units() {
} else {
e.classList.add("offmap");
}
- if (game.who == g)
+ if (view.who == g)
e.classList.add("selected");
else
e.classList.remove("selected");
@@ -273,8 +273,8 @@ function update_units() {
// TODO: reuse CU elements
offset = {};
clear_group("cu");
- for (let i = 0; i < game.cu.length; ++i) {
- let cu = game.cu[i];
+ for (let i = 0; i < view.cu.length; ++i) {
+ let cu = view.cu[i];
let space = SPACES[cu.location] || BOXES[cu.location];
let o = (offset[space.name]|0);
let x = space.x + o * cuX;
@@ -296,9 +296,9 @@ function player_info(player, nc, nq) {
if (nq > 0)
info += "\n" + nq + " OPS in queue.";
if (player == AMERICAN) {
- if (game.pennsylvania_and_new_jersey_line_mutinies)
+ if (view.pennsylvania_and_new_jersey_line_mutinies)
info += "\nPennsylvania and New Jersey Line Mutinies!";
- if (game.congress == CONTINENTAL_CONGRESS_DISPERSED)
+ if (view.congress == CONTINENTAL_CONGRESS_DISPERSED)
info += "\nContinental Congress Dispersed!";
}
return info;
@@ -307,13 +307,13 @@ function player_info(player, nc, nq) {
function on_update() {
let e;
- document.getElementById("british_info").textContent = player_info(BRITISH, game.b_cards, game.b_queue);
- document.getElementById("american_info").textContent = player_info(AMERICAN, game.a_cards, game.a_queue);
+ document.getElementById("british_info").textContent = player_info(BRITISH, view.b_cards, view.b_queue);
+ document.getElementById("american_info").textContent = player_info(AMERICAN, view.a_cards, view.a_queue);
- if (!game.last_played)
+ if (!view.last_played)
document.getElementById("last_played").className = "card show card_back";
else
- document.getElementById("last_played").className = "card show card_" + game.last_played;
+ document.getElementById("last_played").className = "card show card_" + view.last_played;
action_button("pickup_british_cu", "Pick up British CU");
action_button("pickup_american_cu", "Pick up American CU");
@@ -333,30 +333,30 @@ function on_update() {
e.classList.remove("year_1781");
e.classList.remove("year_1782");
e.classList.remove("year_1783");
- if (game.war_ends)
- e.classList.add("year_" + game.war_ends);
+ if (view.war_ends)
+ e.classList.add("year_" + view.war_ends);
e = document.getElementById("played_british_reinforcements");
e.classList.remove("ops_1");
e.classList.remove("ops_2");
e.classList.remove("ops_3");
- e.classList.add("ops_" + game.played_british_reinforcements);
+ e.classList.add("ops_" + view.played_british_reinforcements);
e = document.getElementById("played_american_reinforcements_1");
e.classList.remove("ops_1");
e.classList.remove("ops_2");
e.classList.remove("ops_3");
- if (game.played_american_reinforcements.length >= 1)
- e.classList.add("ops_" + game.played_american_reinforcements[0]);
+ if (view.played_american_reinforcements.length >= 1)
+ e.classList.add("ops_" + view.played_american_reinforcements[0]);
e = document.getElementById("played_american_reinforcements_2");
e.classList.remove("ops_1");
e.classList.remove("ops_2");
e.classList.remove("ops_3");
- if (game.played_american_reinforcements.length >= 2)
- e.classList.add("ops_" + game.played_american_reinforcements[1]);
+ if (view.played_american_reinforcements.length >= 2)
+ e.classList.add("ops_" + view.played_american_reinforcements[1]);
- let cards = game.hand;
+ let cards = view.hand;
for (let c = 1; c <= 110; ++c) {
ui.cards[c].classList.remove('enabled');
if (cards && cards.includes(c))
@@ -376,11 +376,11 @@ function on_update() {
update_units();
- if (player != game.active)
+ if (player != view.active)
return;
- for (let action of Object.keys(game.actions)) {
- let args = game.actions[action];
+ for (let action of Object.keys(view.actions)) {
+ let args = view.actions[action];
switch (action) {
case 'card_play_event':
case 'card_discard_event':
@@ -489,11 +489,11 @@ function on_exchange_for_discard() {
}
function on_card(evt) {
- if (game.actions) {
+ if (view.actions) {
let c = evt.target.id.split("+")[1] | 0;
let menu = [];
- for (let action in game.actions)
- if (Array.isArray(game.actions[action]) && game.actions[action].includes(c))
+ for (let action in view.actions)
+ if (Array.isArray(view.actions[action]) && view.actions[action].includes(c))
menu.push(action);
if (menu.length > 0) {
current_popup_card = c;
@@ -503,8 +503,8 @@ function on_card(evt) {
}
function get_action_from_arg(x) {
- for (let action of Object.keys(game.actions)) {
- let args = game.actions[action];
+ for (let action of Object.keys(view.actions)) {
+ let args = view.actions[action];
if (Array.isArray(args) && args.includes(x))
return action;
}
@@ -512,7 +512,7 @@ function get_action_from_arg(x) {
}
function on_space(evt) {
- if (game.actions) {
+ if (view.actions) {
let space = evt.target.id;
let action = get_action_from_arg(space);
if (action)
@@ -521,7 +521,7 @@ function on_space(evt) {
}
function on_general(evt) {
- if (game.actions) {
+ if (view.actions) {
let general = evt.target.id;
let action = get_action_from_arg(general);
if (action)
@@ -534,6 +534,3 @@ function toggle_markers() {
}
scroll_with_middle_mouse("main", 2);
-init_map_zoom();
-init_shift_zoom();
-init_client(["American", "British"]);