From 4d7ea66092beb7555c842e5fa9420ce3ae9f4c3a Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 14 Dec 2022 18:02:50 +0100 Subject: Select and move legate when marching/sailing. --- play.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'play.js') diff --git a/play.js b/play.js index fccc25c..6a52ae1 100644 --- a/play.js +++ b/play.js @@ -19,6 +19,7 @@ const MAP_DPI = 75 const NOWHERE = -1 const CALENDAR = 100 +const LEGATE = 100 const round = Math.round const floor = Math.floor @@ -178,6 +179,14 @@ function is_card_action(c) { return !!(view.actions && view.actions.card && set_has(view.actions.card, c)) } +function is_legate_action() { + return !!(view.actions && view.actions.legate) +} + +function is_legate_selected() { + return view.who === LEGATE || !!(view.group && set_has(view.group, LEGATE)) +} + const force_type_count = 7 const force_type_name = [ "knights", "sergeants", "light_horse", "asiatic_horse", "men_at_arms", "militia", "serfs" ] const force_type_tip = [ "knights", "sergeants", "light horse", "asiatic horse", "men-at-arms", "militia", "serfs" ] @@ -591,6 +600,11 @@ function on_focus_vassal_service_marker(evt) { document.getElementById("status").textContent = `(${id}) ${lord.name} / ${vassal.name}` } +function on_click_legate(evt) { + if (evt.button === 0) + send_action('legate') +} + function on_blur(evt) { document.getElementById("status").textContent = "" } @@ -951,6 +965,8 @@ function update_legate() { ui.legate.classList.add("hide") } else { ui.legate.classList.remove("hide") + ui.legate.classList.toggle("action", is_legate_action()) + ui.legate.classList.toggle("selected", is_legate_selected()) if (view.call_to_arms.legate === 100) { ui.legate.style.top = "1580px" ui.legate.style.left = "170px" @@ -1421,6 +1437,8 @@ function build_map() { document.getElementById("pieces").appendChild(e) }) + document.getElementById("legate").addEventListener("mousedown", on_click_legate) + for (let name in original_boxes) { let x = round(original_boxes[name][0] * MAP_DPI / 300) let y = round(original_boxes[name][1] * MAP_DPI / 300) -- cgit v1.2.3