diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-06-06 14:15:11 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-06-06 15:30:59 +0200 |
commit | e746813794c5f2408c4b1269ff1c85a817a8219b (patch) | |
tree | 84866d07da36499f8b895751dd3f1cf0b5671c0f /play.js | |
parent | b9f53c30064066e39e18b35697a1e4be21472c15 (diff) | |
download | maria-e746813794c5f2408c4b1269ff1c85a817a8219b.tar.gz |
y
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 136 |
1 files changed, 106 insertions, 30 deletions
@@ -140,14 +140,18 @@ function to_value(c) { const svgNS = "http://www.w3.org/2000/svg" -function make_road(c1, c2, type) { +var _show_path_pcs = [] +var _show_path = [] + +function make_road(a, b, type) { let e = document.createElementNS(svgNS, "line") e.setAttribute("class", type) - let x1 = data.cities.x[c1] - let y1 = data.cities.y[c1] - let x2 = data.cities.x[c2] - let y2 = data.cities.y[c2] + let x1 = data.cities.x[a] + let y1 = data.cities.y[a] + let x2 = data.cities.x[b] + let y2 = data.cities.y[b] + /* let v = Math.hypot(x2 - x1, y2 - y1) let dx = (x2 - x1) / v let dy = (y2 - y1) / v @@ -156,12 +160,63 @@ function make_road(c1, c2, type) { y1 += r * dy x2 -= r * dx y2 -= r * dy + */ e.setAttribute("x1", x1) e.setAttribute("y1", y1) e.setAttribute("x2", x2) e.setAttribute("y2", y2) document.getElementById("roads").appendChild(e) + + if (!ui.roads[a]) ui.roads[a] = {} + if (!ui.roads[b]) ui.roads[b] = {} + ui.roads[a][b] = e + ui.roads[b][a] = e +} + +function on_focus_path_tip(ps, ss) { + _show_path_pcs = ps + for (let p of _show_path_pcs) + on_focus_piece_tip(p) + hide_move_path() + _show_path = ss + show_move_path(view.pos[ps[0]] !== ss[ss.length-1]) + ui.status.textContent = ss.map(s => data.cities.name[s]).join(" - ") +} + +function on_blur_path_tip() { + for (let p of _show_path_pcs) + on_blur_piece_tip(p) + hide_move_path() + ui.status.textContent = "" +} + +function show_move_path(tip_end) { + if (_show_path && _show_path.length > 0) { + for (let i = 0; i < _show_path.length; ++i) + ui.cities[_show_path[i]].classList.add("move") + if (tip_end) + ui.cities[_show_path[_show_path.length-1]].classList.add("tip") + for (let i = 1; i < _show_path.length; ++i) { + let x = _show_path[i-1] + let y = _show_path[i] + ui.roads[x][y].setAttribute("visibility", "visible") + } + } +} + +function hide_move_path() { + if (_show_path && _show_path.length > 0) { + for (let i = 0; i < _show_path.length; ++i) + ui.cities[_show_path[i]].classList.remove("move") + ui.cities[_show_path[_show_path.length-1]].classList.remove("tip") + for (let i = 1; i < _show_path.length; ++i) { + let x = _show_path[i-1] + let y = _show_path[i] + ui.roads[x][y].setAttribute("visibility", "hidden") + } + _show_path = null + } } /* PANEL ORDER */ @@ -271,6 +326,7 @@ const ui = { document.getElementById("hand_austria"), ], cities: [], + roads: [], action_register: [], } @@ -343,7 +399,7 @@ function make_tc_deck_back(n) { return list } -function make_tc_deck_discard(n) { +function make_tc_deck_pile(n) { let list = [] for (let i = 0; i < 10; ++i) { let e = document.createElement("div") @@ -353,6 +409,16 @@ function make_tc_deck_discard(n) { return list } +function make_tc_deck_hand(n) { + let list = [] + for (let i = 0; i < 100; ++i) { + let e = document.createElement("div") + e.className = "card tc hand reverse " + n + list.push(e) + } + return list +} + function make_political_card(fc) { let e = document.createElement("div") if (fc === 0) @@ -446,11 +512,20 @@ function on_init() { make_tc_deck_back("deck_4"), ] + ui.tc_hand = [ + make_tc_deck_pile("deck_1"), + make_tc_deck_pile("deck_1"), + make_tc_deck_pile("deck_1"), + make_tc_deck_pile("deck_1"), + make_tc_deck_pile("deck_1"), + make_tc_deck_pile("deck_1"), + ] + ui.tc_discard = [ - make_tc_deck_discard("deck_1"), - make_tc_deck_discard("deck_2"), - make_tc_deck_discard("deck_3"), - make_tc_deck_discard("deck_4"), + make_tc_deck_pile("deck_1"), + make_tc_deck_pile("deck_2"), + make_tc_deck_pile("deck_3"), + make_tc_deck_pile("deck_4"), ] ui.combat = document.createElement("div") @@ -524,20 +599,17 @@ function on_init() { ui.spaces_element.appendChild(e) } - sort_power_panel(false) - - // TOD: debug road network - if (0) { - for (let a = 0; a <= last_city; ++a) { - for (let b of data.cities.main_roads[a]) - if (a < b) - make_road(a, b, "main_road") - for (let b of data.cities.roads[a]) - if (a < b) - make_road(a, b, "road") - } + for (let a = 0; a <= last_city; ++a) { + for (let b of data.cities.main_roads[a]) + if (a < b) + make_road(a, b, "road") + for (let b of data.cities.roads[a]) + if (a < b) + make_road(a, b, "road") } + sort_power_panel(false) + update_favicon() } @@ -786,7 +858,7 @@ function colorize(text) { } function on_prompt(text) { - return colorize(view.prompt) + return colorize(text) } function on_update() { @@ -822,13 +894,17 @@ function on_update() { */ ui.hand[pow].replaceChildren() - view.hand[pow].sort(cmp_tc) - for (let c of view.hand[pow]) { - console.log("C", c, c&15) - if ((c & 15) === 0) - ui.hand[pow].appendChild(ui.tc_back[c>>7][back[c>>7]++]) - else - ui.hand[pow].appendChild(ui.tc[c]) + if (typeof view.hand[pow] === "number") { + for (let i = 0; i < view.hand[pow]; ++i) + ui.hand[pow].appendChild(ui.tc_hand[pow][i]) + } else { + view.hand[pow].sort(cmp_tc) + for (let c of view.hand[pow]) { + if ((c & 15) === 0) + ui.hand[pow].appendChild(ui.tc_back[c>>7][back[c>>7]++]) + else + ui.hand[pow].appendChild(ui.tc[c]) + } } } |