Add examples of deck scripts and namelists
This commit is contained in:
44
decks/fighting-non-unique-units.py
Normal file
44
decks/fighting-non-unique-units.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from flashcards.decks import create_deck
|
||||
from fighting.fighting import Fighting
|
||||
from flashcards.maps import (create_maps,
|
||||
read_data_to_dict)
|
||||
|
||||
|
||||
|
||||
# your choice of deck name and filename
|
||||
deck_name = 'Fighting (Units, Non-Unique)'
|
||||
deck_fname = 'fighting-non-unique-units'
|
||||
|
||||
# specify the namelist to be used to create the deck
|
||||
# give the relative path of the file from config.namelists_dir
|
||||
namelist = 'units-non-unique.txt'
|
||||
|
||||
# key into json file specifying which data you want
|
||||
name_json_keys = 'units_buildings'
|
||||
data_json_keys = ('data', 'Unit')
|
||||
|
||||
# --- create list of notes ---
|
||||
|
||||
_, nums = create_maps(namelist, name_json_keys)
|
||||
data = read_data_to_dict(data_json_keys)
|
||||
|
||||
fight = Fighting(data, nums)
|
||||
results = fight.generate_all_fight_results()
|
||||
|
||||
# create cards based on data and maps
|
||||
notes = []
|
||||
for k, v in results.items():
|
||||
attacker, defender = k
|
||||
title = f'{attacker} attacking {defender}'
|
||||
|
||||
for fight in v:
|
||||
front = '\n'.join([title, fight['notes']])
|
||||
|
||||
hits = [f'{bonus}: {hit}' for bonus, hit in fight['hits'].items()]
|
||||
back = '\n'.join(hits)
|
||||
|
||||
notes.append((front, back))
|
||||
#print(f'front: {front}\tback: {back}')
|
||||
|
||||
# write deck to .apkg file
|
||||
deck = create_deck(notes, deck_name, deck_fname)
|
||||
Reference in New Issue
Block a user