Stop automatic switching between games;
IDLE state + listbox selection clear fix
This commit is contained in:
1 parent
1d65fddfa1
commit
cf1830cce9
4 files changed
+9
-24
No files matched your search
@@ -9,7 +9,6 @@ This application allows you to AFK mine timed Twitch drops, without having to wo
|
||||
- Stream tags and drop campaign validation, so you don't end up watching a stream that can't earn you the drop.
|
||||
- Channel stream switching, when the one you were currently watching goes offline.
|
||||
- Cookie saving between sessions, so you don't need to login every time.
|
||||
- Game switching once there's no more drops available for the selected game.
|
||||
- Mining is stopped automatically when the last available drop has been mined.
|
||||
|
||||
**Not managed / TODO / manual:**
|
||||
|
||||
@@ -47,6 +47,7 @@ FORMATTER = logging.Formatter(
|
||||
|
||||
|
||||
class State(Enum):
|
||||
IDLE = auto()
|
||||
INVENTORY_FETCH = auto()
|
||||
GAMES_UPDATE = auto()
|
||||
GAME_SELECT = auto()
|
||||
|
||||
@@ -281,6 +281,7 @@ class GameSelector:
|
||||
)
|
||||
if selected_index is not None:
|
||||
# reselect the currently selected item
|
||||
self._list.selection_clear(0, "end")
|
||||
self._list.selection_set(selected_index)
|
||||
else:
|
||||
# the game we've had selected isn't there anymore - clear selection
|
||||
@@ -302,25 +303,13 @@ class GameSelector:
|
||||
if not self._games:
|
||||
raise RuntimeError("No games to select from")
|
||||
# select and return the first game from the list
|
||||
self._list.selection_clear(0, "end")
|
||||
self._list.selection_set(0)
|
||||
first_game = next(iter(self._games.values()))
|
||||
self._selection = str(first_game)
|
||||
return first_game
|
||||
return self._games[self._selection]
|
||||
|
||||
def select_next(self) -> Optional[Game]:
|
||||
current = self._list.curselection()
|
||||
if not current:
|
||||
return self.get_selection()
|
||||
next_idx = current[0]+1
|
||||
game_name = self._list.get(next_idx)
|
||||
if not game_name:
|
||||
# this was the last game on the list
|
||||
return None
|
||||
self._list.selection_set(next_idx)
|
||||
self._selection = game_name
|
||||
return self._games[game_name]
|
||||
|
||||
|
||||
class _BaseVars(TypedDict):
|
||||
progress: DoubleVar
|
||||
@@ -978,9 +967,6 @@ if __name__ == "__main__":
|
||||
create_game(491115, "Paladins"),
|
||||
# create_game(460630, "Tom Clancy's Rainbow Six Siege"),
|
||||
])
|
||||
gui.games.select_next()
|
||||
gui.games.select_next()
|
||||
gui.games.select_next()
|
||||
# Channel list
|
||||
gui.channels.display(create_channel("PaladinsGame", 0, None, 0, 0))
|
||||
channel = create_channel("Traitus", 1, None, 0, 0)
|
||||
|
||||
@@ -205,7 +205,10 @@ class Twitch:
|
||||
selected_game: Optional[Game] = None
|
||||
self.change_state(State.INVENTORY_FETCH)
|
||||
while True:
|
||||
if self._state is State.INVENTORY_FETCH:
|
||||
if self._state is State.IDLE:
|
||||
# clear the flag and wait until it's set again
|
||||
self._state_change.clear()
|
||||
elif self._state is State.INVENTORY_FETCH:
|
||||
await self.fetch_inventory()
|
||||
self.change_state(State.GAMES_UPDATE)
|
||||
elif self._state is State.GAMES_UPDATE:
|
||||
@@ -308,12 +311,8 @@ class Twitch:
|
||||
break
|
||||
else:
|
||||
self.stop_watching()
|
||||
selected_game = self.gui.games.select_next()
|
||||
if selected_game is None:
|
||||
self.gui.print("No suitable channel to watch.")
|
||||
# TODO: Figure out what to do here.
|
||||
return
|
||||
self.change_state(State.CHANNELS_CLEANUP)
|
||||
self.gui.print(f"No suitable channel to watch for game: {selected_game}")
|
||||
self.change_state(State.IDLE)
|
||||
await self._state_change.wait()
|
||||
|
||||
@task_wrapper
|
||||
|
||||
Reference in new issue
Block a user