Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions scripts/generateMonsters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,29 @@ def get_monster_data():
return monsters


def validate_array_value(value):
if not value or value == ['None'] or value == ['N/A']:
return None
return value

def parse_max_hits(max_hits):
if not isinstance(max_hits, list):
return 0

hits = []
for hit in max_hits:
# Max hits can sometimes have multiple values separated by <br> or <br/>, so split them
parsed = [h.strip() for h in re.split(r'<br/?>', hit)]
hits.extend(parsed)

return hits if hits else 0

def get_printout_value(prop, all_results=False):
# SMW printouts are all arrays, so ensure that the array is not empty
if not prop:
return None
else:
return prop if all_results else prop[0]
return validate_array_value(prop) if all_results else prop[0]


def has_category(category_array, category):
Expand Down Expand Up @@ -144,8 +161,6 @@ def main():
continue

monster_style = get_printout_value(po['Attack style'], True)
if monster_style == 'None' or monster_style == 'N/A':
monster_style = None

burn_immunity = get_printout_value(po['Immune to burn'])
if burn_immunity:
Expand All @@ -172,7 +187,7 @@ def main():
'speed': get_printout_value(po['Attack speed']) or 0,
'style': monster_style,
'size': get_printout_value(po['Size']) or 0,
'max_hit': get_printout_value(po['Max hit']) or 0,
'max_hit': parse_max_hits(get_printout_value(po['Max hit'], True) or 0),
'skills': {
'atk': get_printout_value(po['Attack level']) or 0,
'def': get_printout_value(po['Defence level']) or 0,
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Monsters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import monsters from '../../cdn/json/monsters.json';

export function getMonsters(): Omit<Monster, 'inputs'>[] {
return monsters.map((m): Omit<Monster, 'inputs'> => {
const maxHit = parseInt(m.max_hit.toString());
const maxHit = Array.isArray(m.max_hit)
? Math.max(...m.max_hit.map((hit) => parseInt(hit) || 0))
: parseInt(m.max_hit.toString());
const styleStr = m.style?.join(',').toLowerCase() || null;
return {
id: m.id,
Expand Down