summaryrefslogtreecommitdiff
path: root/ui.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2021-12-19 17:03:16 +0100
committerTor Andersson <tor@ccxvii.net>2022-11-17 12:53:18 +0100
commite10d69474d05c66b33d8d41e181348851a54ef89 (patch)
tree743a085f6ff5adc246b43178c931d348b15e20e9 /ui.js
parent17f831488912835e592cb4458cd495deb98a9f5d (diff)
downloadhammer-of-the-scots-e10d69474d05c66b33d8d41e181348851a54ef89.tar.gz
Prettier logs with formatting and colors.
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/ui.js b/ui.js
index b4df3fd..598ad5a 100644
--- a/ui.js
+++ b/ui.js
@@ -48,6 +48,34 @@ let ui = {
present: new Set(),
}
+create_log_entry = function (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(/^~ .* ~$/))
+ p.className = 'br', text = text.substring(2, text.length-2);
+ else if (text.match(/^Start England turn/))
+ p.className = 'E';
+ else if (text.match(/^Start Scotland turn/))
+ p.className = 'S';
+ else if (text.match(/^Start /))
+ p.className = 'st';
+ else if (text.match(/^(Battle in|Defection battle in)/))
+ p.className = 'bs';
+
+ if (text.match(/^Start /))
+ text = text.substring(6);
+
+ p.innerHTML = text;
+ return p;
+}
+
function on_focus_area(evt) {
let where = evt.target.area;
document.getElementById("status").textContent = where;