Files
aoe2-flashcard-creator/decks/basic-unit-costs.py
Nate Bowman d83e7e8e09 Allow creating decks by supplying functions
This reduces the boilerplate code that the user needs to deal with in
the deck-creation scripts.
2026-10-04 02:59:40 -04:00

34 lines
979 B
Python

from flashcards.decks import create_deck_from_functions
from flashcards.maps import create_maps, read_data_to_dict
# your choice of deck name and filename
deck_name = 'Unit Costs'
deck_fname = 'unit-costs'
# specify the namelist to be used to create the deck
# give the relative path of the file from config.namelists_dir
namelist = 'base-units.txt'
# key into json file specifying which data you want
# uncomment either 'units_buildings' or 'techs'
data_json_key = 'units_buildings'
#data_json_key = 'techs'
def card_front(num, name, data):
return name
def card_back(num, name, data):
cost = data[num]['cost']
back = '\n'.join([f'{res}: {val}' for res, val in cost.items()
if val != 0])
return back
create_deck_from_functions(namelist,
data_json_key,
card_front,
card_back,
deck_name,
deck_fname)