aboutsummaryrefslogtreecommitdiff
path: root/scripts/data.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/data.py')
-rwxr-xr-xscripts/data.py71
1 files changed, 64 insertions, 7 deletions
diff --git a/scripts/data.py b/scripts/data.py
index b72fc094..fadf9613 100755
--- a/scripts/data.py
+++ b/scripts/data.py
@@ -7,10 +7,67 @@ CARDS_DATA_DIR = GAME_ROOT / 'data' / 'cards'
CARDS_TO_SETS = {}
SETS_TO_CARDS = {}
-# build up the card lookup dictionaries
-for set_dir in CARDS_DATA_DIR.iterdir():
- set_name = set_dir.name
- SETS_TO_CARDS[set_name] = []
- for card in set_dir.iterdir():
- SETS_TO_CARDS[set_name].append(card.stem)
- CARDS_TO_SETS[card.stem] = set_name
+
+def populate_lookup_dicts():
+ """Populate the global lookup dictionaries"""
+ for set_dir in CARDS_DATA_DIR.iterdir():
+ set_name = set_dir.name
+ SETS_TO_CARDS[set_name] = []
+ for card in set_dir.iterdir():
+ SETS_TO_CARDS[set_name].append(card.stem)
+ CARDS_TO_SETS[card.stem] = set_name
+
+
+def name2set(card: str) -> str:
+ """Return the set containing the card
+
+ :param card: the english card name
+ :returns: the set containing the card
+ """
+
+ if not CARDS_TO_SETS:
+ populate_lookup_dicts()
+
+ return CARDS_TO_SETS[card]
+
+
+def set2names(set_name: str) -> list[str]:
+ """Return a list of all card in a set
+
+ :param set_name: the set name
+ :returns: a list of all cards in the set
+ """
+
+ if not SETS_TO_CARDS:
+ populate_lookup_dicts()
+
+ return SETS_TO_CARDS[set_name]
+
+
+def name2file(card: str) -> str:
+ """Return the file name of a card
+
+ File names are lower case card names with '_' instead of whitespace.
+
+ :param card: the english name of a card
+ :returns: the file name of the card
+ """
+
+ return card.lower().replace(' ', '_')
+
+
+def name2cardlisting(card: str) -> str:
+ """Return the card listing target
+
+ The returned target can be used to directly navigate the
+ card listing to the specific card.
+
+ Card listing targets are all lower case and use '-' instead of
+ whitespace.
+ Ending '!' are stripped from the card names.
+
+ :param card: the english name of a card
+ :returns: the card listing target
+ """
+
+ return card.lower().replace(' ', '-').replace('!', '')