User:Sten/Legacy to spreadsheet

From Wildermyth Wiki
< User:Sten
Revision as of 07:38, 15 February 2022 by Sten (talk | contribs) (Created page with "This is a Python script. Run it from the '''<nowiki>Wildermyth/Players/<player ID></nowiki>''' directory. It will create a text file called '''<nowiki>legacy_table.txt</nowiki...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is a Python script. Run it from the Wildermyth/Players/<player ID> directory. 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.

It does not make any changes to the legacy.

Fields that appear in the output table:

  • Name
  • Playable (Y/N)
  • Legacy tier
  • Number of hooks resolved
  • Themes
  • Weapons
  • Offhand items
  • Abilities
import json
from zipfile import ZipFile
from glob import glob

mod_paths = ['../..'] + glob('../../mods/builtIn/*')

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
  return False

snapshot = -1

with ZipFile('legacy.json.zip') as zf:
  with zf.open('legacy.json') as f:
    data = json.load(f)

names = []
tiers = []
themes = []
playables = []
hooks = []
abilities = []
for entry in data['entries']:
  hook = 0
  themes_ = []
  abilities_ = []
  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)):
    try:
      name = entities[j][6]['name']
    except:
      continue
    for entry_ in entities[j][6]['aspects']['entries']:
      if entry_[0].startswith('themePiece_') and entry_[1]['value'] == 1:
        themes_ += [dictionary[entry_[0]]]
      elif entry_[0].startswith('hookResolved_retirementAgeBoost') and entry_[1]['value'] == 1:
        hook += 1
      elif test_ability(entry_[0]) and entry_[1]['value'] == 1:
        abilities_ += [dictionary[entry_[0]]]
  names += [name]
  tiers += [tier]
  playables += [playable]
  themes += [themes_]
  abilities += [abilities_]
  hooks += [hook]

weapons = []
for entry in data['entries']:
  weapons_ = []
  entities = entry['snapshots'][snapshot]['entities']
  for j in range(len(entities)):
    try:
      if 'MAIN_HAND' in entities[j][6]['slots']:
        try:
          if entities[j][6]['artifact']:
            weapons_ += [entities[j][4]['name']]
          else:
            raise
        except:
          weapons_ += [entities[j][4]['localizableName'].split('.')[-1]]
    except:
      pass
  weapons += [weapons_]

offhands = []
for entry in data['entries']:
  offhand = ''
  entities = entry['snapshots'][snapshot]['entities']
  for j in range(len(entities)):
    try:
      if 'OFF_HAND' in entities[j][6]['slots'] and 'MAIN_HAND' not in entities[j][6]['slots']:
        offhand = entities[j][4]['name']
    except:
      pass
  offhands += [offhand]

with open('legacy_table.txt', 'w') as f:
  f.write('Name\tPlayable\tTier\tHooks\tThemes\tWeapons\tOffhand\tAbilities\n')
  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')