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
|
"use strict"
/* global view, player, send_action, action_button, scroll_with_middle_mouse */
const TILE_BLUE = 1
const TILE_RED = 13
const TILE_GOLD = 25
const TILE_WHITE = 37
const TILE_GREEN = 49
const TILE_W = 56
const TILE_SPACE = TILE_W + 12
function calc_tile_spacing(n) {
if (n > 12)
return 744 / (n-1)
return TILE_SPACE
}
const BOARD_X = 0
const BOARD_Y = 0 + (12 + 80 + 12)
const COURT1_X = 12
const COURT1_Y = 12 + (12)
const COURT2_X = 12
const COURT2_Y = 12 + (12 + 80 + 12 + 638 + 12)
const HAND_X = 12
const HAND_Y = 12 + (12 + 80 + 12 + 638 + 12 + 80 + 12)
const TOKEN_DX = 3
const TOKEN_DY = -5
const TILE_DX = 3
const TILE_DY = 3
const LAYOUT_OVAL = [
[156,165,46,46],
[262,165,46,46],
[369,165,46,46],
[475,165,46,46],
[582,165,46,46],
[688,165,46,46],
[66,164,46,46],
// dragon at home
[67,106,46,46],
// off-board
[10,638-50],
[110,638-50],
[60,638-50],
[160,638-50],
]
const LAYOUT_SQUARE = [
[147,224,62,62],
[253,224,62,62],
[360,225,62,62],
[466,225,62,62],
[573,225,62,62],
[679,225,62,62],
]
const LAYOUT_SCORE_0 = [358,332,46,46]
const LAYOUT_SCORE_39 = [748,547,46,46]
const SCORE_X0 = LAYOUT_SCORE_0[0] + TOKEN_DX + BOARD_X
const SCORE_Y0 = LAYOUT_SCORE_0[1] + TOKEN_DY + BOARD_Y
const SCORE_DX = (LAYOUT_SCORE_39[0] - LAYOUT_SCORE_0[0] + 4) / 7
const SCORE_DY = (LAYOUT_SCORE_39[1] - LAYOUT_SCORE_0[1]) / 4
const SCORE_DXDY = -1
let ui = {
board: document.getElementById("map"),
court1: document.getElementById("court1"),
court2: document.getElementById("court2"),
darkness: document.getElementById("darkness"),
red_hand_size: document.getElementById("red_hand_size"),
blue_hand_size: document.getElementById("blue_hand_size"),
red_score: null,
blue_score: null,
oval_spaces: [],
square_spaces: [],
tokens: [],
tiles: [ null ],
}
let action_register = []
function register_action(e, action, id) {
e.my_action = action
e.my_id = id
e.onmousedown = on_click_action
action_register.push(e)
}
function on_click_action(evt) {
if (evt.button === 0)
if (send_action(evt.target.my_action, evt.target.my_id))
evt.stopPropagation()
}
function is_action(action, arg) {
if (arg === undefined)
return !!(view.actions && view.actions[action] === 1)
return !!(view.actions && view.actions[action] && view.actions[action].includes(arg))
}
function create(t, p, ...c) {
let e = document.createElement(t)
Object.assign(e, p)
e.append(c)
if (p.my_action)
register_action(e, p.my_action, p.my_id)
return e
}
function create_token(p) {
let e = create("div", p)
ui.board.appendChild(e)
return e
}
function create_tile(p) {
let e = create("div", p)
return e
}
let on_init_once = false
function on_init() {
if (on_init_once)
return
on_init_once = true
for (let i = 0; i < 8; ++i) {
ui.oval_spaces[i] = create("div", { className: "oval space", my_action: "space", my_id: i })
ui.oval_spaces[i].style.left = (BOARD_X + LAYOUT_OVAL[i][0]) + "px"
ui.oval_spaces[i].style.top = (BOARD_Y + LAYOUT_OVAL[i][1]) + "px"
ui.oval_spaces[i].style.width = LAYOUT_OVAL[i][2] + "px"
ui.oval_spaces[i].style.height = LAYOUT_OVAL[i][3] + "px"
ui.board.append(ui.oval_spaces[i])
}
for (let i = 0; i < 6; ++i) {
ui.square_spaces[i] = create("div", { className: "square space", my_action: "square", my_id: i })
ui.square_spaces[i].style.left = (BOARD_X + LAYOUT_SQUARE[i][0]) + "px"
ui.square_spaces[i].style.top = (BOARD_Y + LAYOUT_SQUARE[i][1]) + "px"
ui.square_spaces[i].style.width = LAYOUT_SQUARE[i][2] + "px"
ui.square_spaces[i].style.height = LAYOUT_SQUARE[i][3] + "px"
ui.board.append(ui.square_spaces[i])
}
ui.red_score = create_token({ className: "token red", my_action: "score", my_id: 1 })
ui.blue_score = create_token({ className: "token blue", my_action: "score", my_id: 2 })
ui.tokens[0] = create_token({ className: "token white", my_action: "token", my_id: 0 })
ui.tokens[1] = create_token({ className: "token red", my_action: "token", my_id: 1 })
ui.tokens[2] = create_token({ className: "token red", my_action: "token", my_id: 2 })
ui.tokens[3] = create_token({ className: "token blue", my_action: "token", my_id: 3 })
ui.tokens[4] = create_token({ className: "token blue", my_action: "token", my_id: 4 })
for (let i = TILE_BLUE; i < TILE_BLUE + 12; ++i)
ui.tiles[i] = create_tile({ className: "tile blue", my_action: "tile", my_id: i })
for (let i = TILE_RED; i < TILE_RED + 12; ++i)
ui.tiles[i] = create_tile({ className: "tile red", my_action: "tile", my_id: i })
for (let i = TILE_GOLD; i < TILE_GOLD + 12; ++i)
ui.tiles[i] = create_tile({ className: "tile gold", my_action: "tile", my_id: i })
for (let i = TILE_WHITE; i < TILE_WHITE + 12; ++i)
ui.tiles[i] = create_tile({ className: "tile white", my_action: "tile", my_id: i })
for (let i = TILE_GREEN; i < TILE_GREEN + 6; ++i)
ui.tiles[i] = create_tile({ className: "tile green", my_action: "tile", my_id: i })
}
function show(elt) {
if (elt.parentElement !== ui.board)
ui.board.appendChild(elt)
}
function hide(elt) {
if (elt.parentElement === ui.board)
elt.remove()
}
function on_update() {
on_init()
ui.red_hand_size.textContent = view.red_hand + " in Hand"
ui.blue_hand_size.textContent = view.blue_hand + " in Hand"
ui.darkness.textContent = view.darkness + " in Darkness"
for (let i = 1; i <= 54; ++i) {
if ((view.hand && view.hand.includes(i)) || view.red_court.includes(i) || view.blue_court.includes(i) || view.squares.includes(i))
show(ui.tiles[i])
else
hide(ui.tiles[i])
}
for (let i = 0; i < 6; ++i) {
let k = view.squares[i]
if (k > 0) {
let x = LAYOUT_SQUARE[i][0] + TILE_DX + BOARD_X
let y = LAYOUT_SQUARE[i][1] + TILE_DY + BOARD_Y
ui.tiles[k].style.left = x + "px"
ui.tiles[k].style.top = y + "px"
}
}
for (let i = 0; i < 5; ++i) {
let s = view.tokens[i]
let x = LAYOUT_OVAL[s][0] + TOKEN_DX + BOARD_X
let y = LAYOUT_OVAL[s][1] + TOKEN_DY + BOARD_Y
ui.tokens[i].style.left = x + "px"
ui.tokens[i].style.top = y + "px"
ui.tokens[i].classList.toggle("selected", i === view.selected_token)
}
let court1, court2
if (player !== "Blue") {
ui.court1.className = "blue court"
ui.court2.className = "red court"
court1 = view.blue_court
court2 = view.red_court
} else {
ui.court1.className = "red court"
ui.court2.className = "blue court"
court1 = view.red_court
court2 = view.blue_court
}
let tile_space = calc_tile_spacing(court1.length)
for (let i = 0; i < court1.length; ++i) {
let k = court1[i]
let x = COURT1_X + tile_space * i
let y = COURT1_Y
ui.tiles[k].style.left = x + "px"
ui.tiles[k].style.top = y + "px"
ui.tiles[k].style.zIndex = i
}
tile_space = calc_tile_spacing(court2.length)
for (let i = 0; i < court2.length; ++i) {
let k = court2[i]
let x = COURT2_X + tile_space * i
let y = COURT2_Y
ui.tiles[k].style.left = x + "px"
ui.tiles[k].style.top = y + "px"
ui.tiles[k].style.zIndex = i
}
if (view.hand) {
tile_space = calc_tile_spacing(view.hand.length)
for (let i = 0; i < view.hand.length; ++i) {
let k = view.hand[i]
let x = HAND_X + tile_space * i
let y = HAND_Y
ui.tiles[k].style.left = x + "px"
ui.tiles[k].style.top = y + "px"
ui.tiles[k].style.zIndex = i
}
}
let rs = view.red_score
let bs = view.blue_score
let rs_x = rs % 8
let bs_x = bs % 8
let rs_y = rs >> 3
let bs_y = bs >> 3
ui.red_score.style.left = (SCORE_X0 + SCORE_DX * rs_x + SCORE_DXDY * rs_y) + "px"
ui.blue_score.style.left = (SCORE_X0 + SCORE_DX * bs_x + SCORE_DXDY * bs_y) + "px"
if (rs === bs) {
ui.red_score.style.top = (SCORE_Y0 + SCORE_DY * rs_y - 21) + "px"
ui.blue_score.style.top = (SCORE_Y0 + SCORE_DY * bs_y + 8) + "px"
} else {
ui.red_score.style.top = (SCORE_Y0 + SCORE_DY * rs_y) + "px"
ui.blue_score.style.top = (SCORE_Y0 + SCORE_DY * bs_y) + "px"
}
for (let e of action_register)
e.classList.toggle("action", is_action(e.my_action, e.my_id))
action_button("darkness", "Darkness")
action_button("done", "Done")
action_button("undo", "Undo")
}
function on_log(text) {
let p = document.createElement("div")
if (text.match(/^\.r /)) {
text = text.substring(3)
p.className = 'h1 r'
}
else if (text.match(/^\.b /)) {
text = text.substring(3)
p.className = 'h1 b'
}
else if (text.match(/^\.x /)) {
text = text.substring(3)
p.className = 'h1 x'
}
if (text.match(/^Dragon$/))
p.classList.add("dragon")
if (text.match(/^Secrecy$/))
p.classList.add("secrecy")
if (text.match(/^Cloth of Gold$/))
p.classList.add("gold")
if (text.match(/^Banquets/))
p.classList.add("blue")
if (text.match(/^Godliness/))
p.classList.add("white")
if (text.match(/^Tournaments$/))
p.classList.add("red")
if (text.match(/^Collections$/))
p.classList.add("purple")
p.textContent = text
return p
}
scroll_with_middle_mouse("main")
|