This repository has been archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconstants.py
60 lines (43 loc) · 1.71 KB
/
constants.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
import json
from cardDB import CardDB
class Constants():
"""wraps all constant data"""
CARD_LIMIT = 7
def __init__(self, constantJSON='data/constants.json'):
with open(constantJSON, 'r', encoding='utf8') as file:
constants = json.load(file)
# set informations
self.sets = constants['sets']
self.setIds = {}
for id, setDetails in self.sets.items():
self.setIds[setDetails['name']] = id
# classes
self.classes = constants.get('classes', {})
# special keywords to replace
self.__specials = {}
for key, values in constants['specials'].items():
cards = [CardDB.cleanName(card) for card in values]
self.__specials[CardDB.cleanName(key)] = cards
self.specialNames = self.__specials.keys()
# alternative card names
self.__translations = {}
for key, alts in constants['alternative_names'].items():
org = CardDB.cleanName(key)
if isinstance(alts, list):
for alt in alts:
self.__translations[CardDB.cleanName(alt)] = org
else:
self.__translations[CardDB.cleanName(alts)] = org
self.alternativeNames = self.__translations.keys()
def replaceSpecial(self, cards):
"""replace all special keyword cards in list"""
result = []
for card in cards:
if card in self.__specials:
result.extend(self.__specials[card])
else:
result.append(card)
return result
def translateAlt(self, card):
"""translate alternative card name or return card"""
return self.__translations.get(card, card)