-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheditor.py
executable file
·1161 lines (908 loc) · 39.6 KB
/
editor.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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import copy
import json
import re
import shutil
import zipfile
from base64 import b64decode, b64encode
from io import StringIO
import Krakatau
import wx
from Krakatau.assembler.disassembly import Disassembler
from Krakatau.classfileformat.classdata import ClassData
from Krakatau.classfileformat.reader import Reader
RELIC_TIERS = ["common", "uncommon", "rare", "boss", "shop"]
NEOW_CHOICES = []
# ok.. so we're going to reach inside the StS jar and decompile some java
# classes to rip out what we want. Why? Well, because we can.
ROOM_CHOICES = []
all_cards = {}
all_relics = {}
all_potions = {}
colors = set()
class Card:
def __init__(self, id, name, color, card_type, rarity, target):
self.id = id
self.name = name
self.color = color
self.type = card_type
self.rarity = rarity
self.target = target
self.upgrades = 0
def __str__(self):
return "Card:{}".format(
json.dumps({
'id': self.id,
'name': self.name,
'color': self.color,
'type': self.type,
'rarity': self.rarity,
'target': self.target
})
)
def __lt__(self, other):
# so we can sort
return self.name < other.name
def __eq__(self, other):
return self.id == other.id
class Relic:
def __init__(self, name, tier):
self.name = name
self.tier = tier.lower()
def __lt__(self, other):
return self.name < self.name
class Potion:
def __init__(self, name):
self.name = name
def initialize():
global NEOW_CHOICES
global ROOM_CHOICES
global all_cards
global all_relics
global colors
global all_potions
with zipfile.ZipFile("../desktop-1.0.jar", 'r') as zf:
# find NEOW_CHOICES in the class file.. because why not.
namelist = zf.namelist()
neow_fn = "com/megacrit/cardcrawl/neow/NeowReward$NeowRewardType.class"
if neow_fn in namelist:
with zf.open(neow_fn, 'r') as neow_file:
raw_class = neow_file.read()
clsdata = ClassData(Reader(raw_class))
out = StringIO()
disassembled = Disassembler(clsdata, out.write, roundtrip=False).disassemble()
out.seek(0)
for line in out:
reg = re.match(r".*getstatic Field \[c4\] ([A-Z0-9_]*) \[u50\].*", line)
if reg:
NEOW_CHOICES.append(reg.groups()[0])
NEOW_CHOICES.append("") # yeah, for real.
else:
print('neow data is not available')
# to populate the 'room' dropdown we can make some assumptions based
# on which files exist in the jar
for pathfn in namelist:
aslist = pathfn.split('/')
if aslist[0] == "com":
if aslist[1] == "megacrit":
# print(aslist)
if aslist[:4] == ["com", "megacrit", "cardcrawl", "rooms"]:
if "$" in aslist[-1] or not aslist[-1]:
continue
aslist[-1] = aslist[-1].split('.')[0] # trim off .class extension
clean = ".".join(aslist)
ROOM_CHOICES.append(clean)
elif aslist[:4] == ["com", "megacrit", "cardcrawl", "cards"]:
if len(aslist) == 6:
color = aslist[4]
if color in ['deprecated', 'status', 'tempCards', 'optionCards']:
continue
colors.add(color)
card_name = aslist[5].split('.')[0]
if card_name:
with zf.open(pathfn) as card_file:
raw_card = card_file.read()
clsdata = ClassData(Reader(raw_card))
out = StringIO()
disassembled = Disassembler(clsdata, out.write, roundtrip=False).disassemble()
out.seek(0)
cname_re = re.compile(r".*ldc '([-A-Za-z0-9_ ]*).*'")
ctype_re = re.compile(r".*AbstractCard\$CardType ([A-Z]*) .*")
crarity_re = re.compile(r".*AbstractCard\$CardRarity ([A-Z]*) .*")
ctarget_re = re.compile(r".*AbstractCard\$CardTarget ([A-Z]*) .*")
# if card_name == "Strike_Green":
# print(out.read())
# out.seek(0)
cname = None
ctype = None
crarity = None
ctarget = None
for line in out:
found = False
if cname is None:
cname_match = cname_re.match(line)
if cname_match:
cname = cname_match[1]
found = True
if not found and ctype is None:
ctype_match = ctype_re.match(line)
if ctype_match:
ctype = ctype_match[1]
found = True
if not found and crarity is None:
ctype_match = crarity_re.match(line)
if ctype_match:
crarity = ctype_match[1]
found = True
if not found and ctarget is None:
ctarget_match = ctarget_re.match(line)
if ctarget_match:
ctarget = ctarget_match[1]
found = True
# if not found:
# print(line)
all_cards[cname] = Card(card_name, cname, color, ctype, crarity, ctarget)
print(f"Found {all_cards[cname]}")
elif aslist[:4] == ["com", "megacrit", "cardcrawl", "relics"]:
if aslist[4] in ['deprecated', 'AbstractRelic.class']:
continue
# print(f'Relic found: {aslist[4]}')
if "$" in aslist[-1] or not aslist[-1]:
continue
tier_re = re.compile(r".*RelicTier ()([A-Z]*) .*")
name_re = re.compile(r".*ID Ljava/lang/String; = ([\"'])(.*)([\"']) \n")
with zf.open(pathfn) as card_file:
raw_card = card_file.read()
clsdata = ClassData(Reader(raw_card))
out = StringIO()
disassembled = Disassembler(clsdata, out.write, roundtrip=False).disassemble()
out.seek(0)
myvars = {}
for line in out:
# if "RelicTier" in line:
# print(line)
found = False
for regexp, var in (
(tier_re, 'tier'),
(name_re, 'name')):
if var not in myvars:
rematch = regexp.match(line)
if rematch:
# print(f"{regexp} ?= {line}")
myvars[var] = rematch[2]
found = True
if "name" in myvars and "tier" in myvars:
r = Relic(myvars["name"], myvars["tier"])
# print(r)
all_relics[r.name] = r
else:
if "name" not in myvars:
print(f'No matches for {name_re}')
if "tier" not in myvars:
print(f'No matches for {tier_re}')
elif aslist[:4] == ["com", "megacrit", "cardcrawl", "potions"]:
if "$" in aslist[4] or aslist[4] in ['AbstractPotion.class']:
continue
name_re = re.compile(r".*ldc '([A-Za-z ]*)'.*")
with zf.open(pathfn) as potion_file:
raw_potion = potion_file.read()
try:
clsdata = ClassData(Reader(raw_potion))
except Krakatau.classfileformat.reader.TruncatedStreamError:
print(f'Invalid class file: {pathfn}')
continue
out = StringIO()
disassembled = Disassembler(clsdata, out.write, roundtrip=False).disassemble()
out.seek(0)
myvars = {}
for line in out:
found = False
for regexp, var in (
(name_re, 'name'),):
if var not in myvars:
rematch = regexp.match(line)
if rematch:
# print(f"{regexp} ?= {line}")
myvars[var] = rematch[1]
found = True
if "name" in myvars:
p = Potion(myvars["name"])
all_potions[p.name] = p
else:
if "name" not in myvars:
print(f'No matches for {name_re}')
save_key = "key"
def as_spinbox(value):
# convert the values STS uses to indicate an integer to the values
# wx.SpinBox expects
return str(value)
def as_checkbox(value):
# convert the values STS uses to indicate True/False to the values
# wx.CheckBox expects to indicate checked/unchecked.
return 1 if value else 0
def as_textctrl(value):
return str(value)
def as_choice(value):
return value
class SlaySave:
def decrypt(self, in_bytes):
decrypt_index = -1
out = []
for character in in_bytes:
decrypt_index += 1
out.append(chr(character ^ ord(save_key[decrypt_index % len(save_key)])))
print(f"{decrypt_index} bytes decrypted")
return "".join(out)
def encrypt(self, savejsonstr):
strblob = ""
encrypt_index = -1
out = []
for char in savejsonstr:
encrypt_index += 1
out.append(chr(ord(char) ^ ord(save_key[encrypt_index % len(save_key)])))
print(f"{encrypt_index} bytes encrypted")
return "".join(out)
def as_str(self, saveobj):
return json.dumps(saveobj, indent=2, sort_keys=True)
def load_file(self, filename):
with open(filename, 'rb') as h:
raw = h.read()
baked = self.decrypt(b64decode(raw))
print(baked)
decoded = json.loads(baked)
# print(json.dumps(decoded, indent=4))
return decoded
def save_file(self, filename, saveobj):
encoded = b64encode(self.encrypt(self.as_str(saveobj)).encode('utf-8'))
with open(filename, 'wb') as h:
h.write(encoded)
print(f"Saved as {filename}")
with open(filename + ".backUp", 'wb') as h:
h.write(encoded)
print(f"Saved as {filename}.backUp")
return
def assemble_saveobj(self, decoded, settings_dict, deck, relics, potions):
"""Return a json string of the data for this save."""
saveobj = decoded.copy()
for setting_key in saveobj:
value = saveobj[setting_key]
for widget_dict in [settings_dict, ]:
if setting_key in widget_dict:
widget = widget_dict[setting_key]
if isinstance(widget, wx.SpinCtrl):
value = widget.GetValue()
elif isinstance(widget, wx.Choice):
index = widget.GetSelection()
value = widget.GetString(index)
elif isinstance(widget, wx.CheckBox):
value = widget.GetValue()
elif widget.IsModified():
value = []
for index in range(widget.GetNumberOfLines()):
value.append(widget.GetLineText(index))
value = "\n".join(value)
elif setting_key == "cards":
value = []
for card in deck:
value.append({
"upgrades": card.upgrades,
"misc": 0,
"id": card.name
})
elif setting_key == "relics":
value = []
for relic in relics:
value.append(relic.name)
elif setting_key == "potions":
value = []
for potion in potions:
value.append(potion.name)
saveobj[setting_key] = value
return saveobj
class SettingsPanel(wx.ScrolledWindow):
def __init__(self, parent, id, *args, **kwargs):
wx.ScrolledWindow.__init__(self, parent, id, *args, **kwargs)
self.settings_dict = {}
self.labels_dict = {}
self.SetScrollRate(5, 5)
self.sizer = wx.FlexGridSizer(0, 2, 1, 3)
self.SetSizer(self.sizer)
def load_settings(self, data):
clean = False
for key in list(self.settings_dict.keys()):
self.settings_dict.pop(key).Destroy()
self.labels_dict.pop(key).Destroy()
clean = True
if clean:
self.sizer.Layout()
for key, widget, transform, kw in [
["act_num", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["ai_seed_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["ascension_level", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["blue", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["boss", wx.TextCtrl, as_textctrl, {}],
["card_seed_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["champions", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["chose_neow_reward", wx.CheckBox, as_checkbox, {}],
["combo", wx.CheckBox, as_checkbox, {}],
["current_health", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["current_room", wx.Choice, as_choice, {'choices': ROOM_CHOICES}],
["elites1_killed", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["elites2_killed", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["elites3_killed", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["event_seed_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100}],
["floor_num", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100}],
["gold", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100000}],
["gold_gained", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100000}],
["green", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["hand_size", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100}],
["has_emerald_key", wx.CheckBox, as_checkbox, {}],
["has_ruby_key", wx.CheckBox, as_checkbox, {}],
["has_sapphire_key", wx.CheckBox, as_checkbox, {}],
["is_ascension_mode", wx.CheckBox, as_checkbox, {}],
["is_daily", wx.CheckBox, as_checkbox, {}],
["is_endless_mode", wx.CheckBox, as_checkbox, {}],
["is_final_act_on", wx.CheckBox, as_checkbox, {}],
["is_trial", wx.CheckBox, as_checkbox, {}],
["level_name", wx.TextCtrl, as_textctrl, {}],
["max_health", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["max_orbs", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100}],
["merchant_seed_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100}],
["monster_seed_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["monsters_killed", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["mugged", wx.CheckBox, as_checkbox, {}],
["mystery_machine", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["name", wx.TextCtrl, as_textctrl, {}],
["neow_bonus", wx.Choice, as_choice, {'choices': NEOW_CHOICES}],
["overkill", wx.CheckBox, as_checkbox, {}],
["perfect", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100}],
["play_time", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 10000}],
["post_combat", wx.CheckBox, as_checkbox, {}],
["potion_chance", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["potion_slots", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["purgeCost", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["red", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["relic_seed_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["save_date", wx.TextCtrl, as_textctrl, {}],
["seed", wx.TextCtrl, as_textctrl, {}],
["seed_set", wx.CheckBox, as_checkbox, {}],
["shuffle_seed_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 100}],
["smoked", wx.CheckBox, as_checkbox, {}],
["special_seed", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["spirit_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["treasure_seed_count", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
]:
if key in data:
label = wx.StaticText(self, wx.ID_ANY, key)
self.sizer.Add(label, 0, 0, 0)
self.labels_dict[key] = label
value = transform(data[key])
if widget in [wx.SpinCtrl, wx.TextCtrl]:
kw["value"] = value
self.settings_dict[key] = widget(self, wx.ID_ANY, **kw)
if widget in [wx.CheckBox]:
self.settings_dict[key].SetValue(value)
elif widget in [wx.Choice]:
try:
index = kw["choices"].index(value)
except ValueError:
print(f'Expected {key} to know about {value} (but it does not)')
raise
self.settings_dict[key].SetSelection(index)
self.sizer.Add(self.settings_dict[key], 0, 0, 0)
self.FitInside()
self.Layout()
for key in data:
if key in self.settings_dict:
continue
print(key, data[key])
class DeckPanel(wx.ScrolledWindow):
"""
The DeckPanel is in the "Cards" tab in the editor.
Your card deck is on the left side, then there is a cluster of tabs one
per color on the right each containing all the cards of that color.
Clicking on a card in your deck removes it.
Holding down shift and clicking a card in your deck should Upgrade it.
"""
def __init__(self, parent, id, *args, **kwargs):
wx.ScrolledWindow.__init__(self, parent, id, *args, **kwargs)
self.SetScrollRate(5, 5)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.sizer)
self.bindery = {}
self.event_id_to_card = {}
self.cards = []
self.shift_down = False
def onKeyDown(self, event):
keycode = event.GetKeyCode()
if keycode == wx.WXK_SHIFT:
self.shift_down = True
event.Skip()
def onKeyUp(self, event):
keycode = event.GetKeyCode()
if keycode == wx.WXK_SHIFT:
self.shift_down = False
event.Skip()
def redraw_deck(self):
for button_id in self.event_id_to_card:
button = self.bindery[button_id]
# button.Unbind(wx.EVT_KEY_DOWN)
# button.Unbind(wx.EVT_KEY_UP)
# button.Unbind(wx.EVT_BUTTON)
del self.bindery[button_id]
button.Destroy()
self.event_id_to_card = {}
self.Scroll(-1, 0)
self.sizer.Clear()
for card in sorted(self.cards):
print(f'deck redraw: {card}')
self.add_card(card)
self.FitInside()
self.Layout()
self.GetParent().Layout()
def add_card(self, card_obj):
name = card_obj.name
if card_obj.upgrades == 1:
name += "+"
remove_button = wx.Button(
self,
wx.ID_ANY,
name,
(20, 160),
style=wx.NO_BORDER
)
# bind the button to do something
remove_button.Bind(wx.EVT_KEY_DOWN, self.onKeyDown)
remove_button.Bind(wx.EVT_KEY_UP, self.onKeyUp)
remove_button.Bind(wx.EVT_BUTTON, self.remove_card)
self.sizer.Add(remove_button)
remove_button_id = remove_button.GetId()
self.bindery[remove_button_id] = remove_button
self.event_id_to_card[remove_button_id] = card_obj
self.sizer.Layout()
def remove_card(self, event):
event_id = event.GetId()
if self.shift_down:
# upgrade the card
card = self.event_id_to_card[event_id]
if card.upgrades == 0:
self.bindery[event_id].SetLabel(card.name + "+")
card.upgrades = 1
else:
self.bindery[event_id].SetLabel(card.name)
card.upgrades = 0
else:
# remove the card
self.bindery[event_id].Destroy()
card = self.event_id_to_card[event_id]
print(f"Removing card {card}")
self.cards.remove(card)
del self.event_id_to_card[event_id]
del self.bindery[event_id]
self.redraw_deck()
def load_cards(self, data):
self.cards = []
for card in data["cards"]:
print(f"card: {card}")
mycard = copy.deepcopy(all_cards[card["id"]])
if card["upgrades"] == 1:
mycard.upgrades = 1
self.cards.append(mycard)
self.redraw_deck()
def get_cards(self):
return self.cards
class ColorPanel(wx.ScrolledWindow):
"""
The colorpanel is on the 'Cards' menu, it's the tabbed panel
with each of the colors listed and the library of all possible
cards.
"""
def OnClick(self, event):
print(f"Add event: {event}")
event_id = event.GetId()
print(f"event_id: {event_id}")
print(f"cp_bindery[{event_id}] = {self.bindery.get(event_id, 'Missing')}")
library = self.GetParent()
card = library.GetParent()
print(f"Appending card to deck {self.event_id_to_card[event_id]}")
card.deck.cards.append(self.event_id_to_card[event_id])
card.deck.redraw_deck()
def add_cards(self, color):
for card_name in all_cards:
card = all_cards[card_name]
if card.color == color:
add_button = wx.Button(self, wx.ID_ANY, card.name)
self.Bind(wx.EVT_BUTTON, self.OnClick, add_button)
self.event_id_to_card[add_button.GetId()] = card
self.bindery[add_button.GetId()] = add_button
self.sizer.Add(add_button)
def __init__(self, color, parent, id, *args, **kwargs):
wx.ScrolledWindow.__init__(self, parent, id, *args, **kwargs)
self.bindery = {}
self.event_id_to_card = {}
self.SetScrollRate(5, 5)
self.sizer = wx.FlexGridSizer(0, 2, 1, 3)
self.SetSizer(self.sizer)
self.add_cards(color)
class LibraryPanel(wx.Notebook):
def __init__(self, parent, id, *args, **kwargs):
wx.Notebook.__init__(self, parent, id, *args, **kwargs)
self.color = {}
for color in colors:
self.color[color] = ColorPanel(color, self, wx.ID_ANY)
self.AddPage(self.color[color], color)
self.sizer = wx.FlexGridSizer(0, 2, 1, 3)
# self.sizer = wx.BoxSizer(wx.VERTICAL)
# self.sizer.Add(self)
self.SetSizer(self.sizer)
class CardPanel(wx.Panel):
def __init__(self, parent, id, *args, **kwargs):
wx.Panel.__init__(self, parent, id, *args, **kwargs)
self.deck = DeckPanel(
self,
wx.ID_ANY,
wx.DefaultPosition,
(130, 20),
wx.VSCROLL
)
self.library = LibraryPanel(
self,
wx.ID_ANY
)
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.deck, 0, wx.EXPAND)
self.sizer.Add(self.library, 1, wx.EXPAND)
self.SetSizer(self.sizer)
class MyRelicPanel(wx.ScrolledWindow):
def __init__(self, parent, id, *args, **kwargs):
wx.ScrolledWindow.__init__(self, parent, id, *args, **kwargs)
self.SetScrollRate(5, 5)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.sizer)
self.bindery = {}
self.event_id_to_relic = {}
self.relics = []
def redraw_relics(self):
for button_id in self.event_id_to_relic:
button = self.bindery[button_id]
del self.bindery[button_id]
button.Destroy()
self.event_id_to_relic = {}
self.Scroll(-1, 0)
self.sizer.Clear()
for relic in sorted(self.relics):
print(f'deck redraw: {relic}')
self.add_relic(relic)
self.FitInside()
self.Layout()
self.GetParent().Layout()
def add_relic(self, relic_obj):
remove_button = wx.Button(
self,
wx.ID_ANY,
relic_obj.name,
(20, 160),
style=wx.NO_BORDER
)
# bind the button to do something
self.Bind(wx.EVT_BUTTON, self.remove_relic, remove_button)
sizer_item = self.sizer.Add(remove_button)
self.bindery[remove_button.GetId()] = remove_button
self.event_id_to_relic[remove_button.GetId()] = relic_obj
self.sizer.Layout()
self.relics.append(relic_obj)
def remove_relic(self, event):
event_id = event.GetId()
self.bindery[event_id].Destroy()
self.sizer.Layout()
relic = self.event_id_to_relic[event_id]
print(f"Removing relic {relic}")
self.relics.remove(relic)
del self.event_id_to_relic[event_id]
tier_panel = getattr(self.GetParent().all_relics, relic.tier)
tier_panel.add_relic(relic)
def load_relics(self, data):
self.relics = []
for relic_name in sorted(data["relics"]):
self.add_relic(all_relics[relic_name])
self.redraw_relics()
def get_relics(self):
return self.relics
class RelicTierPanel(wx.ScrolledWindow):
bindery = {}
def OnClick(self, event):
print(f"Add relic event: {event}")
event_id = event.GetId()
print(f"event_id: {event_id}")
print(f"bindery[{event_id}] = {self.bindery.get(event_id, 'Missing')}")
self.my_relics.add_relic(self.bindery[event_id])
# remove the button
self.event_id_to_button[event_id].Destroy()
self.sizer.Layout()
def add_relic(self, relic_obj):
add_button = wx.Button(self, wx.ID_ANY, relic_obj.name)
self.Bind(wx.EVT_BUTTON, self.OnClick, add_button)
self.bindery[add_button.GetId()] = relic_obj
self.event_id_to_button[add_button.GetId()] = add_button
self.sizer.Add(add_button)
self.sizer.Layout()
def add_relics(self, tier):
for relic_name in all_relics:
relic = all_relics[relic_name]
if relic.tier != tier:
continue
self.add_relic(relic)
def __init__(self, tier, parent, id, *args, **kwargs):
wx.ScrolledWindow.__init__(self, parent, id, *args, **kwargs)
self.tier = tier
self.my_relics = parent.GetParent().my_relics
self.SetScrollRate(5, 5)
self.sizer = wx.FlexGridSizer(0, 2, 1, 3)
self.SetSizer(self.sizer)
self.bindery = {}
self.event_id_to_button = {}
self.add_relics(tier)
class AllRelicPanel(wx.Notebook):
def __init__(self, parent, id, *args, **kwargs):
wx.Notebook.__init__(self, parent, id, *args, **kwargs)
self.color = {}
for tier in RELIC_TIERS:
setattr(self, tier, RelicTierPanel(tier, self, wx.ID_ANY))
self.AddPage(getattr(self, tier), tier)
self.sizer = wx.FlexGridSizer(0, 2, 1, 3)
self.SetSizer(self.sizer)
class RelicPanel(wx.Panel):
def __init__(self, parent, id, *args, **kwargs):
wx.Panel.__init__(self, parent, id, *args, **kwargs)
self.my_relics = MyRelicPanel(
self,
wx.ID_ANY,
wx.DefaultPosition,
(130, 20),
wx.VSCROLL
)
self.all_relics = AllRelicPanel(self, wx.ID_ANY)
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.my_relics, 0, wx.EXPAND)
self.sizer.Add(self.all_relics, 1, wx.EXPAND)
self.SetSizer(self.sizer)
class MyPotionPanel(wx.ScrolledWindow):
def __init__(self, parent, id, *args, **kwargs):
wx.ScrolledWindow.__init__(self, parent, id, *args, **kwargs)
self.SetScrollRate(5, 5)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.sizer)
self.bindery = {}
self.event_id_to_potion = {}
self.potions = []
self.max_potions = 3
def add_potion(self, potion_obj):
if len(self.potions) < self.max_potions:
remove_button = wx.Button(
self,
wx.ID_ANY,
potion_obj.name,
(20, 160),
style=wx.NO_BORDER
)
# bind the button to do something
self.Bind(wx.EVT_BUTTON, self.remove_potion, remove_button)
sizer_item = self.sizer.Add(remove_button)
self.bindery[remove_button.GetId()] = remove_button
self.event_id_to_potion[remove_button.GetId()] = potion_obj
self.sizer.Layout()
self.potions.append(potion_obj)
def remove_potion(self, event):
event_id = event.GetId()
self.bindery[event_id].Destroy()
self.sizer.Layout()
potion = self.event_id_to_potion[event_id]
print(f"Removing potion {potion}")
self.potions.remove(potion)
del self.event_id_to_potion[event_id]
def load_potions(self, data):
self.max_potions = data["potion_slots"]
for potion_name in sorted(data["potions"]):
self.add_potion(all_potions[potion_name])
self.FitInside()
self.Layout()
def get_potions(self):
return self.potions
class AllPotionPanel(wx.ScrolledWindow):
def __init__(self, parent, id, *args, **kwargs):
wx.ScrolledWindow.__init__(self, parent, id, *args, **kwargs)
self.my_potions = parent.my_potions
self.SetScrollRate(5, 5)
self.sizer = wx.FlexGridSizer(0, 2, 1, 3)
self.SetSizer(self.sizer)
self.bindery = {}
self.event_id_to_button = {}
self.add_potions()
def on_click(self, event):
event_id = event.GetId()
self.my_potions.add_potion(self.bindery[event_id])
def add_potions(self):
for potion_name in all_potions:
potion_obj = all_potions[potion_name]
add_button = wx.Button(self, wx.ID_ANY, potion_obj.name)
self.Bind(wx.EVT_BUTTON, self.on_click, add_button)
self.bindery[add_button.GetId()] = potion_obj
self.event_id_to_button[add_button.GetId()] = add_button
self.sizer.Add(add_button)
self.sizer.Layout()
class PotionPanel(wx.Panel):
def __init__(self, parent, id, *args, **kwargs):
wx.Panel.__init__(self, parent, id, *args, **kwargs)
self.my_potions = MyPotionPanel(
self,
wx.ID_ANY,
wx.DefaultPosition,
(130, 20),
wx.VSCROLL
)
self.all_potions = AllPotionPanel(self, wx.ID_ANY)
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.my_potions, 0, wx.EXPAND)
self.sizer.Add(self.all_potions, 1, wx.EXPAND)
self.SetSizer(self.sizer)
class MetricPanel(wx.ScrolledWindow):
def __init__(self, parent, id, *args, **kwargs):
wx.ScrolledWindow.__init__(self, parent, id, *args, **kwargs)
self.SetScrollRate(5, 5)
self.sizer = wx.FlexGridSizer(0, 2, 1, 3)
self.SetSizer(self.sizer)
def load_metrics(self, data):
metrics_dict = {}
for key, widget, transform, kw in [
["metric_build_version", wx.TextCtrl, as_textctrl, {}],
["metric_campfire_meditates", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["metric_campfire_rested", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["metric_campfire_rituals", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["metric_campfire_upgraded", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["metric_floor_reached", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["metric_playtime", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["metric_purchased_purges", wx.SpinCtrl, as_spinbox, {'min': 0, 'max': 1000}],
["metric_seed_played", wx.TextCtrl, as_textctrl, {}],
]:
if key in data:
label = wx.StaticText(self, wx.ID_ANY, key)
self.sizer.Add(label, 0, 0, 0)
value = transform(data[key])
if widget in [wx.SpinCtrl, wx.TextCtrl]:
kw["value"] = value
metrics_dict[key] = widget(self, wx.ID_ANY, **kw)
if widget in [wx.CheckBox]:
metrics_dict[key].SetValue(value)
elif widget in [wx.Choice]:
try:
index = kw["choices"].index(value)
except ValueError: