update spells.py to fix actioncosts, add various action costs, fix components on heal an dharm

merge-requests/34/merge
James Miller 2019-08-16 12:00:04 -05:00
parent fb9e351514
commit b9aaa6dc2e
2 changed files with 22 additions and 3 deletions

View File

@ -9,6 +9,7 @@ INSERT INTO actioncosts (
abbr
)
VALUES
(0, 'Varies', 'Varies'),
(1, 'Single Action', '1'),
(2, 'Two Actions', '2'),
(3, 'Three Actions', '3'),

View File

@ -1,11 +1,12 @@
import json
import sqlite3
import io
def main():
# load json into python
print("loading json")
## read file into memory
with open('spells.json') as f:
with io.open('spellsNEW.json', 'r', encoding='utf-8-sig') as f:
# raw_data = f.read()
data = json.load(f)
print("Importing {} spells.".format(len(data)))
@ -145,12 +146,29 @@ def do_spell_actions(i,id,conn,acttypes):
try:
conn.execute(stmt, inp)
except:
print("Error updating actioncosts_id")
except sqlite3.Error as e:
print("Error updating actioncosts_id: {}".format(e))
print("\tSpell:{}\tinp:{}".format(i['name'],inp))
else:
conn.commit()
def do_spell_components(i,id,conn,ctypes):
# this block handles heal or harm which have all 3
if i['name']=='Heal' or i['name']=='Harm':
# print("Need to handle heal and harm")
inp = [(id, 1), (id, 2), (id, 3)]
stmt = "INSERT INTO spells_spellcomponents (spells_id, spellcomponents_id) VALUES (?,?)"
try:
conn.executemany(stmt, inp)
except sqlite3.Error as e:
print("Error inserting spell components: {}".format(e))
print("\tinp: {}".format(inp))
else:
print("handled {} succesfully".format(i['name']))
conn.commit()
return
# this handles the rest
res = None
for j in ctypes:
for k in i['components']: