fix #4; linking call on ancient blood to its heritage

merge-requests/45/head^2
James Miller 2020-04-28 17:58:28 -05:00
parent 8c0d75353f
commit 6bd325b08c
2 changed files with 41 additions and 9 deletions

View File

@ -150,6 +150,7 @@ def main():
data = yaml.full_load(yl) data = yaml.full_load(yl)
do_ancestries(data, conn) do_ancestries(data, conn)
# Must be called after feats are loaded
with open('ancestriesheritages.yaml') as yl: with open('ancestriesheritages.yaml') as yl:
data = yaml.full_load(yl) data = yaml.full_load(yl)
do_heritages(data, conn) do_heritages(data, conn)
@ -459,7 +460,7 @@ def get_actioncost_id_by_name(ac, conn):
def do_heritages(data, conn): def do_heritages(data, conn):
table = """ table = """
CREATE TABLE heritages ( CREATE TABLE heritage (
heritage_id INTEGER PRIMARY KEY, heritage_id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE, name TEXT NOT NULL UNIQUE,
descr TEXT NOT NULL, descr TEXT NOT NULL,
@ -471,6 +472,19 @@ def do_heritages(data, conn):
c = conn.cursor() c = conn.cursor()
c.execute(table) c.execute(table)
table = """
CREATE TABLE heritage_feat (
id INTEGER PRIMARY KEY,
heritage_id INTEGER NOT NULL,
feat_id INTEGER NOT NULL,
FOREIGN KEY (heritage_id) REFERENCES heritage(heritage_id),
FOREIGN KEY (feat_id) REFERENCES feat(feat_id)
);
"""
c = conn.cursor()
c.execute(table)
for i in data['ancestries']: for i in data['ancestries']:
#GET ID OF ANCESTRY #GET ID OF ANCESTRY
stmt = "SELECT ancestry_id FROM ancestries WHERE name=?;" stmt = "SELECT ancestry_id FROM ancestries WHERE name=?;"
@ -479,14 +493,32 @@ def do_heritages(data, conn):
#FOR EACH HERITAGE, INSERT INTO TABLE USING ANCESTRY ID #FOR EACH HERITAGE, INSERT INTO TABLE USING ANCESTRY ID
for j in i['heritages']: for j in i['heritages']:
# print("doing this heritage: {}".format(j['name'])) # print("doing this heritage: {}".format(j['name']))
stmt = "INSERT INTO heritages (name, descr, ancestry_id) VALUES (?,?,?);" stmt = "INSERT INTO heritage (name, descr, ancestry_id) VALUES (?,?,?);"
try:
c.execute(stmt, (j['name'], j['descr'], rowid[0])) c.execute(stmt, (j['name'], j['descr'], rowid[0]))
except sqlite3.Error as e:
print("Error inserting a heritage: {}".format(e))
except:
print("Error inserting a heritage other than sqlite3 error")
else:
conn.commit() conn.commit()
if j['feat'] != None: if j['feat'] != None:
print("We have a feat that is not equal to none: {}".format(j['feat'])) # print("We have a feat that is not equal to none: {}".format(j['feat']))
print("TODO THIS NEEDS TO GET DONE AFTER FEATS ARE IN SQL") stmt = """INSERT INTO heritage_feat
# i.e. TODO select feat_id where name = j['feat] then insert into a heritages_feats table (heritage_id, feat_id)
VALUES (
(SELECT heritage_id FROM heritage WHERE name=?),
(SELECT feat_id FROM feat WHERE name=?)
);"""
try:
c.execute(stmt, (j['name'],j['feat']))
except sqlite3.Error as e:
print("Error linking a heritage to its feat: {}".format(e))
except:
print("Error linking a heritage something other than sqlite3 error")
else:
conn.commit()
def do_ancestries(data, conn): def do_ancestries(data, conn):

View File

@ -336,7 +336,7 @@ spell:
descr: "You draw upon your muse to soothe your allies. Choose one of the following\ descr: "You draw upon your muse to soothe your allies. Choose one of the following\
\ three effects:\n The spell attempts to counteract fear effects on the targets.\ \ three effects:\n The spell attempts to counteract fear effects on the targets.\
\ \n The spell attempts to counteract effects imposing paralysis on the targets.\ \ \n The spell attempts to counteract effects imposing paralysis on the targets.\
\ \n The spell restores 7d8 Hit Points to the targets. \n\n**Heightened (+1)** \ \ \n The spell restores 7d8 Hit Points to the targets. \n\n**Heightened (+1)**\
\ When used to heal, soothing ballad restores 1d8 more Hit Points." \ When used to heal, soothing ballad restores 1d8 more Hit Points."
duration: null duration: null
has_been_manually_proofread: true has_been_manually_proofread: true