aboutsummaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-01 15:10:54 -0400
committerYour Name <you@example.com>2021-05-01 15:10:54 -0400
commit7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d (patch)
treed9b808542216f71dbab053ad23145903e96c6401 /parser
parent5a813a75412ac9b8fadb90c9abd46dd95aee8e9b (diff)
downloaddmtool-7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d.tar.gz
dmtool-7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d.tar.bz2
dmtool-7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d.zip
Added bash completion, amongst others
Diffstat (limited to 'parser')
-rwxr-xr-xparser/scrapeToJson.py25
-rwxr-xr-xparser/utils.py12
2 files changed, 22 insertions, 15 deletions
diff --git a/parser/scrapeToJson.py b/parser/scrapeToJson.py
index 3310f2d..fd8403d 100755
--- a/parser/scrapeToJson.py
+++ b/parser/scrapeToJson.py
@@ -75,7 +75,7 @@ def processMonster(data, weapons, armors, spells):
bonus = armorDict['ac']
typ = armorDict['armor_type']
#desc['inventory'].append(armorDict)
- desc['inventory'].append({'name': a, 'type': 'armor', 'text': '{} armor'.format(a)})
+ desc['inventory'].append({'entry': 'item', 'name': a, 'type': 'armor', 'text': '{} armor'.format(a)})
break
if not found:
print('Cound not identify armor: {}'.format(a))
@@ -141,6 +141,7 @@ def processMonster(data, weapons, armors, spells):
desc['saves'].append(ability)
for action in desc['features']:
if re.match('.*Attack:', action['text']):
+ action['type'] = 'attack'
#toHit = int(re.search('\+(\d+) to hit', action['text']).group(1))
#selectedAbility = None
#for ability in ['str', 'dex', 'int', 'wis', 'cha', 'con']:
@@ -191,16 +192,20 @@ def processMonster(data, weapons, armors, spells):
else:
details['damage'].append(toAppend)
details['text'] = re.search('(?s)(_Hit:_ (?:\d+ [^\.]*\.)?)(.*)', action['text']).group(2).strip()
- if len(details['damage']) == 0:
- details['damage'].append({'dmg_die_count': 0, 'dmg_die_sides': 0, 'dmg_type': '-'})
+ # We may need to move some parts of the name to the text
+ if '(' in action['name']:
+ details['text'] = '(' + '('.join(action['name'].split('(')[1:]) + " " + details['text']
+ action['name'] = action['name'].split('(')[0].strip()
+ if action['name'][-1] == '.' or action['name'][-1] == ':':
+ action['name'] = action['name'][:-1].strip()
action['attack'] = {}
- for name, value in utils.formatWeapon(action['name'], details['range'][0], details['range'][1], details['reach'], details['damage'][0]['dmg_type'], details['damage'][0]['dmg_die_count'], details['damage'][0]['dmg_die_sides'], action['text']).items():
+ for name, value in utils.formatWeapon(action['name'], details['range'][0], details['range'][1], details['reach'], details['damage'], details['text']).items():
action['attack'][name] = value
if action['attack']['weapon_type'] != 'unknown':
#desc['inventory'].append(action['attack'])
- desc['inventory'].append({'name': action['attack']['name'], 'type': 'weapon', 'text': action['text']})
+ desc['inventory'].append({'entry': 'item', 'name': action['attack']['name'], 'type': 'weapons', 'text': action['text']})
elif 'spellcasting' in action['name']:
- action['type'] = 'spellcasting'
+ action['type'] = 'spells'
#print('{} has spellcasting!'.format(desc['name']))
abilities = ['Intelligence', 'Wisdom', 'Charisma']
for ability in abilities:
@@ -281,14 +286,14 @@ def dumpStuff(stuff, destDir):
with open(destDir + '/' + thing['name'].replace(' ', '_').replace('/', '') + '.json', 'w') as f:
json.dump(thing, f, indent=2)
-dumpStuff(weapons, 'parsed/items/weapons/')
-dumpStuff(armors, 'parsed/items/armor/')
+dumpStuff(weapons, 'parsed/weapons/')
+dumpStuff(armors, 'parsed/armor/')
dumpStuff(spells, 'parsed/spells/')
for monster in Path(utils.docsLoc + '/gamemaster_rules/monsters/').glob('*.md'):
#print('Processing {}'.format(monster))
with monster.open() as f:
data = f.read()
- Path('parsed/monsters/').mkdir(exist_ok=True)
- with open('parsed/monsters/' + monster.stem + '.json', 'w') as f:
+ Path('parsed/creatures/').mkdir(exist_ok=True)
+ with open('parsed/creatures/' + monster.stem + '.json', 'w') as f:
json.dump(processMonster(data, weapons, armors, spells), f, indent=2)
diff --git a/parser/utils.py b/parser/utils.py
index 34f8af2..34649ca 100755
--- a/parser/utils.py
+++ b/parser/utils.py
@@ -119,7 +119,7 @@ def getWeapons():
name = parts[1] + ' ' + parts[0]
if weapon[2] == '-':
weapon[2] = '0d0 -'
- damage = {'dmg_type': weapon[2].split(' ')[1]}
+ damage = {'dmg_type': weapon[2].split(' ')[1], 'is_or': False}
if 'd' in weapon[2].split(' ')[0]:
damage['dmg_die_count'] = int(weapon[2].split('d')[0])
damage['dmg_die_sides'] = int(weapon[2].split(' ')[0].split('d')[1])
@@ -143,15 +143,17 @@ def getWeapons():
reach += 5
if name in special:
proporties.append(special[name])
- weapons.append({'entry': 'item', 'type': 'weapon', 'name': name, 'cost': cost2copper(weapon[1]), 'damage': damage, 'weight': float(Fraction(weapon[3].split(' ')[0].replace('-', '0'))), 'range': rang, 'reach': reach, 'properties': proporties, 'weapon_type': header, 'text': 'Provided from PHB'})
+ weapons.append(formatWeapon(name, rang[0], rang[1], reach, [damage], 'Provided from PHB', {'cost': cost2copper(weapon[1]), 'weight': float(Fraction(weapon[3].split(' ')[0].replace('-', '0'))), 'properties': proporties, 'weapon_type': header}))
return weapons
-def formatWeapon(name, rangeShort, rangeLong, reach, dmgType, dmgCount, dmgSides, text):
- baseWeapon = {'cost': 0, 'weight': 0.0, 'properties': [], 'weapon_type': 'unknown'}
+# damage is formatted {'dmg_die_count': ddc, 'dmg_die_sides': dds, 'dmg_type': dt, 'is_or': bool}
+def formatWeapon(name, rangeShort, rangeLong, reach, damage, text, baseWeapon = {'cost': -1, 'weight': -1.0, 'properties': [], 'weapon_type': 'unknown'}):
for weapon in weapons:
if weapon['name'] == name:
baseWeapon = weapon
- return {'name': name, 'type': 'weapon', 'cost': baseWeapon['cost'], 'damage': {'dmg_type': dmgType, 'dmg_die_count': dmgCount, 'dmg_die_sides': dmgSides}, 'weight': baseWeapon['weight'], 'range': [rangeShort, rangeLong], 'reach': reach, 'properties': baseWeapon['properties'], 'weapon_type': baseWeapon['weapon_type'], 'text': text}
+ for dmg in damage:
+ assert 'dmg_die_count' in dmg and 'dmg_die_sides' in dmg and 'dmg_type' in dmg and 'is_or' in dmg
+ return {'entry': 'item', 'type': 'weapons', 'name': name, 'cost': baseWeapon['cost'], 'damage': damage, 'weight': baseWeapon['weight'], 'range': [rangeShort, rangeLong], 'reach': reach, 'properties': baseWeapon['properties'], 'weapon_type': baseWeapon['weapon_type'], 'text': text}
spells = []
def getSpells():