-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved docstrings and removed parent dependency for LiveEntities
- Loading branch information
Showing
7 changed files
with
244 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
from hearthstone.enums import GameTag | ||
|
||
from hslog.export import EntityTreeExporter | ||
from hslog.live.entities import LiveCard | ||
from hslog.live.entities import LiveGame | ||
from hslog.live.entities import LivePlayer | ||
from hslog.live.utils import ACCESS_DEBUG | ||
|
||
|
||
class LiveEntityTreeExporter(EntityTreeExporter): | ||
""" | ||
Inherits EntityTreeExporter to provide Live entities | ||
""" | ||
|
||
game_class = LiveGame | ||
player_class = LivePlayer | ||
card_class = LiveCard | ||
|
||
def __init__(self, packet_tree): | ||
super(LiveEntityTreeExporter, self).__init__(packet_tree) | ||
|
||
def handle_full_entity(self, packet): | ||
entity_id = packet.entity | ||
|
||
# Check if the entity already exists in the game first. | ||
# This prevents creating it twice. | ||
# This can legitimately happen in case of GAME_RESET | ||
if entity_id <= len(self.game.entities): | ||
# That first if check is an optimization to prevent always looping over all of | ||
# the game"s entities every single FULL_ENTITY packet... | ||
# FIXME: Switching to a dict for game.entities would simplify this. | ||
existing_entity = self.game.find_entity_by_id(entity_id) | ||
if existing_entity is not None: | ||
existing_entity.card_id = packet.card_id | ||
existing_entity.tags = dict(packet.tags) | ||
return existing_entity | ||
|
||
entity = self.card_class(entity_id, packet.card_id, self.packet_tree) | ||
def handle_player(self, packet): | ||
ACCESS_DEBUG(self.__class__, 'handle_player') | ||
entity_id = int(packet.entity) | ||
|
||
if hasattr(self.packet_tree, "manager"): | ||
# If we have a PlayerManager, first we mutate the CreateGame.Player packet. | ||
# This will have to change if we're ever able to immediately get the names. | ||
player = self.packet_tree.manager.get_player_by_id(entity_id) | ||
packet.name = player.name | ||
entity = self.player_class(entity_id, packet.player_id, packet.hi, packet.lo, packet.name) | ||
entity.tags = dict(packet.tags) | ||
self.game.register_entity(entity) | ||
return entity | ||
entity.initial_hero_entity_id = entity.tags.get(GameTag.HERO_ENTITY, 0) | ||
return entity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.