diff options
-rw-r--r-- | play.css | 16 | ||||
-rw-r--r-- | play.js | 68 | ||||
-rw-r--r-- | rules.js | 101 |
3 files changed, 125 insertions, 60 deletions
@@ -15,11 +15,15 @@ header.your_turn { background-color: orange; } #log { background-color: wheat; } #log div { padding-left: 20px; text-indent: -12px; } -#log .st { background-color: brown; color: gold; font-weight: bold; } +#log div.i { padding-left: 32px; text-indent: -12px; } +#log div.i { font-style: italic; } +#log .h1 { background-color: brown; color: gold; font-weight: bold; } +#log .h2 { background-color: brown; color: gold; font-weight: bold; } #log .C { background-color: salmon; } #log .P { background-color: #eb5; } -#log .bs { background-color: tan; } -#log .br { font-style: italic; text-decoration: underline; } +#log .h4 { background-color: tan; } +#log .h5 { font-style: italic; text-decoration: underline; } +#log .tip:hover { text-decoration: underline; cursor: pointer; } /* CARDS */ @@ -165,6 +169,12 @@ header.your_turn { background-color: orange; } opacity: 0.8; z-index: 9; } +.space.tip { + opacity: 1; + border-color: yellow; + border-style: dashed; + z-index: 9; +} #blocks.hide_blocks { display: none; @@ -76,19 +76,48 @@ const step_up_animation = [ ] let ui = { - cards: {}, - card_backs: {}, - spaces: {}, - blocks: {}, - battle_menu: {}, - battle_block: {}, + cards: [], + card_backs: [], + spaces: [], + blocks: [], + battle_menu: [], + battle_block: [], old_steps: null, old_location: null, present: new Set(), } +function on_focus_space_tip(x) { + ui.spaces[x].classList.add("tip") +} + +function on_blur_space_tip(x) { + ui.spaces[x].classList.remove("tip") +} + +function on_click_space_tip(x) { + ui.spaces[x].scrollIntoView({ block:"center", inline:"center", behavior:"smooth" }) +} + +function sub_space_name(match, p1, offset, string) { + let x = p1 | 0 + let n = SPACES[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") + + if (text.match(/^>>/)) { + text = text.substring(2) + p.className = "ii" + } + + if (text.match(/^>/)) { + text = text.substring(1) + p.className = "i" + } + text = text.replace(/&/g, "&") text = text.replace(/</g, "<") text = text.replace(/>/g, ">") @@ -98,19 +127,20 @@ function on_log(text) { 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 Caesar/)) - p.className = 'C' - else if (text.match(/^Start Pompeius/)) - p.className = 'P' - else if (text.match(/^Start /)) - p.className = 'st', text = text.replace(/\.$/, "") - else if (text.match(/^Battle in/)) - p.className = 'bs' - - if (text.match(/^Start /)) - text = text.substring(6) + text = text.replace(/#(\d+)/g, sub_space_name) + + if (text.match(/^\.h1 /)) + p.className = 'h1', text = text.substring(4) + if (text.match(/^\.h2 /)) + p.className = 'h2', text = text.substring(4) + if (text.match(/^\.h3 C/)) + p.className = 'h3 C', text = text.substring(4) + if (text.match(/^\.h3 P/)) + p.className = 'h3 P', text = text.substring(4) + if (text.match(/^\.h4 /)) + p.className = 'h4', text = text.substring(4) + if (text.match(/^\.h5 /)) + p.className = 'h5', text = text.substring(4) p.innerHTML = text return p @@ -65,11 +65,18 @@ function logbr() { game.log.push("") } -function log(...args) { - let s = Array.from(args).join("") +function log(s) { game.log.push(s) } +function logi(s) { + game.log.push(">" + s) +} + +function logii(s) { + game.log.push(">>" + s) +} + function log_battle(s) { game.log.push(game.active[0] + ": " + s) } @@ -80,16 +87,16 @@ function logp(s) { function log_move_start(from, to, mark = false) { if (mark) - game.turn_buf = [ space_name(from), space_name(to) + mark ] + game.turn_buf = [ from, to, mark ] else - game.turn_buf = [ space_name(from), space_name(to) ] + game.turn_buf = [ from, to ] } function log_move_continue(to, mark = false) { if (mark) - game.turn_buf.push(space_name(to) + mark) + game.turn_buf.push(to, mark) else - game.turn_buf.push(space_name(to)) + game.turn_buf.push(to) } function log_move_end() { @@ -100,30 +107,42 @@ function log_move_end() { } function log_levy(where) { - game.turn_log.push([space_name(where)]) + game.turn_log.push([where]) } function print_turn_log_no_active(text) { - function print_move(last) { - return "\n" + n + " " + last.join(" \u2192 ") - } - game.turn_log.sort() - let last = game.turn_log[0] + let lines = game.turn_log.map(function (move) { + let s = "" + for (let i = 0; i < move.length; ++i) { + let x = move[i] + if (typeof x === 'string') { + s += x + } else { + if (i > 0) + s += " \u2192 " + s += "#" + x + } + } + return s + }).sort() + delete game.turn_log + + log(text) + + let last = lines[0] let n = 0 - for (let entry of game.turn_log) { - if (entry.toString() !== last.toString()) { - text += print_move(last) + for (let entry of lines) { + if (entry !== last) { + logi(n + " " + last) n = 0 } ++n last = entry } if (n > 0) - text += print_move(last) + logi(n + " " + last) else - text += "\nnothing." - log(text) - delete game.turn_log + logi("nothing.") } function print_turn_log(verb) { @@ -868,7 +887,7 @@ states.free_deployment_to = { function start_year() { logbr() - log("Start Year " + game.year) + log(".h1 Year " + game.year) game.turn = 1 let deck = reset_deck() game.c_hand = deal_cards(deck, 6) @@ -983,7 +1002,7 @@ function start_first_turn() { game.moved = [] game.reserves = [] logbr() - log("Start Turn " + game.turn + " of Year " + game.year) + log(".h2 Turn " + game.turn + " of Year " + game.year) reveal_cards() } @@ -1002,7 +1021,7 @@ function start_turn() { game.show_cards = false game.surprise = 0 logbr() - log("Start Turn " + game.turn + " of Year " + game.year) + log(".h2 Turn " + game.turn + " of Year " + game.year) } function resume_play_card() { @@ -1135,7 +1154,7 @@ function reveal_cards() { function start_player_turn() { logbr() - log("Start " + game.active) + log(".h3 " + game.active) reset_road_limits() game.activated = [] @@ -1259,8 +1278,8 @@ states.jupiter_to = { gen_action_space(view, to) }, space: function (to) { - log(block_name(game.who) + " joined " + game.active + ":\n" + - game.location[game.who] + " \u2192 " + space_name(to) + ".") + log(block_name(game.who) + " joined " + game.active + ":") + logi("#"+game.location[game.who] + " \u2192 #" + to + ".") game.location[game.who] = to game.who = -1 end_player_turn() @@ -1277,7 +1296,7 @@ states.vulcan = { gen_action_space(view, s) }, space: function (city) { - log("Vulcan struck " + space_name(city) + "!") + log("Vulcan struck #" + city + "!") if (game.automatic_disruption) { for (let b = 0; b < block_count; ++b) if (game.location[b] === city) @@ -1332,7 +1351,7 @@ function goto_mars_and_neptune() { } if (game.surprise_list.length === 1) { game.surprise = game.surprise_list[0] - log("Surprise attack in " + space_name(game.surprise) + ".") + log("Surprise attack in #" + game.surprise + ".") delete game.surprise_list return end_player_turn() } @@ -1350,7 +1369,7 @@ states.mars_and_neptune = { }, space: function (where) { game.surprise = where - log("Surprise attack in " + space_name(game.surprise) + ".") + log("Surprise attack in #" + game.surprise + ".") delete game.surprise_list end_player_turn() }, @@ -1480,7 +1499,7 @@ states.move_where = { } } else { if (!game.activated.includes(from)) { - logp("activated " + space_name(from) + ".") + logp("activated #" + from + ".") game.moves -- game.activated.push(from) } @@ -1570,7 +1589,7 @@ states.mercury_move_1 = { space: function (to) { let from = game.location[game.who] if (!game.activated.includes(from)) { - logp("activated " + space_name(from) + ".") + logp("activated #" + from + ".") game.moves -- game.activated.push(from) } @@ -1801,7 +1820,7 @@ function start_battle() { game.battle_round = 0 game.flash = "" logbr() - log("Battle in " + space_name(game.where)) + log(".h4 Battle in #" + game.where) if (game.surprise === game.where) log("Surprise attack.") game.state = 'battle_round' @@ -1854,7 +1873,7 @@ function end_disrupt_reserves() { game.flash = "" delete game.disrupted bring_on_reserves() - log("~ Battle Round " + game.battle_round + " ~") + log(".h5 Battle Round " + game.battle_round) pump_battle_round() } @@ -1876,7 +1895,7 @@ states.disrupt_reserves = { function start_battle_round() { if (++game.battle_round <= 4) { if (game.turn_log && game.turn_log.length > 0) - print_turn_log_no_active("Retreated from " + game.where + ":") + print_turn_log_no_active("Retreated from #" + game.where + ":") game.turn_log = [] reset_road_limits() @@ -1899,7 +1918,7 @@ function start_battle_round() { bring_on_reserves() } - log("~ Battle Round " + game.battle_round + " ~") + log(".h5 Battle Round " + game.battle_round) pump_battle_round() } else { @@ -1965,7 +1984,7 @@ function pump_battle_round() { function end_battle() { if (game.turn_log && game.turn_log.length > 0) - print_turn_log_no_active("Retreated from " + game.where + ":") + print_turn_log_no_active("Retreated from #" + game.where + ":") if (game.surprise === game.where) game.surprise = 0 game.flash = "" @@ -2254,7 +2273,7 @@ function goto_regroup() { game.active = get_attacker(game.where) if (is_enemy_space(game.where)) game.active = enemy(game.active) - log(game.active + " won the battle in " + space_name(game.where) + "!") + log(game.active + " won the battle in #" + game.where + "!") game.state = 'regroup' game.turn_log = [] clear_undo() @@ -2355,7 +2374,7 @@ function check_victory() { end_game() } else { logbr() - log("Start Winter Turn of Year " + game.year) + log(".h2 Winter Turn of Year " + game.year) logbr() start_navis_to_port() } @@ -2587,8 +2606,14 @@ exports.setup = function (seed, scenario, options) { if (options.rng) game.rng = options.rng + if (scenario === "Historical") + log(".h1 Historical Deployment") + else + log(".h1 " + scenario) + logbr() + if (options.tournament) { - log("Tournament rule:\nCaesar is the first player on the very first turn of the game.") + log("Tournament rule: Caesar is the first player on the very first turn of the game.") game.tournament = 1 } |