-
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.
- Loading branch information
Showing
5 changed files
with
200 additions
and
213 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
from time import sleep | ||
import traceback | ||
from time import sleep | ||
|
||
from hslog.live.parser import LiveLogParser | ||
|
||
|
||
""" | ||
---------------------------------------------------------------------- | ||
LiveLogParser assumes that you"ve configured Power.log to be a symlink | ||
---------------------------------------------------------------------- | ||
LiveLogParser assumes that you"ve configured Power.log to be a symlink | ||
in "SOME_PATH/Hearthstone/Logs" folder: | ||
ln -s Power.log /tmp/hearthstone-redirected.log | ||
in "SOME_PATH/Hearthstone/Logs" folder: | ||
ln -s Power.log /tmp/hearthstone-redirected.log | ||
this will redirect all data coming into Power.log | ||
so we can access it from a RAM disk | ||
---------------------------------------------------------------------- | ||
For better performance make /tmp of type tmpfs (or another location) | ||
this will redirect all data coming into Power.log | ||
so we can access it from a RAM disk | ||
---------------------------------------------------------------------- | ||
For better performance make /tmp of type tmpfs (or another location) | ||
in /etc/fstab add line: | ||
tmpfs /tmp tmpfs nodev,nosuid,size=1G 0 0 | ||
in /etc/fstab add line: | ||
tmpfs /tmp tmpfs nodev,nosuid,size=1G 0 0 | ||
this will create in-memory storage which is faster then SSD | ||
you need to restart the computer for this to take effect | ||
---------------------------------------------------------------------- | ||
this will create in-memory storage which is faster then SSD | ||
you need to restart the computer for this to take effect | ||
---------------------------------------------------------------------- | ||
""" | ||
|
||
|
||
def main(): | ||
try: | ||
file = "/tmp/hearthstone-redirected.log" | ||
liveParser = LiveLogParser(file) | ||
liveParser.start() | ||
try: | ||
file = "/tmp/hearthstone-redirected.log" | ||
liveParser = LiveLogParser(file) | ||
liveParser.start() | ||
|
||
while True: | ||
sleep(1) | ||
while True: | ||
sleep(1) | ||
|
||
except Exception as e: | ||
print(traceback.format_exc()) | ||
liveParser.stop() | ||
except Exception as e: | ||
print(traceback.format_exc()) | ||
liveParser.stop() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
main() |
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,69 +1,70 @@ | ||
from hearthstone.entities import Card, Entity | ||
from hearthstone.enums import GameTag | ||
|
||
""" | ||
* Card is called on export from game | ||
* LiveCard replaces Card and inserts update_callback | ||
* The point is to become able to route update events towards an API end-point | ||
""" | ||
|
||
|
||
class LiveEntity(Entity): | ||
|
||
def __init__(self, entity_id, parent, **kwargs): | ||
""" Entity requires an ID, store everything else in kwargs """ | ||
self.parent = parent | ||
self.game_index = self.parent.parser.games.index(self.parent) | ||
super(LiveEntity, self).__init__(entity_id, **kwargs) | ||
def __init__(self, entity_id, parent, **kwargs): | ||
""" Entity requires an ID, store everything else in kwargs """ | ||
self.parent = parent | ||
self.game_index = self.parent.parser.games.index(self.parent) | ||
super(LiveEntity, self).__init__(entity_id, **kwargs) | ||
|
||
# push data to an end-point | ||
print(f"GAME {self.game_index} --- ENTITY CREATED:", self) | ||
|
||
# push data to an end-point | ||
print(f"GAME {self.game_index} --- ENTITY CREATED:", self) | ||
def tag_change(self, tag, value): | ||
if tag == GameTag.CONTROLLER and not self._initial_controller: | ||
self._initial_controller = self.tags.get(GameTag.CONTROLLER, value) | ||
self.tags[tag] = value | ||
|
||
def tag_change(self, tag, value): | ||
if tag == GameTag.CONTROLLER and not self._initial_controller: | ||
self._initial_controller = self.tags.get(GameTag.CONTROLLER, value) | ||
self.tags[tag] = value | ||
# update notify | ||
self.update_callback() | ||
|
||
# update notify | ||
self.update_callback() | ||
def update_callback(self): | ||
# push data to an end-point | ||
print(f"GAME {self.game_index} --- ENTITY UPDATED:", self) | ||
|
||
def update_callback(self): | ||
# push data to an end-point | ||
print(f"GAME {self.game_index} --- ENTITY UPDATED:", self) | ||
|
||
""" | ||
* Card is called on export from game | ||
* LiveCard replaces Card and inserts update_callback | ||
* The point is to become able to route update events towards an API end-point | ||
""" | ||
|
||
|
||
class LiveCard(Card, LiveEntity): | ||
|
||
def __init__(self, entity_id, card_id, parent): | ||
super(LiveCard, self).__init__( | ||
entity_id=entity_id, | ||
card_id=card_id, | ||
parent=parent) | ||
|
||
""" if card_id doesn"t change, there"s no need to pass it as the argument. | ||
we can use self.card_id instead as it is set by Card class """ | ||
def reveal(self, card_id, tags): | ||
self.revealed = True | ||
self.card_id = card_id | ||
if self.initial_card_id is None: | ||
self.initial_card_id = card_id | ||
self.tags.update(tags) | ||
|
||
# update notify | ||
self.update_callback() | ||
|
||
def hide(self): | ||
self.revealed = False | ||
|
||
# update notify | ||
self.update_callback() | ||
|
||
""" same comment as for reveal """ | ||
def change(self, card_id, tags): | ||
if self.initial_card_id is None: | ||
self.initial_card_id = card_id | ||
self.card_id = card_id | ||
self.tags.update(tags) | ||
|
||
# update notify | ||
self.update_callback() | ||
def __init__(self, entity_id, card_id, parent): | ||
super(LiveCard, self).__init__( | ||
entity_id=entity_id, | ||
card_id=card_id, | ||
parent=parent) | ||
|
||
""" if card_id doesn"t change, there"s no need to pass it as the argument. | ||
we can use self.card_id instead as it is set by Card class """ | ||
def reveal(self, card_id, tags): | ||
self.revealed = True | ||
self.card_id = card_id | ||
if self.initial_card_id is None: | ||
self.initial_card_id = card_id | ||
self.tags.update(tags) | ||
|
||
# update notify | ||
self.update_callback() | ||
|
||
def hide(self): | ||
self.revealed = False | ||
|
||
# update notify | ||
self.update_callback() | ||
|
||
""" same comment as for reveal """ | ||
def change(self, card_id, tags): | ||
if self.initial_card_id is None: | ||
self.initial_card_id = card_id | ||
self.card_id = card_id | ||
self.tags.update(tags) | ||
|
||
# update notify | ||
self.update_callback() |
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.