summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js95
1 files changed, 50 insertions, 45 deletions
diff --git a/play.js b/play.js
index 9204cef..5e7f081 100644
--- a/play.js
+++ b/play.js
@@ -16,8 +16,10 @@ let ui = {
morale: [ document.getElementById("morale1"), document.getElementById("morale2") ],
pool: [ document.getElementById("pool1"), document.getElementById("pool2") ],
reserve: [ document.getElementById("reserve1"), document.getElementById("reserve2") ],
+ tooltip: document.getElementById("tooltip"),
cards: {},
+ cards_tip: {},
slots: {},
slot_sticks: {},
slot_shift: {},
@@ -163,14 +165,15 @@ function nbsp_target(target) {
.replaceAll("\xa0OR\xa0", " OR ")
}
-function create_formation_card(id) {
+function create_formation_card(id, tip=false) {
let card = data.cards[id]
let e = create_div("card formation " + wing_name[card.wing])
if (card.squeeze)
e.classList.add("squeeze")
- register_action(e, "card", id)
+ if (!tip)
+ register_action(e, "card", id)
if (card.infantry || card.cavalry)
append_div(e, "name with_symbol " + wing_name[card.wing], card.name)
@@ -217,7 +220,8 @@ function create_formation_card(id) {
et = append_div(ee, "action_type reaction", a.type)
else
et = append_div(ee, "action_type", a.type)
- register_action(et, "a" + ix, id, "n" + ix)
+ if (!tip)
+ register_action(et, "a" + ix, id, "n" + ix)
append_div(ee, "action_requirement", a.requirement)
if (a.target)
append_div(ee, "action_target", nbsp_target(a.target))
@@ -264,7 +268,8 @@ function create_formation_card(id) {
ee = append_div(e, "retire", `RETIRE, RESERVE (${reserve})`)
else
ee = append_div(e, "retire", "RETIRE")
- register_action(ee, "retire", id)
+ if (!tip)
+ register_action(ee, "retire", id)
} else if (card.pursuit) {
append_div(e, "reserve", "PURSUIT")
} else if (card.reserve) {
@@ -471,37 +476,27 @@ for (let i = 0; i < 12; ++i) {
}
const ICONS = {
- D0: '<span class="mini black d0"></span>',
- D1: '<span class="mini black d1"></span>',
- D2: '<span class="mini black d2"></span>',
- D3: '<span class="mini black d3"></span>',
- D4: '<span class="mini black d4"></span>',
- D5: '<span class="mini black d5"></span>',
- D6: '<span class="mini black d6"></span>',
- R1: '<span class="mini red d1"></span>',
- R2: '<span class="mini red d2"></span>',
- R3: '<span class="mini red d3"></span>',
- R4: '<span class="mini red d4"></span>',
- R5: '<span class="mini red d5"></span>',
- R6: '<span class="mini red d6"></span>',
- P1: '<span class="mini pink d1"></span>',
- P2: '<span class="mini pink d2"></span>',
- P3: '<span class="mini pink d3"></span>',
- P4: '<span class="mini pink d4"></span>',
- P5: '<span class="mini pink d5"></span>',
- P6: '<span class="mini pink d6"></span>',
- B1: '<span class="mini blue d1"></span>',
- B2: '<span class="mini blue d2"></span>',
- B3: '<span class="mini blue d3"></span>',
- B4: '<span class="mini blue d4"></span>',
- B5: '<span class="mini blue d5"></span>',
- B6: '<span class="mini blue d6"></span>',
- K1: '<span class="mini dkblue d1"></span>',
- K2: '<span class="mini dkblue d2"></span>',
- K3: '<span class="mini dkblue d3"></span>',
- K4: '<span class="mini dkblue d4"></span>',
- K5: '<span class="mini dkblue d5"></span>',
- K6: '<span class="mini dkblue d6"></span>',
+ D0: '<span class="mini d0"></span>',
+ D1: '<span class="mini d1"></span>',
+ D2: '<span class="mini d2"></span>',
+ D3: '<span class="mini d3"></span>',
+ D4: '<span class="mini d4"></span>',
+ D5: '<span class="mini d5"></span>',
+ D6: '<span class="mini d6"></span>',
+}
+
+function on_click_tip(id) {
+ scroll_into_view_if_needed(ui.cards[id])
+}
+
+function on_focus_tip(id) {
+ if (!ui.cards_tip[id])
+ ui.cards_tip[id] = create_formation_card(id, true)
+ ui.tooltip.replaceChildren(ui.cards_tip[id])
+}
+
+function on_blur_tip() {
+ ui.tooltip.replaceChildren()
}
function sub_icon(match) {
@@ -512,7 +507,7 @@ function sub_card(match) {
let c = parseInt(match.substring(1))
let wing = wing_name[data.cards[c].wing]
let name = data.cards[c].name
- return `<span class="n ${wing}">${name}</span>`
+ return `<span onclick="on_click_tip(${c})" onmouseenter="on_focus_tip(${c})" onmouseleave="on_blur_tip()" class="n ${wing}">${name}</span>`
}
function on_log(text) {
@@ -520,10 +515,7 @@ function on_log(text) {
if (text.match(/^\.h1 /)) {
text = text.substring(4)
p.className = "h1"
- let w = null
- for (let s of data.scenarios)
- if (s.name === text)
- w = s.wikipedia
+ let w = data.scenarios[view.scenario].wikipedia
if (w) {
p.innerHTML = `<a href="${w}">${text}</a>`
return p
@@ -534,12 +526,14 @@ function on_log(text) {
p.className = "h2"
}
else if (text.match(/^\.p1/)) {
+ let w = data.cards[data.scenarios[view.scenario].players[0].cards[0]].wing
text = data.scenarios[view.scenario].players[0].name
- p.className = "p1"
+ p.className = "h3 " + side_color[w]
}
else if (text.match(/^\.p2/)) {
+ let w = data.cards[data.scenarios[view.scenario].players[1].cards[0]].wing
text = data.scenarios[view.scenario].players[1].name
- p.className = "p2"
+ p.className = "h3 " + side_color[w]
}
else if (text.match(/^\.rule /)) {
text = text.substring(6)
@@ -557,9 +551,20 @@ function on_log(text) {
text = text.substring(1)
p.className = "i1"
}
- else if (text.match(/^.img /)) {
- p = document.createElement("img")
- p.src = "paintings/" + text.substring(5) + ".jpg"
+ else if (text.match(/^.img/)) {
+ p.className = "img"
+ let img = document.createElement("img")
+ img.src = "paintings/" + data.scenarios[view.scenario].name.toLowerCase().replaceAll(" ", "_") + ".jpg"
+ img.onerror = function (evt) { this.style.display="none" }
+ let w = data.scenarios[view.scenario].wikipedia
+ if (w) {
+ let a = document.createElement("a")
+ a.href = w
+ p.appendChild(a)
+ a.appendChild(img)
+ } else {
+ p.appendChild(img)
+ }
return p
}