-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgem_data.py
163 lines (126 loc) · 4.22 KB
/
gem_data.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
# Python
from enum import Enum
import os
import re
import json
import logging
# Self
import util
# =============================================================================
class gem_color(Enum):
WHITE = 0
RED = 1
GREEN = 2
BLUE = 3
class gem_data_t:
url_suffix_re = re.compile(".com/(.+?)$")
custom_wiki_urls = {
"SupportElementalPenetration": "Elemental_Penetration_Support",
"SupportGreaterSpellEcho": "Greater_Spell_Echo_Support",
}
def __init__(self, id, json):
self.id = id
self.json = json
if json['base_item'] is not None:
self.display_name = json['base_item']['display_name']
#self.id_long = json['base_item']['id']
self.is_support = json['is_support']
self.init_attr(json['static'], 'stat_requirements')
self.init_attr(json['static'], 'required_level')
self.init_attr(json, 'secondary_granted_effect')
self.init_attr(json, 'tags')
def get_color(self):
if self.tags is not None:
if "strength" in self.tags:
return gem_color.RED
elif "dexterity" in self.tags:
return gem_color.GREEN
elif "intelligence" in self.tags:
return gem_color.BLUE
return gem_color.WHITE
def get_color_code(self):
color = self.get_color()
if color == gem_color.RED:
return "#c51e1e"
elif color == gem_color.GREEN:
return "#08a842"
elif color == gem_color.BLUE:
return "#4163c9"
def get_color_str(self):
color = self.get_color()
if color == gem_color.RED:
return "red"
elif color == gem_color.GREEN:
return "green"
elif color == gem_color.BLUE:
return "blue"
elif color == gem_color.WHITE:
return "white"
def get_url_suffix(self):
search = self.url_suffix_re.search(self.wiki_url)
return search.group(1)
# Initialize an attribute, setting its value to None if the key does not
# exist in the JSON.
def init_attr(self, dict, key):
val = None
if key in dict:
val = dict[key]
setattr(self, key, val)
class active_gem_data_t(gem_data_t):
def __init__(self, id, json):
gem_data_t.__init__(self, id, json)
self.description = json['active_skill']['description']
self.is_manually_casted = json['active_skill']['is_manually_casted']
self.is_skill_totem = json['active_skill']['is_skill_totem']
self.types = json['active_skill']['types']
self.weapon_restrictions = json['active_skill']['weapon_restrictions']
self.cast_time = json['cast_time']
self.init_attr(json['static'], 'cooldown')
self.init_attr(json['static'], 'stored_uses')
self.init_attr(json['active_skill'], 'minion_types')
if json['base_item'] is None:
self.display_name = json['active_skill']['display_name']
# derived attributes
self.wiki_url = "https://pathofexile.gamepedia.com/{}".format(self.display_name.replace(" ", "_"))
class support_gem_data_t(gem_data_t):
def __init__(self, id, json):
gem_data_t.__init__(self, id, json)
self.letter = json['support_gem']['letter']
self.supports_gems_only = json['support_gem']['supports_gems_only']
self.init_attr(json['static'], 'mana_multiplier')
if json['base_item'] is None:
self.display_name = id
if id in self.custom_wiki_urls:
self.wiki_url = "https://pathofexile.gamepedia.com/{}".format(self.custom_wiki_urls[id])
else:
self.wiki_url = None
else:
self.wiki_url = "https://pathofexile.gamepedia.com/{}".format(self.display_name.replace(" ", "_"))
# derived attributes
self.short_name = self.display_name.replace(" Support", "")
def load_gems_from_file(path):
if not os.path.isfile(path):
raise Exception("Path to support gem info is invalid. {:s}".format(path))
support_gems = {}
raw_data = None
with open(path, "r") as f:
raw_data = json.loads(f.read())
for id in raw_data:
data = raw_data[id]
gem = None
if data['is_support']:
gem = support_gem_data_t(id, data)
elif 'active_skill' in data:
gem = active_gem_data_t(id, data)
else:
logging.warning("Could not initialize gem {}".format(id))
continue
support_gems[ id ] = gem
logging.debug("Initialized gem {}".format(id))
return support_gems
support_gems = load_gems_from_file("data/gems.json")
def get_support_gem_by_name(name):
if name in support_gems:
return support_gems[name]
else:
raise Exception("{:s} not in support_gems".format(name))