summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-01-06 12:36:53 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-18 12:12:42 +0100
commite06b0cc6cc27899f6f29958c16b04d44d152859b (patch)
treec0fd79c0b4d5265c3a95fd70f55c4c4f72a7070a
parent990c198dc1fee95d5de6328f47172bac31bac9aa (diff)
downloadshores-of-tripoli-e06b0cc6cc27899f6f29958c16b04d44d152859b.tar.gz
Update for new server version.
-rw-r--r--play.css4
-rw-r--r--play.html9
-rw-r--r--play.js124
-rw-r--r--rules.js10
4 files changed, 72 insertions, 75 deletions
diff --git a/play.css b/play.css
index f1d6e66..befdd04 100644
--- a/play.css
+++ b/play.css
@@ -4,8 +4,8 @@ header { background-color: silver; }
.card_info { background-color: silver; }
body.Tripolitania header.your_turn { background-color: salmon; }
body.United_States header.your_turn { background-color: skyblue; }
-.one .role_name { background-color: skyblue; }
-.two .role_name { background-color: salmon; }
+#role_United_States .role_name { background-color: skyblue; }
+#role_Tripolitania .role_name { background-color: salmon; }
#log { background-color: #eee; }
#log .st { background-color: #777; color: white; font-weight: bold; padding:3px; text-align: center; }
diff --git a/play.html b/play.html
index 80ff639..16ef5e8 100644
--- a/play.html
+++ b/play.html
@@ -7,10 +7,9 @@
<title>SHORES OF TRIPOLI</title>
<link rel="icon" href="Flag_of_Tripoli_18th_century.svg">
<link rel="stylesheet" href="/fonts/fonts.css">
-<link rel="stylesheet" href="/common/grid.css">
+<link rel="stylesheet" href="/common/play.css">
<link rel="stylesheet" href="play.css">
-<script defer src="/socket.io/socket.io.min.js"></script>
-<script defer src="/common/client.js"></script>
+<script defer src="/common/play.js"></script>
<script defer src="data.js"></script>
<script defer src="play.js"></script>
</head>
@@ -49,7 +48,7 @@
<aside>
<div id="roles">
- <div class="role one">
+ <div class="role" id="role_United_States">
<div class="role_name">
United States
<div class="role_vp" id="us_score">30</div>
@@ -57,7 +56,7 @@
</div>
<div class="role_info" id="us_info">Hand: X / Draw: X / Discard: X</div>
</div>
- <div class="role two">
+ <div class="role" id="role_Tripolitania">
<div class="role_name">
Tripolitania
<div class="role_vp" id="tr_score">0</div>
diff --git a/play.js b/play.js
index 7a05d8c..ec881e9 100644
--- a/play.js
+++ b/play.js
@@ -1,7 +1,5 @@
"use strict";
-/* global game, PIECES, SPACES */
-
const SEASON_X = [ 893, 978, 1064, 1149 ];
const YEAR_X = { 1801: 175, 1802: 294, 1803: 413, 1804: 532, 1805: 652, 1806: 771 };
const YEAR_Y = 728;
@@ -172,11 +170,11 @@ function on_click_space(evt) { send_action('space', evt.target.space); }
function on_click_piece(evt) { send_action('piece', evt.target.piece); }
function on_focus_active_card(evt) {
- if (typeof game.card === 'number') {
- if (game.card < 27)
- document.getElementById("tooltip").className = "card show us_card_" + game.card;
+ if (typeof view.card === 'number') {
+ if (view.card < 27)
+ document.getElementById("tooltip").className = "card show us_card_" + view.card;
else
- document.getElementById("tooltip").className = "card show tr_card_" + (game.card-27);
+ document.getElementById("tooltip").className = "card show tr_card_" + (view.card-27);
}
}
@@ -237,9 +235,9 @@ const CARD_ACTIONS = [
];
function is_card_enabled(c) {
- if (game.actions)
+ if (view.actions)
for (let a of CARD_ACTIONS)
- if (game.actions[a] && game.actions[a].includes(c))
+ if (view.actions[a] && view.actions[a].includes(c))
return true;
return false;
}
@@ -257,12 +255,12 @@ function update_card(c, show) {
function update_cards() {
for (let i = 1; i <= 3; ++i) {
- update_card(i, game.core.includes(i));
- update_card(i+27, game.core.includes(i+27));
+ update_card(i, view.core.includes(i));
+ update_card(i+27, view.core.includes(i+27));
}
for (let i = 4; i <= 27; ++i) {
- update_card(i, game.hand.includes(i));
- update_card(i+27, game.hand.includes(i+27));
+ update_card(i, view.hand.includes(i));
+ update_card(i+27, view.hand.includes(i+27));
}
}
@@ -270,17 +268,17 @@ function update_cards() {
function tr_info() {
let text = "";
- text += "Hand: " + game.tr.hand + " / ";
- text += "Draw: " + game.tr.draw + " / ";
- text += "Discard: " + game.tr.discard + "\n";
+ text += "Hand: " + view.tr.hand + " / ";
+ text += "Draw: " + view.tr.draw + " / ";
+ text += "Discard: " + view.tr.discard + "\n";
return text;
}
function us_info() {
let text = "";
- text += "Hand: " + game.us.hand + " / ";
- text += "Draw: " + game.us.draw + " / ";
- text += "Discard: " + game.us.discard + "\n";
+ text += "Hand: " + view.us.hand + " / ";
+ text += "Draw: " + view.us.draw + " / ";
+ text += "Discard: " + view.us.discard + "\n";
return text;
}
@@ -289,24 +287,24 @@ function on_update() {
action_button("next", "Next");
action_button("undo", "Undo");
- document.getElementById("tr_score").textContent = game.tr.score;
- document.getElementById("us_score").textContent = game.us.score;
+ document.getElementById("tr_score").textContent = view.tr.score;
+ document.getElementById("us_score").textContent = view.us.score;
document.getElementById("tr_info").textContent = tr_info();
document.getElementById("us_info").textContent = us_info();
- if (game.card === undefined)
+ if (view.card === undefined)
document.getElementById("active_card").className = "card show blank";
- else if (game.card === "United States")
+ else if (view.card === "United States")
document.getElementById("active_card").className = "card show us_card_back";
- else if (game.card === "Tripolitania")
+ else if (view.card === "Tripolitania")
document.getElementById("active_card").className = "card show tr_card_back";
- else if (game.card < 27)
- document.getElementById("active_card").className = "card show us_card_" + game.card;
+ else if (view.card < 27)
+ document.getElementById("active_card").className = "card show us_card_" + view.card;
else
- document.getElementById("active_card").className = "card show tr_card_" + (game.card-27);
+ document.getElementById("active_card").className = "card show tr_card_" + (view.card-27);
- update_year_marker(game.year);
- update_season_marker(game.season);
+ update_year_marker(view.year);
+ update_season_marker(view.season);
update_gold();
update_pieces();
update_cards();
@@ -390,41 +388,41 @@ function layout_space(location, s, x0, y0, size) {
}
function update_pieces() {
- layout_space(game.location, UNITED_STATES_SUPPLY, 1933, 180, 6);
- layout_space(game.location, TRIPOLITAN_SUPPLY, 2195, 180, 6);
-
- layout_space(game.location, TRACK_1801, YEAR_X[1801], 625, 2);
- layout_space(game.location, TRACK_1802, YEAR_X[1802], 625, 2);
- layout_space(game.location, TRACK_1803, YEAR_X[1803], 625, 2);
- layout_space(game.location, TRACK_1804, YEAR_X[1804], 625, 2);
- layout_space(game.location, TRACK_1805, YEAR_X[1805], 625, 2);
- layout_space(game.location, TRACK_1806, YEAR_X[1806], 625, 2);
-
- layout_space(game.location, ALEXANDRIA, 2335, 454, 3);
- layout_space(game.location, ALGIERS, 883, 318, 3);
- layout_space(game.location, BENGHAZI, 1877, 583, 3);
- layout_space(game.location, DERNE, 2030, 437, 3);
- layout_space(game.location, GIBRALTAR, 374, 216, 3);
- layout_space(game.location, MALTA, 1592, 189, 3);
- layout_space(game.location, TANGIER, 296, 426, 3);
- layout_space(game.location, TRIPOLI, 1416, 604, 5);
- layout_space(game.location, TUNIS, 1232, 278, 3);
-
- layout_space(game.location, ALGIERS_PATROL_ZONE, 875, 170, 3);
- layout_space(game.location, GIBRALTAR_PATROL_ZONE, 560, 245, 3);
- layout_space(game.location, TANGIER_PATROL_ZONE, 125, 410, 3);
- layout_space(game.location, TRIPOLI_PATROL_ZONE, 1575, 420, 5);
- layout_space(game.location, TUNIS_PATROL_ZONE, 1300, 130, 3);
+ layout_space(view.location, UNITED_STATES_SUPPLY, 1933, 180, 6);
+ layout_space(view.location, TRIPOLITAN_SUPPLY, 2195, 180, 6);
+
+ layout_space(view.location, TRACK_1801, YEAR_X[1801], 625, 2);
+ layout_space(view.location, TRACK_1802, YEAR_X[1802], 625, 2);
+ layout_space(view.location, TRACK_1803, YEAR_X[1803], 625, 2);
+ layout_space(view.location, TRACK_1804, YEAR_X[1804], 625, 2);
+ layout_space(view.location, TRACK_1805, YEAR_X[1805], 625, 2);
+ layout_space(view.location, TRACK_1806, YEAR_X[1806], 625, 2);
+
+ layout_space(view.location, ALEXANDRIA, 2335, 454, 3);
+ layout_space(view.location, ALGIERS, 883, 318, 3);
+ layout_space(view.location, BENGHAZI, 1877, 583, 3);
+ layout_space(view.location, DERNE, 2030, 437, 3);
+ layout_space(view.location, GIBRALTAR, 374, 216, 3);
+ layout_space(view.location, MALTA, 1592, 189, 3);
+ layout_space(view.location, TANGIER, 296, 426, 3);
+ layout_space(view.location, TRIPOLI, 1416, 604, 5);
+ layout_space(view.location, TUNIS, 1232, 278, 3);
+
+ layout_space(view.location, ALGIERS_PATROL_ZONE, 875, 170, 3);
+ layout_space(view.location, GIBRALTAR_PATROL_ZONE, 560, 245, 3);
+ layout_space(view.location, TANGIER_PATROL_ZONE, 125, 410, 3);
+ layout_space(view.location, TRIPOLI_PATROL_ZONE, 1575, 420, 5);
+ layout_space(view.location, TUNIS_PATROL_ZONE, 1300, 130, 3);
for (let p of FRIGATES) {
- if (game.damaged.includes(p))
+ if (view.damaged.includes(p))
ui.pieces[p].classList.add("damaged");
else
ui.pieces[p].classList.remove("damaged");
}
for (let p = 0; p < PIECES.length; ++p) {
- if (game.actions && game.actions.piece && game.actions.piece.includes(p))
+ if (view.actions && view.actions.piece && view.actions.piece.includes(p))
ui.pieces[p].classList.add("highlight");
else
ui.pieces[p].classList.remove("highlight");
@@ -432,7 +430,7 @@ function update_pieces() {
}
function update_gold() {
- let split = 12 - game.tr.gold;
+ let split = 12 - view.tr.gold;
let x, y;
x = 690;
y = 50;
@@ -453,11 +451,11 @@ function update_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 (view.where !== null) {
+ ui.spaces[view.where].classList.add('where');
}
- if (game.actions && game.actions.space) {
- for (let space of game.actions.space) {
+ if (view.actions && view.actions.space) {
+ for (let space of view.actions.space) {
ui.spaces[space].classList.add('highlight');
}
}
@@ -520,11 +518,11 @@ function on_card_build_corsair() {
}
function is_card_action(action, card) {
- return game.actions && game.actions[action] && game.actions[action].includes(card);
+ return view.actions && view.actions[action] && view.actions[action].includes(card);
}
function on_click_card(evt) {
- if (game.actions) {
+ if (view.actions) {
let card = evt.target.card;
if (is_card_action('discard', card)) {
send_action('discard', card);
@@ -548,5 +546,3 @@ function on_click_card(evt) {
build_map();
scroll_with_middle_mouse("main");
-init_map_zoom();
-init_client([ "United States", "Tripolitania" ]);
diff --git a/rules.js b/rules.js
index 11ca1dd..673ef5a 100644
--- a/rules.js
+++ b/rules.js
@@ -334,7 +334,7 @@ function clear_undo() {
function push_undo() {
game.undo.push(JSON.stringify(game, (k,v) => {
- if (k === 'undo') return undefined;
+ if (k === 'undo') return 0;
if (k === 'log') return v.length;
return v;
}));
@@ -343,7 +343,7 @@ function push_undo() {
function pop_undo() {
let undo = game.undo;
let save_log = game.log;
- Object.assign(game, JSON.parse(undo.pop()));
+ game = JSON.parse(undo.pop());
game.undo = undo;
save_log.length = game.log;
game.log = save_log;
@@ -2880,7 +2880,7 @@ exports.action = function (state, current, action, arg) {
S[action](arg, current);
else
throw new Error("Invalid action: " + action);
- return state;
+ return game;
}
exports.resign = function (state, current) {
@@ -2891,9 +2891,11 @@ exports.resign = function (state, current) {
if (current === TR)
goto_game_over(US, "Tripolitania resigned.");
}
- return state;
+ return game;
}
+exports.is_checkpoint = (a, b) => a.season !== b.season;
+
exports.view = function(state, current) {
game = state;