1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
"use strict"
const space_count = data.space_names.length
let layout = []
let space_layout_cube = []
let space_layout_disc = []
let ui = {
cards: [ null ],
cubes: [],
discs: [],
spaces: [],
red_momentum: document.getElementById("red_momentum"),
blue_momentum: document.getElementById("blue_momentum"),
political_vp: document.getElementById("political_vp"),
military_vp: document.getElementById("military_vp"),
round_marker: document.getElementById("round_marker"),
}
// :r !python3 tools/genboxes.py
const boxes = {
"Royalists": [318,1711,506,505],
"Republicans": [1960,1712,504,504],
"Catholic Church": [318,3146,505,505],
"Social Movements": [1960,3146,506,505],
"Fort d'Issy": [3374,3172,506,506],
"Butte-Aux-Cailles": [4153,2642,505,505],
"Père Lachaise": [4824,2364,506,505],
"Château de Vincennes": [5369,2599,504,507],
"Press": [1176,2908,447,448],
"National Assembly": [1168,1984,447,447],
"Butte Montmartre": [4208,1842,447,444],
"Mont-Valérien": [2868,2028,447,448],
"Versailles HQ": [2646,3398,404,380],
"Prussian Occupied Territory": [5190,1413,718,346],
"Red Crisis Track Start": [3928,244,361,448],
"Red Crisis Track Escalation": [4289,244,334,448],
"Red Crisis Track Tension": [4623,244,332,448],
"Red Crisis Track Final Crisis": [4955,244,332,448],
"Blue Crisis Track Start": [1728,244,354,446],
"Blue Crisis Track Escalation": [1394,244,334,446],
"Blue Crisis Track Tension": [1061,244,333,446],
"Blue Crisis Track Final Crisis": [728,244,333,446],
"Blue Objective Card": [479,3983,1088,218],
"Red Objective Card": [4454,3984,1088,218],
"Red Cube Pool": [4498,790,791,219],
"Blue Cube Pool": [720,790,791,219],
"Red Bonus Cubes 1": [4289,89,334,155],
"Red Bonus Cubes 2": [4623,89,332,155],
"Red Bonus Cubes 3": [4955,89,332,155],
"Blue Bonus Cubes 1": [1394,89,334,155],
"Blue Bonus Cubes 2": [1061,89,333,155],
"Blue Bonus Cubes 3": [728,89,333,155],
}
function is_card_action(action, card) {
if (view.actions && view.actions[action] && view.actions[action].includes(card))
return true
return false
}
function is_cube_action(i) {
if (view.actions && view.actions.cube && view.actions.cube.includes(i))
return true
return false
}
function is_disc_action(i) {
if (view.actions && view.actions.disc && view.actions.disc.includes(i))
return true
return false
}
function is_space_action(i) {
if (view.actions && view.actions.space && view.actions.space.includes(i))
return true
return false
}
function on_blur(evt) {
document.getElementById("status").textContent = ""
}
function on_focus_space(evt) {
document.getElementById("status").textContent = evt.target.my_name
}
function on_click_space(evt) {
if (evt.button === 0) {
if (send_action('space', evt.target.my_space))
evt.stopPropagation()
}
}
function on_click_cube(evt) {
if (evt.button === 0) {
if (send_action('cube', evt.target.my_cube))
evt.stopPropagation()
}
}
function on_click_disc(evt) {
if (evt.button === 0) {
if (send_action('disc', evt.target.my_disc))
evt.stopPropagation()
}
}
function build_user_interface() {
let elt
for (let c = 1; c <= 41 + 12; ++c) {
elt = ui.cards[c] = document.createElement("div")
elt.className = `card card_${c}`
elt.my_card = c
elt.addEventListener("click", on_click_card)
}
for (let i = 0; i < 36; ++i) {
elt = ui.cubes[i] = document.createElement("div")
if (i < 18)
elt.className = "piece cube red"
else
elt.className = "piece cube blue"
elt.my_cube = i
elt.addEventListener("mousedown", on_click_cube)
document.getElementById("pieces").appendChild(elt)
}
for (let i = 0; i < 4; ++i) {
elt = ui.discs[i] = document.createElement("div")
if (i < 2)
elt.className = "piece disc red"
else
elt.className = "piece disc blue"
elt.my_disc = i
elt.addEventListener("mousedown", on_click_disc)
}
for (let i = 0; i < space_count; ++i) {
let name = data.space_names[i]
let r = boxes[name]
elt = ui.spaces[i] = document.createElement("div")
elt.className = "space"
elt.my_space = i
elt.my_name = name
elt.addEventListener("mousedown", on_click_space)
elt.addEventListener("mouseenter", on_focus_space)
elt.addEventListener("mouseleave", on_blur)
let bw = 8
let x = Math.round(r[0] / 4)
let y = Math.round(r[1] / 4)
let w = Math.round(r[2] / 4)
let h = Math.round(r[3] / 4)
elt.style.top = y + "px"
elt.style.left = x + "px"
elt.style.width = (w - bw * 2) + "px"
elt.style.height = (h - bw * 2) + "px"
space_layout_cube[i] = { x: x + Math.round(w/2), y: y + Math.round(h*1/2) }
space_layout_disc[i] = { x: x + w, y: y + h }
document.getElementById("spaces").appendChild(elt)
}
}
function layout_cubes(list, xorig, yorig) {
const dx = 20
const dy = 11
if (list.length > 0) {
let ncol = Math.round(Math.sqrt(list.length))
let nrow = Math.ceil(list.length / ncol)
function place_cube(row, col, e, z) {
let x = xorig - (row * dx - col * dx) - 18 + (nrow-ncol) * 6
let y = yorig - (row * dy + col * dy) - 28 + (nrow-1) * 8
e.style.left = x + "px"
e.style.top = y + "px"
e.style.zIndex = z
}
let z = 50
let i = 0
for (let row = 0; row < nrow; ++row)
for (let col = 0; col < ncol && i < list.length; ++col)
place_cube(row, col, list[list.length-(++i)], z--)
}
}
function layout_disc(s, disc) {
if (s > 0)
disc.classList.remove("hide")
else
disc.classList.add("hide")
disc.style.left = (space_layout_disc[s].x - 50 - 12) + "px"
disc.style.top = (space_layout_disc[s].y - 20 - 8) + "px"
}
function on_focus_card_tip(card_number) {
document.getElementById("tooltip").className = "card card_" + card_number
}
function on_blur_card_tip() {
document.getElementById("tooltip").classList = "card hide"
}
function sub_card_name(match, p1, offset, string) {
let c = p1 | 0
let n = data.cards[c].name
return `<span class="tip" onmouseenter="on_focus_card_tip(${c})" onmouseleave="on_blur_card_tip()">${n}</span>`
}
function on_log(text) {
let p = document.createElement("div")
if (text.match(/^>/)) {
text = text.substring(1)
p.className = 'i'
}
text = text.replace(/&/g, "&")
text = text.replace(/</g, "<")
text = text.replace(/>/g, ">")
text = text.replace(/#(\d+)/g, sub_card_name)
if (text.match(/^\.h1/)) {
text = text.substring(4)
p.className = 'h1'
}
if (text.match(/^\.h2/)) {
text = text.substring(4)
if (text === 'Commune')
p.className = 'h2 commune'
else if (text === 'Versailles')
p.className = 'h2 versailles'
else
p.className = 'h2'
}
p.innerHTML = text
return p
}
function on_update() {
if (view.active_card)
document.getElementById("active_card").className = `card card_${view.active_card}`
else
document.getElementById("active_card").className = `card card_strategy_back`
if (view.initiative === "Commune")
document.getElementById("commune_info").textContent = "\u2756"
else
document.getElementById("commune_info").textContent = ""
if (view.initiative === "Versailles")
document.getElementById("versailles_info").textContent = "\u2756"
else
document.getElementById("versailles_info").textContent = ""
ui.round_marker.className = `piece pawn round${view.round}`
ui.red_momentum.className = `piece cylinder red m${view.red_momentum}`
ui.blue_momentum.className = `piece cylinder blue m${view.blue_momentum}`
ui.military_vp.className = `piece cylinder purple vp${5+view.military_vp}`
ui.political_vp.className = `piece cylinder orange vp${5+view.political_vp}`
document.getElementById("hand").replaceChildren()
if (view.objective)
document.getElementById("hand").appendChild(ui.cards[view.objective])
if (view.hand)
for (let c of view.hand)
document.getElementById("hand").appendChild(ui.cards[c])
for (let i = 0; i < space_count; ++i)
layout[i] = []
for (let i = 0; i < 36; ++i) {
layout[view.cubes[i]].push(ui.cubes[i])
ui.cubes[i].classList.toggle("action", is_cube_action(i))
}
for (let i = 0; i < space_count; ++i) {
layout_cubes(layout[i], space_layout_cube[i].x, space_layout_cube[i].y)
ui.spaces[i].classList.toggle("action", is_space_action(i))
}
for (let i = 0; i < 4; ++i) {
layout_disc(view.discs[i], ui.discs[i])
ui.discs[i].classList.toggle("action", is_cube_action(i))
}
for (let i = 1; i < ui.cards.length; ++i) {
ui.cards[i].classList.toggle("action", is_card_action('card', i))
}
action_button("commune", "Commune")
action_button("versailles", "Versailles")
action_button("undo", "Undo")
}
/* CARD ACTION MENU */
let current_popup_card = 0
function show_popup_menu(evt, list) {
document.querySelectorAll("#popup div").forEach(e => e.classList.remove('enabled'))
for (let item of list) {
let e = document.getElementById("menu_" + item)
e.classList.add('enabled')
}
let popup = document.getElementById("popup")
popup.style.display = 'block'
popup.style.left = (evt.clientX-50) + "px"
popup.style.top = (evt.clientY-12) + "px"
ui.cards[current_popup_card].classList.add("selected")
}
function hide_popup_menu() {
let popup = document.getElementById("popup")
popup.style.display = 'none'
if (current_popup_card) {
ui.cards[current_popup_card].classList.remove("selected")
current_popup_card = 0
}
}
function on_card_event() {
if (send_action('card_event', current_popup_card))
hide_popup_menu()
}
function on_card_ops() {
if (send_action('card_ops', current_popup_card))
hide_popup_menu()
}
function on_card_use_discarded() {
if (send_action('card_use_discarded', current_popup_card))
hide_popup_menu()
}
function on_card_advance_momentum() {
if (send_action('card_advance_momentum', current_popup_card))
hide_popup_menu()
}
function on_click_card(evt) {
if (evt.button === 0) {
if (view.actions) {
let card = evt.target.my_card
if (is_card_action('card', card)) {
send_action('card', card)
} else {
let menu = []
if (is_card_action('card_event', card))
menu.push('card_event')
if (is_card_action('card_ops', card))
menu.push('card_ops')
if (is_card_action('card_use_discarded', card))
menu.push('card_use_discarded')
if (is_card_action('card_advance_momentum', card))
menu.push('card_advance_momentum')
if (menu.length > 0) {
current_popup_card = card
show_popup_menu(evt, menu)
}
}
}
}
}
build_user_interface()
scroll_with_middle_mouse("main")
|