From 7d585f02f395a6e0e055ccb213eb01778ed25cc9 Mon Sep 17 00:00:00 2001 From: James Miller Date: Thu, 14 Nov 2019 00:05:59 -0600 Subject: [PATCH] Have actions YAML-SQL but still need to do actions_traits --- data/yaml/actions.yaml | 6 ++++ data/yaml/basics.yaml | 4 +-- data/yaml/gendb.py | 67 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/data/yaml/actions.yaml b/data/yaml/actions.yaml index cd458da..f49e24c 100644 --- a/data/yaml/actions.yaml +++ b/data/yaml/actions.yaml @@ -12,6 +12,7 @@ actioncategory: - abbr: CRB page_start: 472 page_stop: 472 +# NOTE: action assumes a single source entry action: - actioncategory: Basic actioncost_name: Free Action @@ -51,6 +52,7 @@ action: - Move trigger: null - actioncategory: Basic + actioncost_name: Free Action descr: You wait for the right moment to act. The rest of your turn doesn’t happen yet. Instead, you’re removed from the initiative order. You can return to the initiative order as a free action triggered by the end of any other creature’s @@ -125,6 +127,7 @@ action: - Manipulate trigger: null - actioncategory: Basic + actioncost_name: Varies descr: 'You invest your energy in an item with the invested trait as you don it. This process requires 1 or more Interact actions, usually taking the same amount of time it takes to don the item. Once you’ve Invested the Item, you benefit from @@ -184,6 +187,7 @@ action: - Concentrate trigger: null - actioncategory: Basic + actioncost_name: Free Action descr: You release something you’re holding in your hand or hands. This might mean dropping an item, removing one hand from your weapon while continuing to hold it in another hand, releasing a rope suspending a chandelier, or performing a @@ -333,6 +337,7 @@ action: trait: null trigger: null - actioncategory: Specialty Basic + actioncost_name: Varies descr: You call forth the effect of an item by properly activating it. This is a special activity that takes a variable number of actions, as listed in the item’s stat block.\n\nSome items can be activated as a reaction or free action. In this @@ -423,6 +428,7 @@ action: - Move trigger: null - actioncategory: Specialty Basic + actioncost_name: Varies descr: "You cast a spell you have prepared or in your repertoire. Casting a Spell is a special activity that takes a variable number of actions depending on the spell, as listed in each spell’s stat block. As soon as the spellcasting actions diff --git a/data/yaml/basics.yaml b/data/yaml/basics.yaml index 58cad7b..c2de3aa 100644 --- a/data/yaml/basics.yaml +++ b/data/yaml/basics.yaml @@ -25,8 +25,6 @@ abilityscore: short_name: Free2 long_name: Free 2 actioncost: - - name: Varies - abbr: varies - name: Single Action abbr: 1 - name: Two Actions @@ -37,6 +35,8 @@ actioncost: abbr: free - name: Reaction abbr: reaction + - name: Varies + abbr: varies alignment: - name: Lawful Good abbr: LG diff --git a/data/yaml/gendb.py b/data/yaml/gendb.py index 1b59ff9..8b20eca 100644 --- a/data/yaml/gendb.py +++ b/data/yaml/gendb.py @@ -74,7 +74,72 @@ def main(): def do_actions(data, conn): do_action_categories(data, conn) - pass + do_action_main(data, conn) + +def do_action_main(data, conn): + table = """ +CREATE TABLE action ( + action_id INTEGER PRIMARY KEY, + sourceentry_id INTEGER, + actioncategory_id INTEGER NOT NULL, + actioncost_id INTEGER, + name TEXT NOT NULL UNIQUE, + req TEXT, + trigger TEXT, + descr TEXT NOT NULL, + FOREIGN KEY (actioncategory_id) REFERENCES actioncategory(actioncategory_id), + FOREIGN KEY (actioncost_id) REFERENCES actioncost(actioncost_id), + FOREIGN KEY (sourceentry_id) REFERENCES sourceentry(sourceentry_id) +); + """ + c = conn.cursor() + c.execute(table) + + # print(data) + for i in data['action']: + # print(i) + srcentrydata = [] + for j in i['source']: + abbr = j['abbr'] + page_start = j['page_start'] + # Not all YAML entries have page_stop data + if 'page_stop' in j: + page_stop = j['page_stop'] + else: + page_stop = page_start + srcentrydata.append((abbr, page_start, page_stop)) + # need to insert sourceentry data first but check and make sure the + # length is only one + if len(srcentrydata) != 1: + raise AssertionError( + 'length of srcentrydata should only be 1, no more no less, on action' + ) + # print("length of srcentrydata:{}\tsrcentrydata:{}".format(len(srcentrydata),srcentrydata)) + util_insert_into_sourceentry(srcentrydata, conn) + + stmt = """ +INSERT INTO action(name, descr, req, trigger, actioncategory_id, actioncost_id, sourceentry_id) +VALUES (?,?,?,?, + (SELECT actioncategory_id FROM actioncategory WHERE name=?), + (SELECT actioncost_id from actioncost WHERE name=?), + (SELECT sourceentry_id FROM sourceentry + WHERE source_id=(SELECT source_id FROM source WHERE abbr=?) + AND page_start=? + AND page_stop=? + ) + ); + """ + print('executing on name:{}'.format(i['name'])) + try: + conn.execute( + stmt, + (i['name'], i['descr'],i['req'],i['trigger'],i['actioncategory'],i['actioncost_name'], srcentrydata[0][0], + srcentrydata[0][1], srcentrydata[0][2])) + except Exception as e: + print("Error creating action: {}".format(e)) + else: + conn.commit() + def do_action_categories(data, conn): table = """