Skip to content

Commit

Permalink
Don't invoke game scanner for the same game more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelseeger committed May 11, 2024
1 parent b0a7273 commit 7e50b81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions obs_tools/sc2client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def get_ongoing_gameinfo(self) -> GameInfo:


class ClientAPIScanner(threading.Thread):

last_gameinfo = None

def __init__(self, name):
super().__init__()
self.name = name
Expand All @@ -93,6 +96,12 @@ def scan_client_api(self):
gameinfo = sc2client.get_ongoing_gameinfo()

if self.is_live_game(gameinfo):
if gameinfo == self.last_gameinfo:
# same ongoing game, just later in time
if gameinfo.displayTime > self.last_gameinfo.displayTime:
continue

self.last_gameinfo = gameinfo
opponent = sc2client.get_opponent_name(gameinfo)
mapname = ""

Expand Down
13 changes: 13 additions & 0 deletions obs_tools/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ class GameInfo(BaseModel):
isReplay: bool
displayTime: float
players: List[Player]

def __eq__(self, other: object) -> bool:
if isinstance(other, GameInfo):
return (
self.isReplay == other.isReplay
and len(self.players) == len(other.players)
and all(
self_player == other_player
for self_player, other_player in zip(self.players, other.players)
)
)
else:
return False

0 comments on commit 7e50b81

Please sign in to comment.