Difference between revisions of "User:Sten/Legacy to spreadsheet"
From Wildermyth Wiki
m (Sten moved page Sten/Legacy to spreadsheet to User:Sten/Legacy to spreadsheet) |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[ | This is a [https://www.python.org/downloads/ Python] script to export a player's legacy into a spreadsheet. You need a Python installation to run it. | ||
==Usage== | |||
Copy the code in the box below into a text file named '''<nowiki>legacy_table.py</nowiki>''' (or whatever you want) inside the '''<nowiki>Wildermyth/Players/<player ID></nowiki>''' directory. Then run it by calling '''<nowiki>python legacy_table.py</nowiki>''' from the command line. It will create a text file called '''<nowiki>legacy_table.txt</nowiki>''', which is tab-delimited and can be loaded by any spreadsheet software or viewed in a text editor. | |||
{| role="presentation" class="wikitable mw-collapsible mw-collapsed" | {| role="presentation" class="wikitable mw-collapsible mw-collapsed" | ||
Line 11: | Line 13: | ||
from glob import glob | from glob import glob | ||
mod_paths = ['../..'] + glob('../../mods/builtIn/*') | mod_paths = ['../..'] + glob('../../mods/builtIn/*') + glob('../../mods/user/*') + glob('../../../../workshop/content/763890/*') | ||
dictionary = {} | dictionary = {} | ||
Line 42: | Line 44: | ||
if string.startswith(prefix+suffix): | if string.startswith(prefix+suffix): | ||
return True | return True | ||
if string.startswith('theme') and '_upgrade' in string: | |||
return True | |||
return False | return False | ||
Line 52: | Line 56: | ||
names = [] | names = [] | ||
tiers = [] | tiers = [] | ||
classes = [] | |||
themes = [] | themes = [] | ||
playables = [] | playables = [] | ||
hooks = [] | hooks = [] | ||
abilities = [] | abilities = [] | ||
for entry in data['entries']: | weapons = [] | ||
offhands = [] | |||
for i_entry, entry in enumerate(data['entries']): | |||
hook = 0 | hook = 0 | ||
themes_ = [] | themes_ = [] | ||
abilities_ = [] | abilities_ = [] | ||
class_ = '' | |||
weapons_ = [] | |||
offhand = '' | |||
try: | try: | ||
tier = int(entry['tier'])+1 | tier = int(entry['tier'])+1 | ||
Line 73: | Line 83: | ||
entities = entry['snapshots'][snapshot]['entities'] | entities = entry['snapshots'][snapshot]['entities'] | ||
for j in range(len(entities)): | for j in range(len(entities)): | ||
if 'individual' in entities[j]: | |||
name = entities[j][ | for i in range(len(entities[j])): | ||
if entities[j][i] == 'status': | |||
name = entities[j][i+1]['name'] | |||
print('reading entry %d: %s'%(i_entry,name)) | |||
for entry_ in entities[j][i+1]['aspects']['entries']: | |||
if entry_[0] in ['hunter','warrior','mystic'] and entry_[1]['value'] == 1: | |||
class_ = entry_[0] | |||
elif entry_[0].startswith('themePiece_') and entry_[1]['value'] == 1: | |||
try: | |||
theme = dictionary[entry_[0]] | |||
except: | |||
theme = entry_[0] | |||
themes_ += [theme] | |||
elif entry_[0].startswith('hookResolved_retirementAgeBoost') and entry_[1]['value'] == 1: | |||
hook += 1 | |||
elif test_ability(entry_[0]) and entry_[1]['value'] == 1: | |||
try: | |||
ability = dictionary[entry_[0]] | |||
except: | |||
ability = entry_[0] | |||
abilities_ += [ability] | |||
elif 'item' in entities[j]: | |||
for i in range(len(entities[j])): | |||
if entities[j][i] == 'status': | |||
itemName = entities[j][i+1]['name'] | |||
itemID = entities[j][i+1]['localizableName'].split('.')[-1] | |||
elif entities[j][i] == 'item': | |||
if 'MAIN_HAND' in entities[j][i+1]['slots']: | |||
try: | |||
if entities[j][i+1]['artifact']: | |||
weapons_ += [itemName] | |||
else: | |||
raise | |||
except: | |||
weapons_ += [itemID] | |||
elif 'OFF_HAND' in entities[j][i+1]['slots'] and 'MAIN_HAND' not in entities[j][i+1]['slots']: | |||
offhand = itemName | |||
names += [name] | names += [name] | ||
tiers += [tier] | tiers += [tier] | ||
classes += [class_] | |||
playables += [playable] | playables += [playable] | ||
themes += [themes_] | themes += [themes_] | ||
abilities += [abilities_] | abilities += [abilities_] | ||
hooks += [hook] | hooks += [hook] | ||
weapons += [weapons_] | weapons += [weapons_] | ||
offhands += [offhand] | offhands += [offhand] | ||
with open('legacy_table.txt', 'w') as f: | with open('legacy_table.txt', 'w') as f: | ||
f.write('Name\tPlayable\tTier\tHooks\tThemes\tWeapons\tOffhand\tAbilities\n') | f.write('Name\tPlayable\tTier\tClass\tHooks\tThemes\tWeapons\tOffhand\tAbilities\n') | ||
for i,name in enumerate(names): | for i,name in enumerate(names): | ||
f.write('%s\t%s\t%d\t%d\t'%(name,playables[i],tiers[i],hooks[i]) + ', '.join(themes[i]) + '\t' + ', '.join(weapons[i]) + '\t' + offhands[i] + '\t' + ', '.join(abilities[i]) + '\n')</nowiki> | f.write('%s\t%s\t%d\t%s\t%d\t'%(name,playables[i],tiers[i],classes[i],hooks[i]) + ', '.join(themes[i]) + '\t' + ', '.join(weapons[i]) + '\t' + offhands[i] + '\t' + ', '.join(abilities[i]) + '\n') | ||
print('Done. Press ENTER to close.\n') | |||
input()</nowiki> | |||
|} | |} | ||
==Output== | |||
'''This script does ''not'' make any changes to the legacy.''' | '''This script does ''not'' make any changes to the legacy.''' | ||
The following fields appear in the output table: | The following fields appear in the output table ('''<nowiki>legacy_table.txt</nowiki>'''): | ||
* Name | * Name | ||
* Playable (Y/N) | * Playable (Y/N) | ||
* Legacy tier | * Legacy tier | ||
* Class | |||
* Number of hooks resolved | * Number of hooks resolved | ||
* Themes | * Themes | ||
* Weapons | * Weapons | ||
* Offhand | * Offhand item | ||
* Abilities | * Abilities | ||
==Example== | |||
[[File:Legacy_table.png|frame|none|alt=Example image|Example legacy export, viewed in Microsoft Excel]] |
Latest revision as of 03:05, 23 March 2022
This is a Python script to export a player's legacy into a spreadsheet. You need a Python installation to run it.
Usage
Copy the code in the box below into a text file named legacy_table.py (or whatever you want) inside the Wildermyth/Players/<player ID> directory. Then run it by calling python legacy_table.py from the command line. It will create a text file called legacy_table.txt, which is tab-delimited and can be loaded by any spreadsheet software or viewed in a text editor.
legacy_table.py |
import json from zipfile import ZipFile from glob import glob mod_paths = ['../..'] + glob('../../mods/builtIn/*') + glob('../../mods/user/*') + glob('../../../../workshop/content/763890/*') dictionary = {} for m in mod_paths: try: with open(m + '/assets/text/aspects/aspects.properties','r',encoding='utf8') as f: lines = f.readlines() for line in lines: if line[0] == '#': continue try: key,val = line.split('=') except: continue try: key_split = key.split('.') except: continue if len(key_split) != 2 or key_split[-1] != 'name': continue dictionary[key_split[0]] = val[:-1] except: continue def test_ability(string): if string in ['hunterGreenhorn_silkstep']: return False for prefix in ['mystic','hunter','warrior','common']: for suffix in ['Deck','Special','Greenhorn','Goldhorn']: if string.startswith(prefix+suffix): return True if string.startswith('theme') and '_upgrade' in string: return True return False snapshot = -1 with ZipFile('legacy.json.zip') as zf: with zf.open('legacy.json') as f: data = json.load(f) names = [] tiers = [] classes = [] themes = [] playables = [] hooks = [] abilities = [] weapons = [] offhands = [] for i_entry, entry in enumerate(data['entries']): hook = 0 themes_ = [] abilities_ = [] class_ = '' weapons_ = [] offhand = '' try: tier = int(entry['tier'])+1 except: tier = 1 try: if entry['usage'] == 'background': playable = 'N' else: raise except: playable = 'Y' entities = entry['snapshots'][snapshot]['entities'] for j in range(len(entities)): if 'individual' in entities[j]: for i in range(len(entities[j])): if entities[j][i] == 'status': name = entities[j][i+1]['name'] print('reading entry %d: %s'%(i_entry,name)) for entry_ in entities[j][i+1]['aspects']['entries']: if entry_[0] in ['hunter','warrior','mystic'] and entry_[1]['value'] == 1: class_ = entry_[0] elif entry_[0].startswith('themePiece_') and entry_[1]['value'] == 1: try: theme = dictionary[entry_[0]] except: theme = entry_[0] themes_ += [theme] elif entry_[0].startswith('hookResolved_retirementAgeBoost') and entry_[1]['value'] == 1: hook += 1 elif test_ability(entry_[0]) and entry_[1]['value'] == 1: try: ability = dictionary[entry_[0]] except: ability = entry_[0] abilities_ += [ability] elif 'item' in entities[j]: for i in range(len(entities[j])): if entities[j][i] == 'status': itemName = entities[j][i+1]['name'] itemID = entities[j][i+1]['localizableName'].split('.')[-1] elif entities[j][i] == 'item': if 'MAIN_HAND' in entities[j][i+1]['slots']: try: if entities[j][i+1]['artifact']: weapons_ += [itemName] else: raise except: weapons_ += [itemID] elif 'OFF_HAND' in entities[j][i+1]['slots'] and 'MAIN_HAND' not in entities[j][i+1]['slots']: offhand = itemName names += [name] tiers += [tier] classes += [class_] playables += [playable] themes += [themes_] abilities += [abilities_] hooks += [hook] weapons += [weapons_] offhands += [offhand] with open('legacy_table.txt', 'w') as f: f.write('Name\tPlayable\tTier\tClass\tHooks\tThemes\tWeapons\tOffhand\tAbilities\n') for i,name in enumerate(names): f.write('%s\t%s\t%d\t%s\t%d\t'%(name,playables[i],tiers[i],classes[i],hooks[i]) + ', '.join(themes[i]) + '\t' + ', '.join(weapons[i]) + '\t' + offhands[i] + '\t' + ', '.join(abilities[i]) + '\n') print('Done. Press ENTER to close.\n') input() |
Output
This script does not make any changes to the legacy.
The following fields appear in the output table (legacy_table.txt):
- Name
- Playable (Y/N)
- Legacy tier
- Class
- Number of hooks resolved
- Themes
- Weapons
- Offhand item
- Abilities