summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-10-02 22:55:13 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-16 19:12:55 +0100
commit048c9064a827b55bce6dda74e2007d616a33964d (patch)
treebae4e3666189f5a53ba9957ea7d9eccb80b27988
parente269954c8a936600f3d3d7fdba156b046e586df5 (diff)
downloadrichard-iii-048c9064a827b55bce6dda74e2007d616a33964d.tar.gz
New log format.
-rw-r--r--play.css7
-rw-r--r--play.js75
-rw-r--r--rules.js35
3 files changed, 68 insertions, 49 deletions
diff --git a/play.css b/play.css
index b287433..c9251be 100644
--- a/play.css
+++ b/play.css
@@ -9,11 +9,12 @@ header.your_turn { background-color: orange; }
#log { background-color: ghostwhite; }
#log div { padding-left: 20px; text-indent: -12px; }
-#log .st { background-color: steelblue; color: white; font-weight: bold; }
+#log div.i { padding-left: 32px; text-indent: -12px; }
+#log .h1 { background-color: steelblue; color: white; font-weight: bold; }
#log .L { background-color: pink; }
#log .Y { background-color: gainsboro; }
-#log .bs { background-color: lightsteelblue; }
-#log .br { font-style: italic; text-decoration: underline; }
+#log .h3 { background-color: lightsteelblue; }
+#log .h4 { font-style: italic; text-decoration: underline; }
.hand {
margin: 25px;
diff --git a/play.js b/play.js
index ea429df..ccac1cb 100644
--- a/play.js
+++ b/play.js
@@ -62,38 +62,55 @@ let ui = {
present: new Set(),
}
+function on_focus_space_tip(x) {
+ ui.areas[x].classList.add("tip")
+}
+
+function on_blur_space_tip(x) {
+ ui.areas[x].classList.remove("tip")
+}
+
+function on_click_space_tip(x) {
+ ui.areas[x].scrollIntoView({ block:"center", inline:"center", behavior:"smooth" })
+}
+
+function sub_space_name(match, p1, offset, string) {
+ let x = p1 | 0
+ let n = AREAS[x].name
+ return `<span class="tip" onmouseenter="on_focus_space_tip(${x})" onmouseleave="on_blur_space_tip(${x})" onclick="on_click_space_tip(${x})">${n}</span>`
+}
+
function on_log(text) {
- let p = document.createElement("div");
- text = text.replace(/&/g, "&amp;");
- text = text.replace(/</g, "&lt;");
- text = text.replace(/>/g, "&gt;");
-
- text = text.replace(/\u2192 /g, "\u2192\xa0");
-
- text = text.replace(/^([A-Z]):/, '<span class="$1"> $1 </span>');
-
- if (text.match(/^Scenario: /)) {
- p.className = 'st', text = text.substring(10);
- } else if (text.match(/^~ .* ~$/)) {
- p.className = 'br', text = text.substring(2, text.length-2);
- } else if (text.match(/^Start Lancaster turn/)) {
- text = "Lancaster";
- p.className = 'L';
- } else if (text.match(/^Start York turn/)) {
- text = "York";
- p.className = 'Y';
- } else if (text.match(/^Start /)) {
- p.className = 'st', text = text.replace(/\.$/, "");
- } else if (text.match(/^Battle in/)) {
- text = text.substring(0,text.length-1);
- p.className = 'bs';
- }
+ let p = document.createElement("div")
+
+ if (text.match(/^>/)) {
+ text = text.substring(1)
+ p.className = "i"
+ }
+
+ text = text.replace(/&/g, "&amp;")
+ text = text.replace(/</g, "&lt;")
+ text = text.replace(/>/g, "&gt;")
+
+ text = text.replace(/\u2192 /g, "\u2192\xa0")
+
+ text = text.replace(/^([A-Z]):/, '<span class="$1"> $1 </span>')
+
+ text = text.replace(/#(\d+)/g, sub_space_name)
- if (text.match(/^Start /))
- text = text.substring(6);
+ if (text.match(/^\.h1 /))
+ p.className = 'h1', text = text.substring(4)
+ if (text.match(/^\.h2 L/))
+ p.className = 'h2 L', text = text.substring(4)
+ if (text.match(/^\.h2 Y/))
+ p.className = 'h2 Y', text = text.substring(4)
+ if (text.match(/^\.h3 /))
+ p.className = 'h3', text = text.substring(4)
+ if (text.match(/^\.h4 /))
+ p.className = 'h4', text = text.substring(4)
- p.innerHTML = text;
- return p;
+ p.innerHTML = text
+ return p
}
function is_known_block(b) {
diff --git a/rules.js b/rules.js
index bab505c..8a5e58f 100644
--- a/rules.js
+++ b/rules.js
@@ -66,6 +66,10 @@ function logp(s) {
game.log.push(game.active + " " + s)
}
+function logi(s) {
+ game.log.push(">" + s)
+}
+
function log(s) {
game.log.push(s)
}
@@ -89,40 +93,37 @@ function log_move_end() {
}
function print_turn_log_no_count(text) {
- function print_move(last) {
- return "\n" + last.join(" \u2192 ")
- }
+ log(text)
if (game.turn_log.length > 0) {
game.turn_log.sort()
for (let entry of game.turn_log)
- text += print_move(entry)
+ logi(entry.join(" \u2192 "))
} else {
- text += "\nnothing."
+ logi("nothing.")
}
- log(text)
delete game.turn_log
}
function print_turn_log(text) {
function print_move(last) {
- return "\n" + n + " " + last.join(" \u2192 ")
+ logi(n + " " + last.join(" \u2192 "))
}
game.turn_log.sort()
let last = game.turn_log[0]
+ log(text)
let n = 0
for (let entry of game.turn_log) {
if (entry.toString() !== last.toString()) {
- text += print_move(last)
+ print_move(last)
n = 0
}
++n
last = entry
}
if (n > 0)
- text += print_move(last)
+ print_move(last)
else
- text += "\nnothing."
- log(text)
+ logi("nothing.")
delete game.turn_log
}
@@ -1310,7 +1311,7 @@ function free_henry_vi() {
function start_campaign() {
logbr()
- log("Start Campaign " + game.campaign + ".")
+ log(".h1 Campaign " + game.campaign)
// TODO: Use board game mulligan rules instead of automatically redealing?
do {
@@ -1326,7 +1327,7 @@ function start_game_turn() {
game.turn = 8 - game.l_hand.length
logbr()
- log("Start Turn " + game.turn + " of campaign " + game.campaign + ".")
+ log(".h1 Turn " + game.turn + " of campaign " + game.campaign + ".")
// Reset movement and attack tracking state
reset_border_limits()
@@ -1449,7 +1450,7 @@ function reveal_cards() {
function start_player_turn() {
logbr()
- log("Start " + game.active + " turn.")
+ log(".h2 " + game.active)
reset_border_limits()
let lc = CARDS[game.l_card]
let yc = CARDS[game.y_card]
@@ -1974,7 +1975,7 @@ states.battle_phase = {
function start_battle(where) {
game.flash = ""
logbr()
- log("Battle in " + where + ".")
+ log(".h3 Battle in #" + where)
game.where = where
game.battle_round = 0
game.defected = []
@@ -2960,7 +2961,7 @@ states.supply_limits_king = {
function goto_political_turn() {
logbr()
- log("Start Political Turn.")
+ log(".h1 Political Turn")
logbr()
game.turn_log = []
@@ -3398,7 +3399,7 @@ exports.setup = function (seed, scenario, options) {
else
throw new Error("Unknown scenario:", scenario)
- log("Scenario: " + scenario)
+ log(".h1 " + scenario)
start_campaign()
return game
}