-
Notifications
You must be signed in to change notification settings - Fork 17
/
pokemon.py
547 lines (511 loc) · 19.5 KB
/
pokemon.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
from .utils import *
from .tags import Tags
from aqt.qt import *
from aqt.utils import tooltip
# Nickname Settings
def Nickname():
deckmonlist, f = get_pokemons()
if deckmonlist is None:
return
displaylist = []
for item in deckmonlist:
deckname = mw.col.decks.name(item[1])
if len(item) == 4:
if item[2] < 5:
displaytext = "%s - Egg from %s" % (item[3], deckname)
elif item[0].startswith("Eevee"):
displaytext = "%s - Eevee (Level %s) from %s" % (
item[3], int(item[2]), deckname)
else:
displaytext = "%s - %s (Level %s) from %s" % (
item[3], item[0], int(item[2]), deckname)
else:
if item[2] < 5:
displaytext = "Egg from %s" % (deckname)
elif item[0].startswith("Eevee"):
displaytext = "Eevee (Level %s) from %s" % (
int(item[2]), deckname)
else:
displaytext = "%s (Level %s) from %s" % (
item[0], int(item[2]), deckname)
displaylist.append(displaytext)
totallist = list(zip(deckmonlist, displaylist))
nicknamewindow = QWidget()
inp, ok = QInputDialog.getItem(
nicknamewindow, "Pokemanki", "Choose a Pokémon who you would like to give a new nickname", displaylist, 0, False)
deckmon = []
nickname = ""
if ok and inp:
for thing in totallist:
if inp in thing:
deckmon = thing[0]
displaytext = inp
if not deckmon:
return
if len(deckmon) == 4:
nickname = deckmon[3]
inp, ok = QInputDialog.getText(nicknamewindow, "Pokemanki", (
"Enter a new nickname for %s (leave blank to remove nickname)" % displaytext))
if ok:
if inp:
nickname = inp
deckmon = [deckmon[0], deckmon[1], deckmon[2], nickname]
newnickname = QMessageBox()
newnickname.setWindowTitle("Pokemanki")
if int(deckmon[2]) < 5:
newnickname.setText(
"New nickname given to Egg - %s" % (nickname))
elif deckmon[0].startswith("Eevee"):
newnickname.setText(
"New nickname given to Eevee - %s" % (nickname))
else:
newnickname.setText(
"New nickname given to %s - %s" % (deckmon[0], nickname))
newnickname.exec_()
else:
deckmon = [deckmon[0], deckmon[1], deckmon[2]]
nicknameremoved = QMessageBox()
nicknameremoved.setWindowTitle("Pokemanki")
if int(deckmon[2]) < 5:
nicknameremoved.setText("Nickname removed from Egg")
elif deckmon[0].startswith("Eevee"):
nicknameremoved.setText("Nickname removed from Eevee")
else:
nicknameremoved.setText(
"Nickname removed from %s" % deckmon[0])
nicknameremoved.exec_()
modifieddeckmonlist = []
for item in deckmonlist:
if item[1] == deckmon[1]:
modifieddeckmonlist.append(deckmon)
else:
modifieddeckmonlist.append(item)
if f:
write_json("_tagmon.json", modifieddeckmonlist)
else:
write_json("_pokemanki.json", modifieddeckmonlist)
def Toggle():
window = QWidget()
items = ("Decks (Default)", "Tags")
by = get_json("_decksortags.json")
default = 0
if by:
default = 1
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Choose how you would like Pokemanki to assign you Pokémon.", items, default, False)
if ok and inp:
if inp == "Tags":
write_json("_decksortags.json", inp)
tags = Tags()
tags.tagMenu()
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText(
"Please restart Anki to see your updated Pokémon.")
settingschanged.exec_()
else:
write_json("_decksortags.json", "")
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText(
"Please restart Anki to see your updated Pokémon.")
settingschanged.exec_()
# Threshold Settings
def ThresholdSettings():
global thresholdlist
# Find recommended number of cards for starter Pokemon threshold (based on deck with highest number of cards).
decklist = mw.col.decks.allIds()
sumlist = []
for deck in decklist:
sumlist.append(len(mw.col.decks.cids(deck)))
recommended = .797 * max(sumlist)
# Refresh threshold settings
thresholdlist = get_json("_pokemankisettings.json")
# Make settings window (input dialog)
window = QWidget()
inp, ok = QInputDialog.getInt(window, "Pokemanki", (
"Change number of cards needed in a deck to get a starter Pokémon (recommended %d)" % recommended), value=thresholdlist[4])
if ok:
# Make sure threshold is at least 10
if inp < 10:
error = QMessageBox()
error.setWindowTitle("Pokemanki")
error.setText("Number must be at least ten")
error.exec_()
# Change settings and save them if the threshold is changed
elif inp != thresholdlist[4]:
newthresholdlist = [
int(0.1*inp), int(0.25*inp), int(0.5*inp), int(0.75*inp), int(inp)]
write_json("_pokemankisettings.json", newthresholdlist)
# Message box confirming change
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText("Your settings have been changed")
settingschanged.exec_()
# Show the window
window.show()
# Reset Pokemon
def ResetPokemon():
# Make message box
resetwindow = QMessageBox()
resetwindow.setWindowTitle("Pokemanki")
resetwindow.setText("\n".join((
"Are you sure you want to reset your Pokémon?",
"This will reset everything including everstone, settings stored in collection.media, etc.",
"All your pokemons will be lost - both in deck and tag mode."
)))
resetwindow.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
resetwindow.setDefaultButton(QMessageBox.No)
resetresult = resetwindow.exec_()
# Clear pokemanki.json if Yes
if resetresult == QMessageBox.Yes:
reset_files = [
"_pokemanki.json", "_tagmon.json",
"_alolanlist.json", "_everstonelist.json", "_everstonepokemonlist.json", "_megastonelist.json",
"_pokemankisettings.json", "_tagmonsettings.json", "_prestigelist.json", "_tagmon.json", "_tags.json", "_trades.json"
]
for fname in reset_files:
write_json(fname, {})
# TODO reset everstone? and other stuff?
# Message box confirming reset
resetdone = QMessageBox()
resetdone.setWindowTitle("Pokemanki")
resetdone.setText("Pokemon reset")
resetdone.exec_()
def MovetoBottom():
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText(
"Please restart Anki to see your updated settings.")
settingschanged.exec_()
def MovetoTop():
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText(
"Please restart Anki to see your updated settings.")
settingschanged.exec_()
def giveEverstone():
pokemon, f = get_pokemons()
if pokemon is None:
return
everstonelist = get_json("_everstonelist.json", default=[])
everstonepokemonlist = get_json("_everstonepokemonlist.json", default=[])
everstoneables = []
for item in pokemon:
if f:
cb = ("%s (Level %s) from %s" % (item[0], item[2], item[1]))
else:
cb = ("%s (Level %s) from %s" %
(item[0], item[2], mw.col.decks.name(item[1])))
if item[1] in everstonelist:
continue
elif cb in everstoneables:
continue
else:
everstoneables.append(cb)
if not everstoneables:
tooltip("You don't have any pokemons that can get an everstone")
return
window = QWidget()
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Select a Pokemon you would like to give an everstone to.", sorted(everstoneables), 0, False)
if inp and ok:
textlist = inp.split(" from ")
item = textlist[1]
everstone_pokemon_name = inp.split(" (Level ")[0]
if f:
everstonelist.append(item)
everstonepokemonlist.append(everstone_pokemon_name)
else:
everstonelist.append(mw.col.decks.id(item))
everstonepokemonlist.append(everstone_pokemon_name)
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText("Please restart Anki to see changes.")
settingschanged.exec_()
write_json("_everstonelist.json", everstonelist)
write_json("_everstonepokemonlist.json", everstonepokemonlist)
def takeEverstone():
pokemon, f = get_pokemons()
if pokemon is None:
return
everstonelist = get_json("_everstonelist.json", [])
everstonepokemonlist = get_json("_everstonepokemonlist.json", [])
if not everstonelist:
noeverstone = QMessageBox()
noeverstone.setWindowTitle("Pokemanki")
noeverstone.setText("None of your Pokémon are holding everstones.")
noeverstone.exec_()
return
possibleuneverstones = []
for thing in everstonelist:
for item in pokemon:
if item[1] == thing:
if f:
cb = ("%s from %s" % (item[0], item[1]))
else:
cb = ("%s from %s" % (item[0], mw.col.decks.name(item[1])))
if cb in possibleuneverstones:
continue
else:
possibleuneverstones.append(cb)
else:
continue
window = QWidget()
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Select a Pokemon whose everstone you would like to take.", sorted(possibleuneverstones), 0, False)
if inp and ok:
textlist = inp.split(" from ")
item = textlist[1]
if f:
everstonelist.remove(item)
everstonepokemonlist.remove(textlist[0])
else:
everstonelist.remove(mw.col.decks.id(item))
everstonepokemonlist.remove(textlist[0])
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText("Please restart Anki to see your changes.")
settingschanged.exec_()
write_json("_everstonelist.json", everstonelist)
def giveMegastone():
pokemon, f = get_pokemons()
if pokemon is None:
return
megastonelist = get_json("_megastonelist.json", [])
megastoneables = []
for item in pokemon:
if item[2] >= 70:
if f:
cb = ("%s (Level %s) from %s" % (item[0], item[2], item[1]))
else:
cb = ("%s (Level %s) from %s" %
(item[0], item[2], mw.col.decks.name(item[1])))
if item[1] in megastonelist:
continue
elif cb in megastoneables:
continue
else:
megastoneables.append(cb)
else:
continue
if not megastoneables:
tooltip("You don't have any pokemons that can get a mega stone")
return
window = QWidget()
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Select a Pokemon you would like to give a mega stone to", sorted(megastoneables), 0, False)
if inp and ok:
textlist = inp.split(" from ")
item = textlist[1]
if f:
megastonelist.append(item)
else:
megastonelist.append(mw.col.decks.id(item))
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText("Please restart Anki to see your changes.")
settingschanged.exec_()
write_json("_megastonelist.json", megastonelist)
def takeMegastone():
pokemon, f = get_pokemons()
if pokemon is None:
return
megastonelist = get_json("_megastonelist.json", [])
if not megastonelist:
nomegastone = QMessageBox()
nomegastone.setWindowTitle("Pokemanki")
nomegastone.setText("None of your Pokémon are holding mega stones.")
nomegastone.exec_()
return
possibleunmegastones = []
for thing in megastonelist:
for item in pokemon:
if item[1] == thing:
if f:
cb = ("%s from %s" % (item[0], item[1]))
else:
cb = ("%s from %s" % (item[0], mw.col.decks.name(item[1])))
if cb in possibleunmegastones:
continue
else:
possibleunmegastones.append(cb)
else:
continue
window = QWidget()
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Select a Pokemon whose mega stone you would like to take", sorted(possibleunmegastones), 0, False)
if inp and ok:
textlist = inp.split(" from ")
item = textlist[1]
if f:
megastonelist.remove(item)
else:
megastonelist.remove(mw.col.decks.id(item))
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText("Please restart Anki to see your changes.")
settingschanged.exec_()
write_json("_megastonelist.json", megastonelist)
def giveAlolanPassport():
pokemon, f = get_pokemons()
if pokemon is None:
return
alolanlist = get_json("_alolanlist.json", [])
alolanables = []
for item in pokemon:
if f:
cb = ("%s (Level %s) from %s" % (item[0], item[2], item[1]))
else:
cb = ("%s (Level %s) from %s" %
(item[0], item[2], mw.col.decks.name(item[1])))
if item[1] in alolanlist:
continue
elif cb in alolanables:
continue
else:
alolanables.append(cb)
if not alolanables:
tooltip("You don't have any pokemons that you can give Alolan Passport to")
return
window = QWidget()
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Select a Pokemon you would like to give an Alolan Passport to.", sorted(alolanables), 0, False)
if inp and ok:
textlist = inp.split(" from ")
item = textlist[1]
alolan_pokemon_name = inp.split(" (Level ")[0]
if f:
alolanlist.append(item)
else:
alolanlist.append(mw.col.decks.id(item))
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText("Please restart Anki to see changes.")
settingschanged.exec_()
write_json("_alolanlist.json", alolanlist)
def takeAlolanPassport():
pokemon, f = get_pokemons()
if pokemon is None:
return
alolanlist = get_json("_alolanlist.json", [])
if not alolanlist:
noalolan = QMessageBox()
noalolan.setWindowTitle("Pokemanki")
noalolan.setText(
"None of your Pokémon are holding an Alolan Passport.")
noalolan.exec_()
return
possibleunalolans = []
for thing in alolanlist:
for item in pokemon:
if item[1] == thing:
if f:
cb = ("%s from %s" % (item[0], item[1]))
else:
cb = ("%s from %s" % (item[0], mw.col.decks.name(item[1])))
if cb in possibleunalolans:
continue
else:
possibleunalolans.append(cb)
else:
continue
window = QWidget()
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Select a Pokemon whose Alolan Passport you would like to take.", sorted(possibleunalolans), 0, False)
if inp and ok:
textlist = inp.split(" from ")
item = textlist[1]
if f:
alolanlist.remove(item)
else:
alolanlist.remove(mw.col.decks.id(item))
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText("Please restart Anki to see your changes.")
settingschanged.exec_()
write_json("_alolanlist.json", alolanlist)
def PrestigePokemon():
pokemon, f = get_pokemons()
if pokemon is None:
return
prestigelist = get_json("_prestigelist.json", [])
possibleprestiges = []
for item in pokemon:
if item[2] >= 60:
if f:
cb = ("%s (Level %s) from %s" % (item[0], item[2], item[1]))
else:
cb = ("%s (Level %s) from %s" %
(item[0], item[2], mw.col.decks.name(item[1])))
if item[1] in prestigelist:
continue
elif cb in possibleprestiges:
continue
else:
possibleprestiges.append(cb)
else:
continue
window = QWidget()
if not possibleprestiges:
tooltip("You don't have any pokemons with level > 60")
return
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Select a Pokemon you would like to prestige (decreases level by 50, only availabe for Pokemon with level > 60)", sorted(possibleprestiges), 0, False)
if inp and ok:
textlist = inp.split(" from ")
item = textlist[1]
if f:
prestigelist.append(item)
else:
prestigelist.append(mw.col.decks.id(item))
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText(
"Please restart Anki to see your prestiged Pokémon.")
settingschanged.exec_()
write_json("_prestigelist.json", prestigelist)
def UnprestigePokemon():
pokemon, f = get_pokemons()
if pokemon is None:
return
prestigelist = get_json("_prestigelist.json", [])
if not prestigelist:
noprestige = QMessageBox()
noprestige.setWindowTitle("Pokemanki")
noprestige.setText("You have no prestiged Pokémon.")
noprestige.exec_()
return
possibleunprestiges = []
for thing in prestigelist:
for item in pokemon:
if item[1] == thing:
if f:
cb = ("%s from %s" % (item[0], item[1]))
else:
cb = ("%s from %s" % (item[0], mw.col.decks.name(item[1])))
if cb in possibleunprestiges:
continue
else:
possibleunprestiges.append(cb)
else:
continue
if not possibleunprestiges:
tooltip("You don't have any pokemons with prestige")
return
window = QWidget()
inp, ok = QInputDialog.getItem(
window, "Pokemanki", "Select a Pokemon you would like to unprestige", sorted(possibleunprestiges), 0, False)
if inp and ok:
textlist = inp.split(" from ")
item = textlist[1]
if f:
prestigelist.remove(item)
else:
prestigelist.remove(mw.col.decks.id(item))
settingschanged = QMessageBox()
settingschanged.setWindowTitle("Pokemanki")
settingschanged.setText(
"Please restart Anki to see your unprestiged Pokémon.")
settingschanged.exec_()
write_json("_prestigelist.json", prestigelist)