Skip to content

Commit ba80ff8

Browse files
committed
[BUG] The new json files do not have resourc cost. Will need to fix them.
1 parent 9a75678 commit ba80ff8

File tree

12 files changed

+85
-13
lines changed

12 files changed

+85
-13
lines changed

coc/enums.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Resource(Enum):
8383
"Bowler",
8484
"Ice Golem",
8585
"Headhunter",
86+
"Electro Titan",
8687
]
8788

8889
SIEGE_MACHINE_ORDER = [
@@ -91,7 +92,8 @@ class Resource(Enum):
9192
"Stone Slammer",
9293
"Siege Barracks",
9394
"Log Launcher",
94-
"Flame Flinger"
95+
"Flame Flinger",
96+
"Battle Drill",
9597
]
9698

9799
SUPER_TROOP_ORDER = [
@@ -108,7 +110,7 @@ class Resource(Enum):
108110
"Super Valkyrie",
109111
"Super Witch",
110112
"Ice Hound",
111-
"Super Bowler"
113+
"Super Bowler",
112114
]
113115

114116
HOME_TROOP_ORDER = HOME_TROOP_ORDER + SIEGE_MACHINE_ORDER
@@ -141,11 +143,21 @@ class Resource(Enum):
141143
"Haste Spell",
142144
"Skeleton Spell",
143145
"Bat Spell",
146+
"Recall Spell",
144147
]
145148

146149
HERO_ORDER = ["Barbarian King", "Archer Queen", "Grand Warden", "Royal Champion", "Battle Machine"]
147150

148-
HERO_PETS_ORDER = ["L.A.S.S.I", "Electro Owl", "Mighty Yak", "Unicorn"]
151+
HERO_PETS_ORDER = [
152+
"L.A.S.S.I",
153+
"Electro Owl",
154+
"Mighty Yak",
155+
"Unicorn",
156+
"Poison Lizard",
157+
"Diggy",
158+
"Frosty",
159+
"Phoenix",
160+
]
149161

150162
ACHIEVEMENT_ORDER = [
151163
# Home Base

coc/players.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,13 @@ def spells(self) -> typing.List[Spell]:
650650
651651
This will return spells in the order found in both spell factory and labatory in-game.
652652
"""
653-
dict_spells = self._spells = {s.name: s for s in self._iter_spells}
653+
self._spells = {s.name: s for s in self._iter_spells}
654+
dict_spells = self._spells
654655
order = {k: v for v, k in enumerate(SPELL_ORDER)}
655-
return list(sorted(dict_spells.values(), key=lambda s: order.get(s.name)))
656+
657+
return list(sorted(
658+
dict_spells.values(),
659+
key=lambda s: order.get(s.name, 0)))
656660

657661
def get_spell(self, name: str, default_value=None) -> typing.Optional[Spell]:
658662
"""Returns a spell with the given name.

coc/static/buildings.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/characters.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/heroes.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/object_ids.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/pets.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/spells.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/texts_EN.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

coc/static/update_static.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Automates updating the static files. If new files need to be added, then
3+
place them in the TARGETS list.
4+
"""
5+
import json
6+
import urllib
7+
import urllib.request
8+
9+
# Targets first index is the URL and the second is the filename. If filename
10+
# is None, then the url name is used
11+
TARGETS = [
12+
("buildings.json", None),
13+
("characters.json", None),
14+
("heroes.json", None),
15+
("object_ids.json", None),
16+
("pets.json", None),
17+
("spells.json", None),
18+
("supers.json", None),
19+
("lang/texts_EN.json", "texts_EN.json"),
20+
]
21+
22+
BASE_URL = "https://coc.guide/static/json/"
23+
24+
25+
def main():
26+
for target_file in TARGETS:
27+
req = urllib.request.Request(f"{BASE_URL}{target_file[0]}")
28+
try:
29+
print(f"[+] Downloading {req.full_url}")
30+
with urllib.request.urlopen(req) as response:
31+
bytes = response.read()
32+
encoding = response.info().get_content_charset('utf8')
33+
except urllib.error.URLError:
34+
print(f"[!] Failed to fetch {req.full_url}")
35+
continue
36+
37+
json_obj = json.loads(bytes.decode(encoding))
38+
39+
filename = target_file[0] if target_file[1] is None else target_file[1]
40+
with open(filename, "wt", encoding="UTF-8") as outfile:
41+
json.dump(json_obj, outfile)
42+
43+
44+
if __name__ == "__main__":
45+
main()

0 commit comments

Comments
 (0)