-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual.py
553 lines (445 loc) · 19.8 KB
/
manual.py
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
#!/bin/env python
import json
def translate_class(name):
if name == "creature":
return "Criatura"
if name == "spell":
return "Hechizo"
if name == "amulet":
return "Amuleto"
if name == "power":
return "Poder"
return name.capitalize()
def magic_to_color(magic):
if magic == "blue":
return "is-link"
if magic == "black":
return "is-dark"
if magic == "white":
return "is-white"
if magic == "red":
return "is-danger"
if magic == "green":
return "is-success"
def translate_kind(items):
out = ""
for item in items:
key = item[0]
value = item[1]
if key == "size":
out += f"""
<span class="tag is-warning">{key}: {value}</span>
"""
elif key == "magic":
out += f"""
<span class="tag {magic_to_color(value)}">{key}: {value}</span>
"""
else:
out += f"""
<span class="tag is-info">{key}: {value}</span>
"""
return out
def translate_ability(items, lang = "es"):
out = "<ul>"
for item in items:
for key in item.keys():
if key == "pay" or key == "limit":
continue
if key == "draw_cards":
out += f"""
<li>
<span class="spanish">Obtener <i>{item[key]}</i> carta(s).</span>
</li>
<li>
<span class="english hidden">Draw <i>{item[key]}</i> card(s).</span>
</li>
"""
if lang == "en":
if key == "inc_self_defense":
out += f"<li>Increment self defense by <i>{item[key]}</i> points.</li>"
if key == "inc_self_attack":
out += f"<li>Increment self attack by <i>{item[key]}</i> points.</li>"
if key == "block_spin_opponent_power":
out += f"<li>Block activation of <i>{item[key]}</i> powers.</li>"
if key == "block_spin_opponent_creature":
out += f"<li>Block activation of <i>{item[key]}</i> creatures.</li>"
if key == "inc_holder_defense":
out += f"<li>Gives holder <i>{item[key]}</i> defense points.</li>"
if key == "dec_opponent_life":
out += f"<li>Damages opponent's life by <i>{item[key]}</i> points.</li>"
if key == "inc_owner_life":
out += f"<li>Restores player life by <i>{item[key]}</i> points.</li>"
if key == "alter_owner_field":
element = item[key]
command = element["do"]
if command == "inc_defense_in_all_creatures":
quantity = element["quantity"]
out += f"<li>Increase defense in all player field creatures by <i>{quantity}</i> points.</li>"
if command == "inc_attack_in_all_creatures":
quantity = element["quantity"]
out += f"<li>Increase attack in all player field creatures by <i>{quantity}</i> points.</li>"
if command == "set_shield_to_all_creatures":
quantity = element.get("quantity") or element.get("quantiy") or 1
defense = element.get("inc_defense")
if defense:
out += f"<li>All player field creatures are <i>defenders</i> for the next <i>{quantity}</i> turns with {defense} additional defense points.</li>"
else:
out += f"<li>All player field creatures are <i>defenders</i> for the next <i>{quantity}</i> turns.</li>"
if key == "alter_opponent_field":
element = item[key]
command = element["do"]
if command == "delete_mystic_status_from_all_creatures":
out += f"<li>Erase <i>Mystic</i> status from opponent's field creatures.</li>"
if command == "destroy":
quantity = element.get("quantity") or 1
type = element.get("type").capitalize()
out += f"<li>Destroys <i>{quantity}</i> <i>{type}</i> cards from opponent's field.</li>"
if lang == "es":
if key == "inc_self_defense":
out += f"<li>Aumenta la propia defensa por <i>{item[key]}</i> puntos.</li>"
if key == "inc_self_attack":
out += f"<li>Aumenta el propio ataque por <i>{item[key]}</i> puntos.</li>"
if key == "block_spin_opponent_power":
out += f"<li>Bloquea activar <i>{item[key]}</i> poderes.</li>"
if key == "block_spin_opponent_creature":
out += f"<li>Bloquea activar <i>{item[key]}</i> criaturas.</li>"
if key == "inc_holder_defense":
out += f"<li>Da al portador <i>{item[key]}</i> puntos de defensa.</li>"
if key == "dec_opponent_life":
out += f"<li>Daña la vida del adversario en <i>{item[key]}</i> puntos.</li>"
if key == "inc_owner_life":
out += f"<li>Restaura la vida del aprendiz en <i>{item[key]}</i> puntos.</li>"
if key == "alter_owner_field":
element = item[key]
command = element["do"]
if command == "inc_defense_in_all_creatures":
quantity = element["quantity"]
out += f"<li>Aumenta la defensa de todas las criaturas del campo del aprendiz en <i>{quantity}</i> puntos.</li>"
if command == "inc_attack_in_all_creatures":
quantity = element["quantity"]
out += f"<li>Aumenta el ataque de todas las criaturas del campo del aprendiz en <i>{quantity}</i> puntos.</li>"
if command == "set_shield_to_all_creatures":
quantity = element.get("quantity") or 1
defense = element.get("inc_defense")
if defense:
out += f"<li>Las criaturas del campo del jugador serán <i>defensoras</i> por los siguientes <i>{quantity}</i> turnos con {defense} puntos de defensa adicional.</li>"
else:
out += f"<li>Las criaturas del campo del jugador serán <i>defensoras</i> por los siguientes <i>{quantity}</i> turnos.</li>"
if key == "alter_opponent_field":
element = item[key]
command = element.get("do")
if command == "delete_mystic_status_from_all_creatures":
out += f"<li>Elimina el estado <i>Místico</i> de las criaturas del oponente en el campo.</li>"
if command == "destroy":
quantity = element.get("quantity") or 1
type = element.get("type")
if type == "amulet":
type = "Amuleto"
if type == "power":
type = "Poder"
if type == "creature":
type = "Criatura"
if type == "spell":
type = "Hechizo"
out += f"<li>Destruye <i>{quantity}</i> cartas del tipo <i>{type}</i> del oponente en el campo.</li>"
out += "</ul>"
return out
def calculate_total_pay(items):
total = 0
for item in items:
total += item["pay"]
return total
def calculate_total_turns(items, lang = "es"):
turns = -1
for item in items:
if item["limit"] > turns:
turns = item["limit"]
if turns < 0:
turns = "Ilimitado"
if lang == "en":
turns = "Unlimited"
return turns
def special_fields(card, lang = "es"):
abilities = card.get("abilities")
out = ""
if abilities and abilities.get("special"):
out += """
<tr>
<td>
<span class="spanish">Especial</span><span class="english hidden">Special</span>
</td>
<td>
"""
special = abilities.get("special")
for item in special:
for key in item.keys():
if key == "can_defend_multiple_times":
out += f"""
<span class="spanish">Puede defender hasta {item[key]} veces.</span>
<span class="english hidden">Can defend up to {item[key]} times.</span>
"""
if key == "can_attack_multiple_times":
out += f"""
<span class="spanish">Puede atacar hasta {item[key]} veces.</span>
<span class="english hidden">Can attack up to {item[key]} times.</span>
"""
out += """
</td>
</tr>
"""
return out
def show_creature_fields(card):
if card["class"] == "creature":
return f"""
<tr>
<td>
<span class="spanish">Ataque</span><span class="english hidden">Attack</span>
</td>
<td>
{card["attack"]}
</td>
</tr>
<tr>
<td>
<span class="spanish">Defensa</span><span class="english hidden">Defense</span>
</td>
<td>
{card["defense"]}
</td>
</tr>
<tr>
<td>
<span class="spanish">Tipo</span><span class="english hidden">Type</span>
</td>
<td>
{card["type"].capitalize()}
</td>
</tr>
<tr>
<td>
<span class="spanish">Subtipo</span><span class="english hidden">Subtype</span>
</td>
<td>
{card["subtype"].capitalize()}
</td>
</tr>
{special_fields(card)}
"""
else:
return ""
def translate_abilities(abilities, lang = "es"):
out = ""
if len(abilities) <= 0 or len(abilities["main"]) <= 0:
if lang == "en":
return "None"
return "Ninguna"
main = abilities["main"]
main_pay = calculate_total_pay(main)
main_turns = calculate_total_turns(main, lang)
if lang == "en":
out += f"""
<h3>Pay: {main_pay}</h3>
<h3>Turns: {main_turns}</h3>
{translate_ability(main, lang)}
"""
if lang == "es":
out += f"""
<h3>Pagar: {main_pay}</h3>
<h3>Turnos: {main_turns}</h3>
{translate_ability(main, lang)}
"""
return out
def show_before_activate_fields(card):
abilities = card.get("abilities").get("on_activate") or []
out = ""
for item in abilities:
out += """
<tr>
<td>
<span class="spanish">Efectos al Activar</span><span class="english hidden">Activation Effects</span>
</td>
"""
for key in item.keys():
if key == "inc_owner_power":
out += f"""
<td>
<span class="spanish">Obtener <i>{item[key]}</i> poder(es).</span>
<span class="english hidden">Obtain <i>{item[key]}</i> power(s).</span>
</td>
"""
if key == "draw_cards":
out += f"""
<td>
<span class="spanish">Obtener <i>{item[key]}</i> carta(s).</span>
<span class="english hidden">Draw <i>{item[key]}</i> card(s).</span>
</td>
"""
out += "</tr>"
return out
def show_before_attack_fields(card):
abilities = card.get("abilities").get("on_before_attack") or []
out = ""
for item in abilities:
out += """
<tr>
<td>
<span class="spanish">Efectos al Atacar</span><span class="english hidden">Attack Effects</span>
</td>
"""
for key in item.keys():
if key == "dec_owner_life":
out += f"""
<td>
<span class="spanish">Reduce <i>{item[key]}</i> punto de vida al aprendiz (aumenta con la defensa).</span>
<span class="english hidden">Decrease <i>{item[key]}</i> player's life points (increase with defense).</span>
</td>
"""
return out
def show_before_cast_fields(card):
abilities = card.get("abilities").get("on_before_cast") or []
out = ""
for item in abilities:
out += """
<tr>
<td>
<span class="spanish">Efectos al Invocar</span><span class="english hidden">Invocation Effects</span>
</td>
"""
for key in item.keys():
if key == "draw_cards":
out += f"""
<td>
<span class="spanish">Obtener <i>{item[key]}</i> carta(s).</span>
<span class="english hidden">Draw <i>{item[key]}</i> card(s).</span>
</td>
"""
if key == "dec_opponent_life":
out += f"""
<td>
<span class="spanish">Disminuye <i>{item[key]}</i> puntos de vida al oponente.</span>
<span class="english hidden">Drains <i>{item[key]}</i> opponent's life points.</span>
</td>
"""
if key == "inc_owner_life":
out += f"""
<td>
<span class="spanish">Aumenta <i>{item[key]}</i> puntos de vida al aprendiz.</span>
<span class="english hidden">Recovers <i>{item[key]}</i> player life points.</span>
</td>
"""
if key == "block_spin_opponent_creature":
out += f"""
<td>
<span class="spanish">Bloquea activar <i>{item[key]}</i> criaturas del oponente por 1 turno.</span>
<span class="english hidden">Blocks the activation of <i>{item[key]}</i> opponent's creatures by 1 turn.</span>
</td>
"""
if key == "owner_min_activated_creatures":
out += f"""
<td>
<span class="spanish">Requiere <i>{item[key]}</i> criaturas que se hayan activado durante la partida.</span>
<span class="english hidden">Requires <i>{item[key]}</i> activated creatures during the match.</span>
</td>
"""
if key == "alter_opponent_field":
element = item[key]
command = element.get("do")
if command == "destroy":
quantity = element.get("quantity") or element.get("quantiy") or 1
type = element.get("type")
out += f"""
<td>
<span class="spanish">Destruye {quantity} {translate_class(type)}(s).</span>
<span class="english hidden">Destroys {quantity} {type.capitalize()}</span>
</td>
"""
out += "</tr>"
return out
# TODO: Check why None appears in spells
def main():
data = open("./cards.json", encoding="utf8").read()
cards = json.loads(data)
template = open("./template.html", encoding="utf8").read()
cards_table = ""
for card in cards:
# Omit disabled cards
settings = card["settings"]
if len(settings) > 0:
disabled_setting = settings[0]
if disabled_setting["disabled"] == True:
continue
cards_table += f"""
<label class="table-header">
#{card["id"]} <span class="spanish">{card["name"]["spanish"]}</span><span class="english hidden">{card["name"]["english"]}</span>
<img src="cards/{card["id"]}.jpg" class="image">
<table>
<tbody>
<tr>
<td>
<span class="spanish">Clase</span><span class="english hidden">Class</span>
</td>
<td>
<span class="spanish">{translate_class(card["class"])}</span><span class="english hidden">{card["class"].capitalize()}</span>
</td>
</tr>
<tr>
<td>
<span class="spanish">Nivel</span><span class="english hidden">Level</span>
</td>
<td>
{card["level"]}
</td>
</tr>
<tr>
<td>
<span class="spanish">Rareza</span><span class="english hidden">Rarity</span>
</td>
<td>
{card["rarity"]["value"].capitalize()} ({0.1 if (100 - card["rarity"]["percent"] <= 0) else 100 - card["rarity"]["percent"]}%)
</td>
</tr>
<tr>
<td>
<span class="spanish">Costo</span><span class="english hidden">Cost</span>
</td>
<td>
{card["casting_cost"]}
</td>
</tr>
{show_creature_fields(card)}
{show_before_cast_fields(card)}
{show_before_activate_fields(card)}
{show_before_attack_fields(card)}
<tr>
<td>
<span class="spanish">Copias por Mazo</span><span class="english hidden">Max Per Deck</span>
</td>
<td>
{card["max_per_deck"]}
</td>
</tr>
<tr>
<td>
<span class="spanish">Especie</span><span class="english hidden">Kind</span>
</td>
<td>
<span class="spanish">{translate_kind(card["kind"])}</span><span class="english hidden">{translate_kind(card["kind"])}</span>
</td>
</tr>
<tr>
<td>
<span class="spanish">Habilidades</span><span class="english hidden">Abilities</span>
</td>
<td>
<span class="spanish">{translate_abilities(card["abilities"])}</span><span class="english hidden">{translate_abilities(card["abilities"], "en")}</span>
</td>
</tr>
</tbody>
</table>
</label>
"""
output = template.replace("{cards}", cards_table)
with open("./manual.html", "w", encoding="utf-8") as manual:
manual.write(output)
if __name__ == "__main__":
main()