|
1 | 1 | from hearthstone.entities import Card, Entity |
2 | 2 | from hearthstone.enums import GameTag |
3 | 3 |
|
4 | | -""" |
5 | | - * Card is called on export from game |
6 | | - * LiveCard replaces Card and inserts update_callback |
7 | | - * The point is to become able to route update events towards an API end-point |
8 | | -""" |
9 | | - |
10 | 4 |
|
11 | 5 | class LiveEntity(Entity): |
12 | 6 |
|
13 | | - def __init__(self, entity_id, parent, **kwargs): |
14 | | - """ Entity requires an ID, store everything else in kwargs """ |
15 | | - self.parent = parent |
16 | | - self.game_index = self.parent.parser.games.index(self.parent) |
17 | | - super(LiveEntity, self).__init__(entity_id, **kwargs) |
| 7 | + def __init__(self, entity_id, parent, **kwargs): |
| 8 | + """ Entity requires an ID, store everything else in kwargs """ |
| 9 | + self.parent = parent |
| 10 | + self.game_index = self.parent.parser.games.index(self.parent) |
| 11 | + super(LiveEntity, self).__init__(entity_id, **kwargs) |
| 12 | + |
| 13 | + # push data to an end-point |
| 14 | + print(f"GAME {self.game_index} --- ENTITY CREATED:", self) |
18 | 15 |
|
19 | | - # push data to an end-point |
20 | | - print(f"GAME {self.game_index} --- ENTITY CREATED:", self) |
| 16 | + def tag_change(self, tag, value): |
| 17 | + if tag == GameTag.CONTROLLER and not self._initial_controller: |
| 18 | + self._initial_controller = self.tags.get(GameTag.CONTROLLER, value) |
| 19 | + self.tags[tag] = value |
21 | 20 |
|
22 | | - def tag_change(self, tag, value): |
23 | | - if tag == GameTag.CONTROLLER and not self._initial_controller: |
24 | | - self._initial_controller = self.tags.get(GameTag.CONTROLLER, value) |
25 | | - self.tags[tag] = value |
| 21 | + # update notify |
| 22 | + self.update_callback() |
26 | 23 |
|
27 | | - # update notify |
28 | | - self.update_callback() |
| 24 | + def update_callback(self): |
| 25 | + # push data to an end-point |
| 26 | + print(f"GAME {self.game_index} --- ENTITY UPDATED:", self) |
29 | 27 |
|
30 | | - def update_callback(self): |
31 | | - # push data to an end-point |
32 | | - print(f"GAME {self.game_index} --- ENTITY UPDATED:", self) |
| 28 | + |
| 29 | +""" |
| 30 | + * Card is called on export from game |
| 31 | + * LiveCard replaces Card and inserts update_callback |
| 32 | + * The point is to become able to route update events towards an API end-point |
| 33 | +""" |
33 | 34 |
|
34 | 35 |
|
35 | 36 | class LiveCard(Card, LiveEntity): |
36 | 37 |
|
37 | | - def __init__(self, entity_id, card_id, parent): |
38 | | - super(LiveCard, self).__init__( |
39 | | - entity_id=entity_id, |
40 | | - card_id=card_id, |
41 | | - parent=parent) |
42 | | - |
43 | | - """ if card_id doesn"t change, there"s no need to pass it as the argument. |
44 | | - we can use self.card_id instead as it is set by Card class """ |
45 | | - def reveal(self, card_id, tags): |
46 | | - self.revealed = True |
47 | | - self.card_id = card_id |
48 | | - if self.initial_card_id is None: |
49 | | - self.initial_card_id = card_id |
50 | | - self.tags.update(tags) |
51 | | - |
52 | | - # update notify |
53 | | - self.update_callback() |
54 | | - |
55 | | - def hide(self): |
56 | | - self.revealed = False |
57 | | - |
58 | | - # update notify |
59 | | - self.update_callback() |
60 | | - |
61 | | - """ same comment as for reveal """ |
62 | | - def change(self, card_id, tags): |
63 | | - if self.initial_card_id is None: |
64 | | - self.initial_card_id = card_id |
65 | | - self.card_id = card_id |
66 | | - self.tags.update(tags) |
67 | | - |
68 | | - # update notify |
69 | | - self.update_callback() |
| 38 | + def __init__(self, entity_id, card_id, parent): |
| 39 | + super(LiveCard, self).__init__( |
| 40 | + entity_id=entity_id, |
| 41 | + card_id=card_id, |
| 42 | + parent=parent) |
| 43 | + |
| 44 | + """ if card_id doesn"t change, there"s no need to pass it as the argument. |
| 45 | + we can use self.card_id instead as it is set by Card class """ |
| 46 | + def reveal(self, card_id, tags): |
| 47 | + self.revealed = True |
| 48 | + self.card_id = card_id |
| 49 | + if self.initial_card_id is None: |
| 50 | + self.initial_card_id = card_id |
| 51 | + self.tags.update(tags) |
| 52 | + |
| 53 | + # update notify |
| 54 | + self.update_callback() |
| 55 | + |
| 56 | + def hide(self): |
| 57 | + self.revealed = False |
| 58 | + |
| 59 | + # update notify |
| 60 | + self.update_callback() |
| 61 | + |
| 62 | + """ same comment as for reveal """ |
| 63 | + def change(self, card_id, tags): |
| 64 | + if self.initial_card_id is None: |
| 65 | + self.initial_card_id = card_id |
| 66 | + self.card_id = card_id |
| 67 | + self.tags.update(tags) |
| 68 | + |
| 69 | + # update notify |
| 70 | + self.update_callback() |
0 commit comments