Skip to content

Commit eb64982

Browse files
committed
review fixes part 2
1 parent e5e3b4e commit eb64982

File tree

9 files changed

+72
-41
lines changed

9 files changed

+72
-41
lines changed

coc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
ACHIEVEMENT_ORDER,
3636
BUILDER_TROOPS_ORDER,
3737
HERO_ORDER,
38-
HERO_PETS_ORDER,
38+
PETS_ORDER,
3939
HOME_TROOP_ORDER,
4040
SIEGE_MACHINE_ORDER,
4141
SPELL_ORDER,

coc/abc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pathlib import Path
2626
from typing import AsyncIterator, Any, Dict, Type, Optional, TYPE_CHECKING
2727

28-
from .enums import Resource
28+
from .enums import PETS_ORDER, Resource
2929
from .miscmodels import try_enum, Badge, TimeDelta
3030
from .iterators import PlayerIterator
3131
from .utils import CaseInsensitiveDict, UnitStat, _get_maybe_first
@@ -204,7 +204,7 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
204204
cls.is_elixir_spell = True
205205
elif production_building == "Mini Spell Factory":
206206
cls.is_dark_spell = True
207-
elif name in coc.HERO_PETS_ORDER:
207+
elif name in PETS_ORDER:
208208
production_building = "Pet Shop"
209209

210210
# load buildings

coc/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class Resource(Enum):
149149

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

152-
HERO_PETS_ORDER = [
152+
PETS_ORDER = [
153153
"L.A.S.S.I",
154154
"Electro Owl",
155155
"Mighty Yak",

coc/players.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
UNRANKED_LEAGUE_DATA,
3636
ACHIEVEMENT_ORDER,
3737
SUPER_TROOP_ORDER,
38-
HERO_PETS_ORDER,
38+
PETS_ORDER,
3939
)
4040
from .abc import BasePlayer
4141
from .hero import Hero, Pet
@@ -237,6 +237,7 @@ class Player(ClanMember):
237237
"war_opted_in",
238238
"_achievements",
239239
"_heroes",
240+
"_pets",
240241
"_labels",
241242
"_spells",
242243
"_home_troops",
@@ -262,7 +263,7 @@ class Player(ClanMember):
262263
"_cs_home_troops",
263264
"_cs_builder_troops",
264265
"_cs_siege_machines",
265-
"_cs_hero_pets",
266+
"_cs_pets",
266267
"_cs_super_troops",
267268
"_cs_heroes",
268269
"_cs_spells",
@@ -281,6 +282,7 @@ def __init__(self, *, data, client, load_game_data=None, **_):
281282
self._home_troops: dict = {}
282283
self._builder_troops: dict = {}
283284
self._super_troops: list = []
285+
self._pets = None # type: Optional[dict]
284286

285287
self.achievement_cls = Achievement
286288
self.hero_cls = Hero
@@ -335,7 +337,7 @@ def _from_data(self, data: dict) -> None:
335337
if self._game_files_loaded:
336338
pet_lookup = [p.name for p in self._client._pet_holder.items]
337339
else:
338-
pet_lookup = HERO_PETS_ORDER
340+
pet_lookup = PETS_ORDER
339341

340342
self._iter_labels = (label_cls(data=ldata, client=self._client) for ldata in data_get("labels", []))
341343
self._iter_achievements = (achievement_cls(data=adata) for adata in data_get("achievements", []))
@@ -400,11 +402,12 @@ def load_game_data(self):
400402
# if self._game_files_loaded:
401403
# return True
402404

403-
holders = (self._client._troop_holder, self._client._hero_holder, self._client._spell_holder)
405+
holders = (self._client._troop_holder, self._client._hero_holder, self._client._spell_holder,
406+
self._client._pet_holder)
404407
if not all(holder.loaded for holder in holders):
405408
self._client._load_holders()
406409

407-
for items, holder in zip((self.troops, self.heroes, self.spells), holders):
410+
for items, holder in zip((self.troops, self.heroes, self.spells, self.pets), holders):
408411
for item in items:
409412
if not item.is_loaded:
410413
if isinstance(item, Troop):
@@ -435,7 +438,7 @@ def achievements(self) -> List[Achievement]:
435438
return list(sorted_achievements.values())
436439

437440
def get_achievement(self, name: str, default_value=None) -> Optional[Achievement]:
438-
"""Returns an achievement with the given name.
441+
"""Gets an achievement with the given name.
439442
440443
Parameters
441444
-----------
@@ -544,18 +547,42 @@ def siege_machines(self) -> List[Troop]:
544547
troops = (t for t in self.troops if t.name in SIEGE_MACHINE_ORDER or t.is_siege_machine)
545548
return list(sorted(troops, key=lambda t: order.get(t.name, 0)))
546549

547-
@cached_property("_cs_hero_pets")
548-
def hero_pets(self) -> List[Pet]:
550+
@cached_property("_cs_pets")
551+
def pets(self) -> List[Pet]:
549552
"""List[:class:`Pet`]: A :class:`List` of the player's hero pets.
550553
551554
This will return hero pets in the order found in the Pet House in-game.
552555
553556
This includes:
554557
- Hero pets only.
555558
"""
556-
order = {k: v for v, k in enumerate(HERO_PETS_ORDER)}
559+
order = {k: v for v, k in enumerate(PETS_ORDER)}
557560
return list(sorted(self._iter_pets, key=lambda t: order.get(t.name, 0)))
558561

562+
def get_pet(self, name: str, default_value=None) -> Optional[Pet]:
563+
"""Gets the pet with the given name.
564+
565+
Parameters
566+
-----------
567+
name: :class:`str`
568+
The name of a pet as found in-game.
569+
default_value:
570+
The default value to return if a pet with ``name`` is not found. Defaults to ``None``.
571+
572+
Returns
573+
--------
574+
Optional[:class:`Pet`]
575+
The returned pet or the ``default_value`` if not found, which defaults to ``None``.
576+
577+
"""
578+
if not self._pets:
579+
_ = self._pets
580+
581+
try:
582+
return self._pets[name]
583+
except KeyError:
584+
return default_value
585+
559586
@cached_property("_cs_super_troops")
560587
def super_troops(self) -> List[Troop]:
561588
"""List[:class:`Troop`]: A :class:`List` of the player's super troops.
@@ -573,7 +600,7 @@ def super_troops(self) -> List[Troop]:
573600
return list(sorted(self._super_troops, key=lambda t: order.get(t.name, 0)))
574601

575602
def get_troop(self, name: str, is_home_troop=None, default_value=None) -> Optional[Troop]:
576-
"""Returns a troop with the given name.
603+
"""Gets a troop with the given name.
577604
578605
Parameters
579606
-----------
@@ -626,16 +653,19 @@ def heroes(self) -> List[Hero]:
626653
return list(sorted_heroes.values())
627654

628655
def get_hero(self, name: str, default_value=None) -> Optional[Hero]:
629-
"""
630-
Gets the player
656+
"""Gets the hero with the given name.
657+
631658
Parameters
632-
----------
633-
name
634-
default_value
659+
-----------
660+
name: :class:`str`
661+
The name of a hero as found in-game.
662+
default_value:
663+
The default value to return if a hero with ``name`` is not found. Defaults to ``None``.
635664
636665
Returns
637-
-------
638-
Hero
666+
--------
667+
Optional[:class:`Hero`]
668+
The returned hero or the ``default_value`` if not found, which defaults to ``None``.
639669
640670
"""
641671
if not self._heroes:
@@ -661,7 +691,7 @@ def spells(self) -> List[Spell]:
661691
key=lambda s: order.get(s.name, 0)))
662692

663693
def get_spell(self, name: str, default_value=None) -> Optional[Spell]:
664-
"""Returns a spell with the given name.
694+
"""Gets the spell with the given name.
665695
666696
Parameters
667697
-----------

coc/raid.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _from_data(self, data):
103103
@property
104104
def attacks(self):
105105
"""List[:class:`RaidAttack`]: The member's attacks in this raid log entry.
106-
Can be empty due to missing parts in the api response
106+
Can be empty due to missing parts in the API response.
107107
"""
108108
list_attacks = self._attacks # type: List[RaidAttack]
109109
if list_attacks:
@@ -146,7 +146,8 @@ class RaidAttack:
146146
"destruction",
147147
"stars",
148148
"_client",
149-
"_raw_data")
149+
"_raw_data",
150+
)
150151

151152
def __repr__(self):
152153
attrs = [
@@ -155,7 +156,7 @@ def __repr__(self):
155156
("district", repr(self.district)),
156157
("attacker_tag", self.attacker_tag),
157158
("destruction", self.destruction),
158-
("stars", self.stars)
159+
("stars", self.stars),
159160
]
160161
return "<%s %s>" % (self.__class__.__name__, " ".join("%s=%r" % t for t in attrs),)
161162

coc/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def get_season_end(month: Optional[int] = None, year: Optional[int] = None) -> d
370370
def get_raid_weekend_start(time: Optional[datetime] = None) -> datetime:
371371
"""Get the datetime that the raid weekend will start.
372372
373-
This goes by the assumption that raid weekends start at friday 7 UTC.
373+
This goes by the assumption that raid weekends start at Friday 7 am UTC.
374374
375375
.. note::
376376
@@ -398,7 +398,7 @@ def get_raid_weekend_start(time: Optional[datetime] = None) -> datetime:
398398
def get_raid_weekend_end(time: Optional[datetime] = None) -> datetime:
399399
"""Get the datetime that the raid weekend will end.
400400
401-
This goes by the assumption that raid weekends end at monday 7 UTC.
401+
This goes by the assumption that raid weekends end at Monday 7 am UTC.
402402
403403
.. note::
404404

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
sys.path.append((root_project / "docs").as_posix())
1414

1515
project = 'coc'
16-
copyright = '2022, mathsman'
17-
author = 'mathsman'
16+
copyright = '2022, mathsman5133'
17+
author = 'mathsman5133'
1818
release = '2.3.0'
1919

2020
# -- General configuration ---------------------------------------------------

docs/models/miscellaneous.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,35 @@ Enumerations
4646
The library provides some enumerations for certain types of strings, as well as orders for troops, spells and
4747
achievements that are used internally.
4848

49-
All elixir troops
49+
All Elixir Troops
5050
^^^^^^^^^^^^^^^^^
5151
ordered as they appear in-game.
5252

5353
.. data:: coc.ELIXIR_TROOP_ORDER
5454

5555

56-
All dark elixir troops
56+
All Dark Elixir Troops
5757
^^^^^^^^^^^^^^^^^^^^^^
5858
ordered as they appear in-game.
5959

6060
.. data:: coc.DARK_ELIXIR_TROOP_ORDER
6161

6262

63-
All siege machines
63+
All Siege Machines
6464
^^^^^^^^^^^^^^^^^^
6565
ordered as they appear in-game.
6666

6767
.. data:: coc.SIEGE_MACHINE_ORDER
6868

6969

70-
All super troops
70+
All Super Troops
7171
^^^^^^^^^^^^^^^^
7272
ordered as they appear in-game.
7373

7474
.. data:: coc.SUPER_TROOP_ORDER
7575

7676

77-
All home troops
77+
All Home Troops
7878
^^^^^^^^^^^^^^^
7979
ordered as they appear in-game.
8080

@@ -84,42 +84,42 @@ This does not contain super troops.
8484
.. data:: coc.HOME_TROOP_ORDER
8585

8686

87-
All builder troops
87+
All Builder Troops
8888
^^^^^^^^^^^^^^^^^^
8989
ordered as they appear in-game.
9090

9191
.. data:: coc.BUILDER_TROOPS_ORDER
9292

9393

94-
All elixir spells
94+
All Elixir Spells
9595
^^^^^^^^^^^^^^^^^
9696
ordered as they appear in-game.
9797

9898
.. data:: coc.ELIXIR_SPELL_ORDER
9999

100100

101-
All dark elixir spells
101+
All Dark Elixir Spells
102102
^^^^^^^^^^^^^^^^^^^^^^
103103
ordered as they appear in-game.
104104

105105
.. data:: coc.DARK_ELIXIR_SPELL_ORDER
106106

107107

108-
All spells
108+
All Spells
109109
^^^^^^^^^^
110110
ordered as they appear in-game.
111111

112112
.. data:: coc.SPELL_ORDER
113113

114114

115-
All heroes
115+
All Heroes
116116
^^^^^^^^^^
117117
ordered as they appear in-game.
118118

119119
.. data:: coc.HERO_ORDER
120120

121121

122-
All hero pets
122+
All Pets
123123
^^^^^^^^^^^^^^
124124
ordered as they appear in-game.
125125

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ docs = ["sphinx",
3030
]
3131

3232
[tool.setuptools]
33-
packages = ["coc", "coc.ext.discordlinks", "coc.static"]
33+
packages = ["coc", "coc.ext.discordlinks", "coc.static", "coc.ext.fullwarapi"]
3434
include-package-data = true
3535

3636
[tool.setuptools.package-data]

0 commit comments

Comments
 (0)