Difference between revisions of "Ability/Script"
From Wildermyth Wiki
< Ability
(Created page with "This is a [https://www.python.org/downloads/ Python] script to generate the Ability tables. Copy the code in the box below into a text file named '''<nowiki>abilityTable.p...") |
|||
| Line 96: | Line 96: | ||
break | break | ||
return string | return string | ||
linkwords = [ | |||
'Bonus Damage', | |||
'Potency', | |||
'Stunt Chance', | |||
'Temp Health', | |||
'Temporary Health', | |||
'Armor', | |||
'Warding', | |||
'Dodge', | |||
'Block', | |||
'Speed', | |||
'Recovery Rate', | |||
'Retirement Age', | |||
'Grayplane', | |||
'bonus damage', | |||
'spell damage', | |||
'armor', | |||
'warding', | |||
'dodge', | |||
'block', | |||
'augment', | |||
'grayplane', | |||
] | |||
def parse(blurb): | def parse(blurb): | ||
| Line 107: | Line 131: | ||
out = out.replace('<name>','Hero') | out = out.replace('<name>','Hero') | ||
out = re.sub(r'\<int.*?\>', 'x', out) | out = re.sub(r'\<int:(.*?)\>', 'x', out) | ||
out = re.sub(r'\<float.*?\>', 'x', out) | out = re.sub(r'\<float:(.*?)\>', 'x', out) | ||
out = re.sub(r'\<mf:.*?/.*?/(.*?)\>', '\g<1>', out) | out = re.sub(r'\<mf:.*?/.*?/(.*?)\>', '\g<1>', out) | ||
out = re.sub(r'\[:statusEffect\.(.*?)\](.*?)\[\]', '[[\g<1>|\g<2>]]', out) | out = re.sub(r'\[:statusEffect\.(.*?)\](.*?)\[\]', '[[\g<1>|\g<2>]]', out) | ||
out = re.sub(r'\[statusEffect:(.*?)\](.*?)\[\]', '[[\g<1>|\g<2>]]', out) | out = re.sub(r'\[statusEffect:(.*?)\](.*?)\[\]', '[[\g<1>|\g<2>]]', out) | ||
| Line 122: | Line 144: | ||
out = out.replace('\\n','<br />') | out = out.replace('\\n','<br />') | ||
for word in linkwords: | |||
out = out.replace(word,'[[%s]]'%word) | |||
return out | return out | ||
| Line 160: | Line 172: | ||
reqname = reqname.replace('(','') | reqname = reqname.replace('(','') | ||
reqname = reqname.replace(')','') | reqname = reqname.replace(')','') | ||
requirements += ['[[%s]]'%reqname] | requirements += ['[[%s|%s]]'%(reqname,aspectNames[req])] | ||
string += '| %s\n'%(', '.join(requirements)) | string += '| %s\n'%(', '.join(requirements)) | ||
string += '| %s\n|-\n'%parse(blurb) | string += '| %s\n|-\n'%parse(blurb) | ||
Revision as of 02:49, 5 March 2022
This is a Python script to generate the Ability tables. Copy the code in the box below into a text file named abilityTable.py (or whatever you want) inside the Wildermyth directory. Then run it by calling python abilityTable.py from the command line. It will create a text file named abilityTable.txt with the appropriate wiki-formatted content.
| abilityTable.py |
import json
from glob import glob
import re
directory = 'assets/data/aspects'
text_file = 'assets/text/aspects/aspects.properties'
aspectNames = {}
aspectBlurbs = {}
with open(text_file,'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 and key_split[-1] == 'name':
aspectNames[key_split[0]] = val[:-1]
elif len(key_split) == 2 and key_split[-1] == 'blurb':
aspectBlurbs[key_split[0]] = val[:-1]
with open('version.txt','r',encoding='utf8') as f:
lines = f.readlines()
version = lines[0]
decks = {'common':[],'warrior':[],'hunter':[],'mystic':[],'upgrade':[]}
aspectfiles = glob(directory + '/*')
for file in aspectfiles:
with open(file) as f:
data = json.load(f)
for entry in data:
for deck in decks:
if entry.get('info', {}).get('abilityDeckUsage') == deck:
decks[deck] += [entry]
upgrades = []
for entry in decks['upgrade']:
upgradeFor = entry.get('info', {}).get('upgradeForAbility')
if upgradeFor is not None:
for deck in decks:
for base in decks[deck]:
if base['id'] == upgradeFor:
decks[deck] += [entry]
break
else:
continue
break
else:
upgrades += [entry]
else:
upgrades += [entry]
decks['upgrade'] = upgrades
for deck in decks:
decks[deck] = sorted(decks[deck], key=lambda d: aspectNames[d['id']])
deck_blurbs = {
'common':'=== General Abilities ===\nThese abilities are available to all heroes.\n',
'warrior':'=== Warrior Abilities ===\nThese abilities are only available to [[Warrior]]s.\n',
'hunter':'=== Hunter Abilities ===\nThese abilities are only available to [[Hunter]]s.\n',
'mystic':'=== Mystic Abilities ===\nThese abilities are only available to [[Mystic]]s.\n',
'upgrade':'=== Theme Upgrades ===\nThese upgrades require specific [[theme]]s.',
}
string = ''
def replace_tag(tag,new,string):
while True:
start = string.find('[%s]'%tag)
if start < 0:
break
num = 1
for j in re.finditer(r'\[.*?\]',string[start+len(tag)+2:]):
tag_ = string[start+len(tag)+2+j.start():start+len(tag)+2+j.end()][1:-1]
if tag_ not in ['',tag]:
num += 1
else:
num -= 1
if num == 0:
end = start+len(tag)+2+j.end()
string = string[:start] + new + string[start+len(tag)+2:end-2-len(tag_)] + new + string[end:]
break
return string
linkwords = [
'Bonus Damage',
'Potency',
'Stunt Chance',
'Temp Health',
'Temporary Health',
'Armor',
'Warding',
'Dodge',
'Block',
'Speed',
'Recovery Rate',
'Retirement Age',
'Grayplane',
'bonus damage',
'spell damage',
'armor',
'warding',
'dodge',
'block',
'augment',
'grayplane',
]
def parse(blurb):
out = blurb
out = replace_tag('b',"'''",out)
out = replace_tag('blue',"",out)
out = replace_tag('gray',"",out)
out = out.replace('<self>','Hero')
out = out.replace('<name>','Hero')
out = re.sub(r'\<int:(.*?)\>', 'x', out)
out = re.sub(r'\<float:(.*?)\>', 'x', out)
out = re.sub(r'\<mf:.*?/.*?/(.*?)\>', '\g<1>', out)
out = re.sub(r'\[:statusEffect\.(.*?)\](.*?)\[\]', '[[\g<1>|\g<2>]]', out)
out = re.sub(r'\[statusEffect:(.*?)\](.*?)\[\]', '[[\g<1>|\g<2>]]', out)
out = re.sub(r'\<self\..*?:.*?[^<]/(.*?)\>', '\g<1>', out)
out = re.sub(r'\<self\..*?:.*?\>', '', out)
out = re.sub(r'\<test:.*?:(.*?[^<])/.*?\>', '\g<1>', out)
out = re.sub(r'\<test:.*?:.*?\>', '', out)
out = re.sub(r'\(Current.*?\)', '', out)
out = out.replace('\\n','<br />')
for word in linkwords:
out = out.replace(word,'[[%s]]'%word)
return out
for deck in decks:
string += deck_blurbs[deck]
if deck != 'upgrade':
string += '\n{| class="wikitable"\n! Name\n! Description\n|-\n'
else:
string += '\n{| class="wikitable sortable"\n! Name\n! Requires one of\n! Description\n|-\n'
for entry in decks[deck]:
name = aspectNames[entry['id']]
blurb = aspectBlurbs[entry['id']]
if name[-1] == '+':
nameStr = '[[' + name[:-1] + ']]+'
else:
nameStr = '[[' + name + ']]'
nameStr = nameStr.replace('/',']]/[[')
string += '| %s\n'%(nameStr)
if deck == 'upgrade':
requirements = []
for req in entry.get('abilityRequiresOneAspectOf'):
reqname = aspectNames[req]
reqname = reqname.replace('(','')
reqname = reqname.replace(')','')
requirements += ['[[%s|%s]]'%(reqname,aspectNames[req])]
string += '| %s\n'%(', '.join(requirements))
string += '| %s\n|-\n'%parse(blurb)
string += '|}\n\n'
string += '<small>Last updated [[%s]] using [[/Script|this script]].</small>\n'%version[:-1]
with open('abilityTable.txt', 'w') as f:
f.write(string)
|