Initial commit
This commit is contained in:
45
flashcards/create_full_namelists.py
Normal file
45
flashcards/create_full_namelists.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# run with `python -m flashcards.create_full_namelists`
|
||||
# Create two lists -- once for each high-level key in the data file
|
||||
# * units_buildings
|
||||
# * techs
|
||||
# The resulting lists will likely still have a lot of junk.
|
||||
# You will want to manually remove what you don't need before creating maps
|
||||
# from the lists.
|
||||
from flashcards.config import config
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
||||
def generate_namelist(big, key, namelist_fname):
|
||||
added = set()
|
||||
with open(namelist_fname, 'w') as f:
|
||||
for k, v in big[key].items():
|
||||
lname = v['localised_name'].strip()
|
||||
costs = sum([v for k, v in v['cost'].items()])
|
||||
# for some reason, "cost" of a civ "research" is 1
|
||||
#if lname.strip() != '' and costs != 0 and lname not in added:
|
||||
if lname.strip() != '' and costs > 1 and lname not in added:
|
||||
added.add(lname)
|
||||
f.write(lname + '\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
namelist_info = {
|
||||
'units_buildings': 'full-units-namelist.txt',
|
||||
'techs': 'full-research-namelist.txt',
|
||||
}
|
||||
|
||||
# Read in the full data dictionary
|
||||
with open(config.data_file, 'r') as f:
|
||||
big = json.load(f)
|
||||
|
||||
for key, fname in namelist_info.items():
|
||||
namelist_path = config.namelists_dir / fname
|
||||
|
||||
if not namelist_path.exists():
|
||||
# if the global namelist does not exist, create it and exit
|
||||
generate_namelist(big, key, namelist_path)
|
||||
else:
|
||||
print(f'File {namelist_path} already exists. Skipping.')
|
||||
Reference in New Issue
Block a user