diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-12-19 17:03:16 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-16 19:19:39 +0100 |
commit | f778826847895a3bea0e31eb577204646fd20469 (patch) | |
tree | b4c028112a66908648e4f8252a3eebc4d5537629 /ui.js | |
parent | 639a9a6edb68adb9b6b7e09a7abf95a3b409d2ef (diff) | |
download | crusader-rex-f778826847895a3bea0e31eb577204646fd20469.tar.gz |
Prettier logs with formatting and colors.
Diffstat (limited to 'ui.js')
-rw-r--r-- | ui.js | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -50,6 +50,34 @@ let ui = { present: new Set(), } +create_log_entry = function (text) { + let p = document.createElement("div"); + text = text.replace(/&/g, "&"); + text = text.replace(/</g, "<"); + text = text.replace(/>/g, ">"); + + 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 Frank turn/)) + p.className = 'F'; + else if (text.match(/^Start Saracen turn/)) + p.className = 'S'; + else if (text.match(/^Start /)) + p.className = 'st'; + else if (text.match(/^(Battle in)/)) + p.className = 'bs'; + + if (text.match(/^Start /)) + text = text.substring(6); + + p.innerHTML = text; + return p; +} + function on_focus_town(evt) { let where = evt.target.town; let text = where; |