Add examples of deck scripts and namelists
This commit is contained in:
28
decks/building-costs.py
Normal file
28
decks/building-costs.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from flashcards.decks import create_deck_from_back_function
|
||||
|
||||
|
||||
|
||||
# your choice of deck name and filename
|
||||
deck_name = 'Building Costs'
|
||||
deck_fname = 'building-costs'
|
||||
|
||||
# specify the namelist to be used to create the deck
|
||||
# give the relative path of the file from config.namelists_dir
|
||||
namelist = 'buildings.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_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_back_function(namelist,
|
||||
data_json_key,
|
||||
card_back,
|
||||
deck_name,
|
||||
deck_fname)
|
||||
32
decks/building-times.py
Normal file
32
decks/building-times.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from flashcards.decks import create_deck
|
||||
from flashcards.maps import (create_name_to_lname_map,
|
||||
read_data_to_dict)
|
||||
|
||||
|
||||
|
||||
# your choice of deck name and filename
|
||||
deck_name = 'Building Times'
|
||||
deck_fname = 'building-times'
|
||||
|
||||
namelist = 'buildings.txt'
|
||||
|
||||
name_json_key = 'units_buildings'
|
||||
data_json_keys = ('data', 'Building',)
|
||||
|
||||
lnames = create_name_to_lname_map(namelist, name_json_key)
|
||||
data = read_data_to_dict(data_json_keys)
|
||||
|
||||
notes = []
|
||||
for v in data.values():
|
||||
name = v['internal_name']
|
||||
if name in lnames.keys():
|
||||
front = lnames[name]
|
||||
back = str(v['TrainTime'])
|
||||
notes.append((front, back))
|
||||
#print(front, back)
|
||||
else:
|
||||
print(f'missing: {name} --')
|
||||
print(v)
|
||||
print('\n\n')
|
||||
|
||||
deck = create_deck(notes, deck_name, deck_fname)
|
||||
54
decks/counters.py
Normal file
54
decks/counters.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from collections import defaultdict
|
||||
import json
|
||||
|
||||
from flashcards.config import config
|
||||
from flashcards.decks import create_deck
|
||||
from flashcards.maps import create_maps, read_name_data_to_dict
|
||||
|
||||
|
||||
|
||||
def generate_counter_list(counters):
|
||||
all_c_names = []
|
||||
for c_type in sorted(counters.keys()):
|
||||
c_names = '\n'.join(counters[c_type])
|
||||
if len(c_names) > 0:
|
||||
all_c_names.append(f'<b>{c_type}</b>:\n\n{c_names}')
|
||||
return '\n\n\n'.join(all_c_names)
|
||||
|
||||
|
||||
# your choice of deck name and filename
|
||||
deck_name = 'Counters'
|
||||
deck_fname = 'counters'
|
||||
|
||||
# --- create list of notes ---
|
||||
|
||||
# read in data
|
||||
with open(config.data_dir / 'counters.json', 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# determine countered_by from counters
|
||||
all_countered_by = defaultdict(lambda: defaultdict(list))
|
||||
for unit, counters in data.items():
|
||||
for counter_type in counters.keys(): # 'hard' or 'soft'
|
||||
for unit2 in counters[counter_type]:
|
||||
all_countered_by[unit2][counter_type].append(unit)
|
||||
|
||||
notes = []
|
||||
for unit in data.keys():
|
||||
# note: 'counters' contains units countered *by* 'unit'
|
||||
# note: 'countered_by' contains units that counter 'unit'
|
||||
counters = data[unit]
|
||||
countered_by = all_countered_by[unit]
|
||||
|
||||
front = f'{unit} is a counter against...'
|
||||
back = generate_counter_list(counters)
|
||||
notes.append((front, back))
|
||||
#print(f'front: {front}\tback: {back}')
|
||||
|
||||
front = f'{unit} is countered by...'
|
||||
back = generate_counter_list(countered_by)
|
||||
notes.append((front, back))
|
||||
#print(f'front: {front}\tback: {back}')
|
||||
|
||||
# write deck to .apkg file
|
||||
deck = create_deck(notes, deck_name, deck_fname)
|
||||
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)
|
||||
28
decks/units-times.py
Normal file
28
decks/units-times.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from flashcards.decks import create_deck
|
||||
from flashcards.maps import (create_name_to_lname_map,
|
||||
read_data_to_dict)
|
||||
|
||||
|
||||
|
||||
# your choice of deck name and filename
|
||||
deck_name = 'Unit Training Times'
|
||||
deck_fname = 'units-times'
|
||||
|
||||
namelist = 'units-non-unique.txt'
|
||||
|
||||
name_json_key = 'units_buildings'
|
||||
data_json_keys = ('data', 'Unit',)
|
||||
|
||||
lnames = create_name_to_lname_map(namelist, name_json_key)
|
||||
data = read_data_to_dict(data_json_keys)
|
||||
|
||||
notes = []
|
||||
for v in data.values():
|
||||
name = v['internal_name']
|
||||
if name in lnames.keys():
|
||||
front = lnames[name]
|
||||
back = str(v['TrainTime'])
|
||||
notes.append((front, back))
|
||||
#print(front, back)
|
||||
|
||||
deck = create_deck(notes, deck_name, deck_fname)
|
||||
40
decks/units-upgrades.py
Normal file
40
decks/units-upgrades.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from flashcards.decks import create_deck
|
||||
from flashcards.maps import (create_maps,
|
||||
read_data_to_dict)
|
||||
|
||||
|
||||
|
||||
# your choice of deck name and filename
|
||||
deck_name = 'Unit Upgrades'
|
||||
deck_fname = 'unit-upgrades'
|
||||
|
||||
# key into json file specifying which data you want
|
||||
data_json_keys = ('data', 'unit_upgrades',)
|
||||
|
||||
# --- create list of notes ---
|
||||
|
||||
data = read_data_to_dict(data_json_keys)
|
||||
|
||||
# create cards based on data and maps
|
||||
order = ['Wood', 'Food', 'Gold', 'Stone']
|
||||
notes = []
|
||||
completed = set()
|
||||
for d in data.values():
|
||||
front = d['internal_name']
|
||||
|
||||
if front not in completed:
|
||||
completed.add(front)
|
||||
|
||||
cost = d['Cost']
|
||||
all_cost = '\n'.join([f'{k}: {cost[k]}' for k in order
|
||||
if k in cost.keys() and cost[k] != 0])
|
||||
|
||||
time_text = f'Research time: {d["ResearchTime"]}'
|
||||
|
||||
back = '\n\n'.join([all_cost, time_text])
|
||||
|
||||
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