This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
addDbLevels.py
executable file
·51 lines (39 loc) · 1.6 KB
/
addDbLevels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import sqlite3
import sys
DB_FILE = "static/ltype.db"
ASSETS_FILE = "include/assetsID.hpp"
CONST_FILE = "include/constants.hpp"
def searchAsset(searchedEntity, searchedNumber, searchedValue):
with open(ASSETS_FILE, "r") as data:
content = data.readlines()
for line in content[2:]:
if line.strip() != "":
asset = line.strip().split(" ")[2].split("_")
if asset[1] == searchedEntity and asset[2] == searchedNumber and asset[3] == searchedValue:
return line.split(" ")[4].strip()[:-1]
def build_levels(db, level_file_path):
cur = db.cursor()
cur.execute("INSERT INTO levels (creator) VALUES ('tijl')")
cur.execute("SELECT last_insert_rowid()")
lvlID = cur.fetchone()[0]
db.commit()
lvl_file = open(level_file_path, "r")
content = lvl_file.readlines()
lvl_file.close()
for values in content:
progress, name, xPos = values.split(",")
splitted = name.split("_")
entity = splitted[0]
number = splitted[1]
ID = searchAsset(entity, number, "ID")
width = searchAsset(entity, number, "WIDTH")
height = searchAsset(entity, number, "HEIGHT")
values = [lvlID, progress, ID, xPos, width, height]
cur.execute(f"INSERT INTO level_entities (level, progress, entity, xPos, yPos, xSize, ySize, xVelocity, yVelocity) VALUES (?, ?, ?, ?, 0, ?, ?, 0, 0)", values)
db.commit()
if __name__ == "__main__":
level_file_path = sys.argv[1]
db = sqlite3.connect(DB_FILE)
build_levels(db, level_file_path)
db.close()