Skip to content

Commit 939a56f

Browse files
update load function to look in family games
1 parent a0b66c0 commit 939a56f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

catalog/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@ def load(slug: str) -> gbt.Game:
2222
"""
2323
slug = str(Path(slug)).replace("\\", "/")
2424

25+
# Try to load from file
2526
for suffix, reader in READERS.items():
2627
resource_path = _CATALOG_RESOURCE / f"{slug}{suffix}"
27-
2828
if resource_path.is_file():
29-
# as_file ensures we have a real filesystem path for the reader
3029
with as_file(resource_path) as path:
3130
return reader(str(path))
3231

33-
raise FileNotFoundError(f"No catalog entry called {slug}.nfg or {slug}.efg")
32+
# Try loading from family games
33+
fg = family_games()
34+
if slug in fg:
35+
return fg[slug]
36+
37+
# Raise error if game does not exist
38+
raise FileNotFoundError(f"No catalog entry called {slug}")
3439

3540

3641
def games() -> pd.DataFrame:

tests/test_catalog.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def test_catalog_load_subdir_slug():
3030
assert isinstance(g, gbt.Game)
3131

3232

33+
def test_catalog_load_family_game():
34+
"""Test loading a game generated from code with a game family func."""
35+
g = gbt.catalog.load("one_shot_trust")
36+
assert isinstance(g, gbt.Game)
37+
38+
3339
def test_catalog_games():
3440
"""Test games() function returns df of game slugs and titles"""
3541
all_games = gbt.catalog.games()

0 commit comments

Comments
 (0)