From 73616b835394b357d5cc9ed1a2219249862462f9 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 6 Jun 2024 14:19:09 +0200 Subject: eslint and other cleanups --- play.css | 2 +- play.js | 26 +++----------------------- rules.js | 51 +++++++++++++-------------------------------------- 3 files changed, 17 insertions(+), 62 deletions(-) diff --git a/play.css b/play.css index 817d1af..8e9fdad 100644 --- a/play.css +++ b/play.css @@ -121,7 +121,7 @@ body { min-height: 6px; } -.city_tip .piece_tip, .move_tip { cursor: pointer; } +.city_tip, .piece_tip, .move_tip { cursor: pointer; } .city_tip:hover, .piece_tip:hover, .move_tip:hover { text-decoration: underline; } #log .h { diff --git a/play.js b/play.js index 9f7e449..7eb5c21 100644 --- a/play.js +++ b/play.js @@ -564,8 +564,8 @@ const ui = { document.getElementById("hand_france"), ], cities: [], - action_register: [], roads: [], + action_register: [], } function register_action(target, action, id) { @@ -1091,9 +1091,6 @@ function colorize(text) { text = text.replaceAll("\u2663", colorize_C) text = text.replaceAll("\u2665", colorize_H) text = text.replaceAll("\u2666", colorize_D) - -/* - */ return text } @@ -1133,7 +1130,7 @@ function player_from_power(pow) { return role } -function update_player_power_list(role, powers) { +function update_player_power_list(role) { if (roles[role]) { roles[role].stat.replaceChildren() for (let pow of all_powers) @@ -1148,7 +1145,7 @@ function update_player_active(name) { } function on_prompt(text) { - return colorize(view.prompt) + return colorize(text) } function on_update() { @@ -1433,22 +1430,6 @@ function sub_path(pieces_and_spaces) { return `${ps_name} to ${ss_name}.` } -const suit_icon = [ - '\u2660', - '\u2663', - '\u2665', - '\u2666', - 'R', -] - -function sub_tc(_match, p1) { - let c = p1 | 0 - let d = to_deck(c) - let v = to_value(c) - let s = to_suit(c) - return `${v}${suit_icon[s]}` -} - const strokes_of_fate_name = [ "Poems", "Lord Bute", @@ -1485,7 +1466,6 @@ function on_log(text) { text = colorize(text) text = text.replace(/S(\d+)/g, sub_space) text = text.replace(/P(\d+)/g, sub_piece) - text = text.replace(/C(\d+)/g, sub_tc) if (text.startsWith("@")) { p.className = "move_tip" diff --git a/rules.js b/rules.js index df845cc..1ecdf74 100644 --- a/rules.js +++ b/rules.js @@ -339,12 +339,6 @@ function is_west_of(here, there) { return dx < 0 && Math.abs(dx) >= Math.abs(dy) } -function format_card_list(list) { - if (list.length > 0) - return list.map(format_card).join(", ") - return "nothing" -} - function format_card_list_prompt(list) { if (list.length > 0) return list.map(format_card_prompt).join(", ") @@ -357,36 +351,14 @@ function format_selected() { return game.selected.map(p => piece_name[p]).join(" and ") } -function log_selected() { - log(game.selected.map(p => "P" + p).join(" and ")) +function log_move_to(to) { + let from = game.pos[game.selected[0]] + log("@" + game.selected.join(",") + ";" + from + "," + to) } -function is_important_move(s) { - return set_has(game.move_conq, s) || set_has(game.move_reconq, s) || set_has(game.retro, s) -} - -function log_small_move_to(to) { - if (0) { - log_selected() - log(">from S" + game.pos[game.selected[0]]) - log(">to S" + s) - } else { - let from = game.pos[game.selected[0]] - log("@" + game.selected.join(",") + ";" + from + "," + to) - } -} - -function log_selected_move_path() { - if (0) { - log_selected() - log(">from S" + game.move_path[0]) - for (let i = 1; i < game.move_path.length; ++i) - if (is_important_move(game.move_path[i]) || i === game.move_path.length-1) - log(">to S" + game.move_path[i]) - } else { - if (game.move_path.length > 1) - log("@" + game.selected.join(",") + ";" + game.move_path.join(",")) - } +function log_move_path() { + if (game.move_path.length > 1) + log("@" + game.selected.join(",") + ";" + game.move_path.join(",")) } /* OBJECTIVES */ @@ -1830,7 +1802,7 @@ states.move_give = { } function end_move_piece() { - log_selected_move_path() + log_move_path() if (game.move_elim) { for (let p of game.move_elim) @@ -2084,7 +2056,10 @@ function end_recruit() { if (game.recruit) { if (game.recruit.used.length > 0) { log_br() - log("Recruited " + game.recruit.troops + " troops with " + game.recruit.used.map(format_card).join(", ") + ".") + if (game.recruit.troops > 0) + log("Recruited " + game.recruit.troops + " troops with " + game.recruit.used.map(format_card).join(", ") + ".") + else + log("Recruited with " + game.recruit.used.map(format_card).join(", ") + ".") map_for_each(game.recruit.pieces, (p,s) => { log("Re-entered P" + p + " at S" + s + ".") }) @@ -3863,7 +3838,7 @@ states.austria_may_move_laudon_by_one_city_immediately = { space(s) { push_undo() - log_small_move_to(s) + log_move_to(s) move_general_immediately(s) game.state = "laudon_done" @@ -4022,7 +3997,7 @@ states.move_to_any_empty_adjacent_city = { gen_action_space(next) }, space(s) { - log_small_move_to(s) + log_move_to(s) for (let p of game.selected) game.pos[p] = s game.state = "prussians_who_are_attacked_by_daun_may_move" -- cgit v1.2.3