From 79e685ed0b12e77060db6184ac849208a7934087 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sat, 8 Jan 2022 15:03:09 +0100 Subject: [PATCH] Use a list for the games; Preserves games sorting, and lets the campaigns return games in their active state order --- gui.py | 2 +- twitch.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gui.py b/gui.py index 41bccf8..69440d7 100644 --- a/gui.py +++ b/gui.py @@ -252,7 +252,7 @@ class GameSelector: def set_games(self, games: Iterable[Game]): self._games.clear() - self._games.update((str(g), g) for g in sorted(games, key=lambda g: g.name)) + self._games.update((str(g), g) for g in games) self._list.delete(0, "end") self._list.insert("end", *self._games.keys()) self._list.config(width=0) # autoadjust listbox width diff --git a/twitch.py b/twitch.py index acb82c2..974ddab 100644 --- a/twitch.py +++ b/twitch.py @@ -8,7 +8,7 @@ from yarl import URL from time import time from itertools import chain from functools import partial -from typing import Any, Callable, Iterable, Optional, Union, List, Dict, Set, cast, TYPE_CHECKING +from typing import Any, Callable, Iterable, Optional, Union, List, Dict, cast, TYPE_CHECKING try: import aiohttp @@ -176,7 +176,7 @@ class Twitch: WebsocketTopic("User", "Drops", self._user_id, self.process_drops), WebsocketTopic("User", "CommunityPoints", self._user_id, self.process_points), ]) - games: Set[Game] = set() + games: List[Game] = [] selected_game: Optional[Game] = None self.change_state(State.INVENTORY_FETCH) while True: @@ -189,8 +189,8 @@ class Twitch: # we have no use in processing upcoming campaigns here continue for drop in campaign.timed_drops.values(): - if drop.can_earn: - games.add(campaign.game) + if drop.can_earn and (game := campaign.game) not in games: + games.append(game) if drop.can_claim: await drop.claim() self.change_state(State.GAME_SELECT)