first steps of melee weapons working
parent
9d97d42bbe
commit
0f60606c73
6
gendb.sh
6
gendb.sh
|
@ -16,6 +16,7 @@ sqlite3 pf2.db < schema/senses.sql
|
||||||
sqlite3 pf2.db < schema/ancestries.sql
|
sqlite3 pf2.db < schema/ancestries.sql
|
||||||
sqlite3 pf2.db < schema/armor.sql
|
sqlite3 pf2.db < schema/armor.sql
|
||||||
sqlite3 pf2.db < schema/gear.sql
|
sqlite3 pf2.db < schema/gear.sql
|
||||||
|
sqlite3 pf2.db < schema/weapons.sql
|
||||||
echo 'loading data'
|
echo 'loading data'
|
||||||
sqlite3 pf2.db < data/sources.sql
|
sqlite3 pf2.db < data/sources.sql
|
||||||
sqlite3 pf2.db < data/damagetypes.sql
|
sqlite3 pf2.db < data/damagetypes.sql
|
||||||
|
@ -34,10 +35,15 @@ sqlite3 pf2.db < data/ancestries.sql
|
||||||
sqlite3 pf2.db < data/armor.sql
|
sqlite3 pf2.db < data/armor.sql
|
||||||
sqlite3 pf2.db < data/gear.sql
|
sqlite3 pf2.db < data/gear.sql
|
||||||
sqlite3 pf2.db < data/heritages.sql
|
sqlite3 pf2.db < data/heritages.sql
|
||||||
|
sqlite3 pf2.db < data/weapons.sql
|
||||||
# Comment out the following three lines if you don't want to generate the spell data.
|
# Comment out the following three lines if you don't want to generate the spell data.
|
||||||
cd data/third_party_json
|
cd data/third_party_json
|
||||||
python3 spells.py
|
python3 spells.py
|
||||||
cd ../..
|
cd ../..
|
||||||
|
# Comment out the following when we don't want to generate weapons
|
||||||
|
cd src/weapons
|
||||||
|
python3 weapons.py
|
||||||
|
cd ../..
|
||||||
|
|
||||||
# TODO Eventually we will stop relying on the spells.py script and I will have
|
# TODO Eventually we will stop relying on the spells.py script and I will have
|
||||||
# the actual .sql files for the spell data; I am waiting to see if the
|
# the actual .sql files for the spell data; I am waiting to see if the
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
import csv
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# load json into python
|
||||||
|
print("loading melee.csv")
|
||||||
|
## read file into memory
|
||||||
|
rows = []
|
||||||
|
with open('melee.csv') as f:
|
||||||
|
reader = csv.DictReader(f)
|
||||||
|
print(reader)
|
||||||
|
for row in reader:
|
||||||
|
rows.append(row)
|
||||||
|
|
||||||
|
|
||||||
|
## Get database connection
|
||||||
|
conn = sqlite3.connect('../../pf2.db')
|
||||||
|
## Set pragmas to make it go FAST
|
||||||
|
pragma1 = "PRAGMA synchronous=OFF;"
|
||||||
|
pragma2 = "PRAGMA count_changes=OFF;"
|
||||||
|
pragma3 = "PRAGMA journal_mode=MEMORY;"
|
||||||
|
pragma4 = "PRAGMA temp_store=MEMORY;"
|
||||||
|
pragma5 = "PRAGMA foreign_keys=ON;"
|
||||||
|
conn.execute(pragma1)
|
||||||
|
conn.execute(pragma2)
|
||||||
|
conn.execute(pragma3)
|
||||||
|
conn.execute(pragma4)
|
||||||
|
conn.execute(pragma5)
|
||||||
|
|
||||||
|
# load in ids for traits from traits table so we only call this once
|
||||||
|
# instead of every spell
|
||||||
|
stmt = "SELECT trait_id, short_name FROM traits"
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute(stmt)
|
||||||
|
traits = c.fetchall()
|
||||||
|
# print("Printing traits")
|
||||||
|
# print(traits)
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
insert_melee_weapon(row, conn, traits)
|
||||||
|
|
||||||
|
def insert_melee_weapon(row, conn, traits):
|
||||||
|
print("Inserting: {}".format(row['name']))
|
||||||
|
# insert everything that's not a lookup
|
||||||
|
stmt = """
|
||||||
|
INSERT INTO weapons (
|
||||||
|
weapons_id,
|
||||||
|
sources_id,
|
||||||
|
sources_pages,
|
||||||
|
price_gp,
|
||||||
|
dice_size,
|
||||||
|
bulk,
|
||||||
|
hands,
|
||||||
|
name,
|
||||||
|
descr)
|
||||||
|
VALUES (?,?,?,?,?,?,?,?,?);
|
||||||
|
"""
|
||||||
|
r = row
|
||||||
|
inp = (r['weapon_m_id'],r['sources_id'],r['sources_pg'],r['price_gp'],
|
||||||
|
r['dice_size'],r['bulk'],r['hands'],r['name'],r['description'])
|
||||||
|
|
||||||
|
try:
|
||||||
|
conn.execute(stmt, inp)
|
||||||
|
except:
|
||||||
|
print("Error inserting basic row information")
|
||||||
|
else:
|
||||||
|
conn.commit()
|
||||||
|
# print("Successfully inserted row")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue