collections: Use a set for game ids
This commit is contained in:
@@ -36,7 +36,7 @@ class Collection(Gio.SimpleActionGroup):
|
|||||||
def __init__(self, **kwargs: Any):
|
def __init__(self, **kwargs: Any):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
self.game_ids = self.game_ids or []
|
self.game_ids = self.game_ids or set()
|
||||||
self.bind_property(
|
self.bind_property(
|
||||||
"icon",
|
"icon",
|
||||||
self,
|
self,
|
||||||
@@ -81,12 +81,12 @@ def _get_collections() -> Generator[Collection]:
|
|||||||
yield Collection(
|
yield Collection(
|
||||||
name=data["name"],
|
name=data["name"],
|
||||||
icon=data["icon"],
|
icon=data["icon"],
|
||||||
game_ids=[
|
game_ids={
|
||||||
ident
|
ident
|
||||||
for ident in data["game-ids"]
|
for ident in data["game-ids"]
|
||||||
if not ident.startswith(imported.ID)
|
if not ident.startswith(imported.ID)
|
||||||
or ident in manually_added_game_ids
|
or ident in manually_added_game_ids
|
||||||
],
|
},
|
||||||
)
|
)
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
continue
|
continue
|
||||||
@@ -111,7 +111,7 @@ def save():
|
|||||||
{
|
{
|
||||||
"name": GLib.Variant.new_string(collection.name),
|
"name": GLib.Variant.new_string(collection.name),
|
||||||
"icon": GLib.Variant.new_string(collection.icon),
|
"icon": GLib.Variant.new_string(collection.icon),
|
||||||
"game-ids": GLib.Variant.new_strv(collection.game_ids),
|
"game-ids": GLib.Variant.new_strv(tuple(collection.game_ids)),
|
||||||
"removed": GLib.Variant.new_boolean(collection.removed),
|
"removed": GLib.Variant.new_boolean(collection.removed),
|
||||||
}
|
}
|
||||||
for collection in cast(Iterable[Collection], model)
|
for collection in cast(Iterable[Collection], model)
|
||||||
|
|||||||
@@ -114,12 +114,11 @@ class CollectionsBox(Adw.Bin):
|
|||||||
for button in cast(Iterable[CollectionButton], self.box):
|
for button in cast(Iterable[CollectionButton], self.box):
|
||||||
game_ids = button.collection.game_ids
|
game_ids = button.collection.game_ids
|
||||||
old_game_ids = game_ids.copy()
|
old_game_ids = game_ids.copy()
|
||||||
in_collection = self.game.game_id in game_ids
|
|
||||||
|
|
||||||
if button.props.active and not in_collection:
|
if button.props.active:
|
||||||
game_ids.append(self.game.game_id)
|
game_ids.add(self.game.game_id)
|
||||||
elif not button.props.active and in_collection:
|
else:
|
||||||
game_ids.remove(self.game.game_id)
|
game_ids.discard(self.game.game_id)
|
||||||
|
|
||||||
if game_ids != old_game_ids:
|
if game_ids != old_game_ids:
|
||||||
filter_changed = True
|
filter_changed = True
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ class Window(Adw.ApplicationWindow):
|
|||||||
def _add_collection(self, game_id: str | None = None):
|
def _add_collection(self, game_id: str | None = None):
|
||||||
collection = Collection()
|
collection = Collection()
|
||||||
if game_id:
|
if game_id:
|
||||||
collection.game_ids.append(game_id)
|
collection.game_ids.add(game_id)
|
||||||
|
|
||||||
details = CollectionDetails(collection=collection)
|
details = CollectionDetails(collection=collection)
|
||||||
details.present(self)
|
details.present(self)
|
||||||
|
|||||||
Reference in New Issue
Block a user