added SID system and update documentation

main
Justus Jan Nico Wolff 2024-05-24 20:37:41 +02:00
parent a8810fbb63
commit 06fbfa4051
22 changed files with 43 additions and 52 deletions

View File

@ -211,10 +211,14 @@ class game:
self.sounds[i.split(".")[0]] = loadsound(sounddir+"/"+i)
self._size = size
self._objects = {}
self._SIDS = {}
self.camera = camera()
self._renderer = renderer(size, self.camera)
self._threads = []
def getobjbySID(self, target):
return self._objects[self._SIDS[target]]
def isdown(self, key):
temp = self._renderer.getkeys()
if key in temp:

View File

@ -37,4 +37,5 @@
"export": "Exportieren",
"import": "Importieren",
"clog": "Logs erstellen",
"copied": "Kopiert!",
}

View File

@ -37,4 +37,5 @@
"export": "Export",
"import": "Import",
"clog": "Create logs",
"copied": "Copied!",
}

76
main.py
View File

@ -53,49 +53,6 @@ version = "HE2.2-Hashengine V2.2"
cooldown = False
gamedata = {}
def prepgamedata():
out = []
tempwin = tk.Tk()
bar = tkk.Progressbar(tempwin)
bar.place(width=200)
ptext = tk.Label(tempwin, text="NONE")
ptext.place()
count = 1
modellist = {}
for i in gamedata:
id = i
i = gamedata[i]
ptext.config(text=i["name"])
bar.step(count/len(gamedata))
count += 1
tempwin.update()
temp = {"id": i["id"], "name": i["name"]}
tempargs = {}
tosearch = {}
for arg in i["args"]:
if not arg in extypes and not arg in ignoreat and arg != "sdata":
tosearch[arg] = i["args"][arg]
continue
if arg in ignoreat and arg != "sdata": continue
if arg != "sdata":
tempargs[arg] = i["args"][arg]
else:
tempargs[arg] = str(base64.b64encode(i["args"][arg]), "ascii", "ignore")
for argname in tosearch:
arg = tosearch[argname]
temp2 = getattributes(arg)
temp2.update({"ARGID": arg._type})
tempargs[argname] = temp2
if objtree.parent(id) != "":
modelname = objtree.item(objtree.parent(id), "text")
if not modelname in list(modellist.keys()):
modellist[modelname] = []
modellist[modelname].append(count-2)
temp["args"] = tempargs
out.append(temp)
tempwin.destroy()
return [out, modellist]
def prepspecified(target):
out = []
tempwin = tk.Tk()
@ -112,7 +69,7 @@ def prepspecified(target):
bar.step(count/len(gamedata))
count += 1
tempwin.update()
temp = {"id": i["id"], "name": i["name"]}
temp = {"id": i["id"], "name": i["name"], "SID": i["SID"],}
tempargs = {}
tosearch = {}
for arg in i["args"]:
@ -303,7 +260,7 @@ def add(objtype, parent="", render=True):
for i in dir(obj):
if i.startswith("_"): continue
args[i] = getattr(obj, i)
temp = {"id": objtype, "args": args, "name": LH.string(objtype)}
temp = {"id": objtype, "args": args, "name": LH.string(objtype), "SID": genid()}
id = genid()
if GUIe == True: objtree.insert(parent, tk.END, text=LH.string(objtype), image=icons[objtype], iid=id, tags=("objsel"))
gamedata[id] = temp
@ -396,6 +353,13 @@ def getattributes(target):
out[i] = getattr(target, i)
return out
def copySID(event):
target = atritree.focus()
text = atritree.item(target, "values")[0]
container.clipboard_clear()
container.clipboard_append(text)
messagebox.showinfo(LH.string("done"), LH.string("copied"))
def updatribute(event):
global currentat
target = objtree.focus()
@ -413,6 +377,7 @@ def updatribute(event):
temp = getattributes(gamedata[target]["args"][i])
for f in temp:
atritree.insert(root, tk.END, text=f, values=(temp[f]), tags=("FA", ))
atritree.insert("", tk.END, text="SID", values=(gamedata[target]["SID"]), tags=("SID", ))
def halatribute(event):
target = atritree.focus()
@ -453,7 +418,7 @@ def updatepreviewcam(char):
def save():
target = filedialog.asksaveasfile()
target.write(str(prepgamedata()))
target.write(str(prepspecified(gamedata)))
target.close()
messagebox.showinfo(LH.string("suc"), LH.string("save-suc"))
@ -471,6 +436,8 @@ def importsound(target):
gamedata[oid]["name"] = target["name"]
gamedata[oid]["args"]["sdata"] = base64.b64decode(target["args"]["sdata"])
gamedata[oid]["args"]["spath"] = target["args"]["spath"]
if "SID" in target:
gamedata[oid]["SID"] = target["SID"]
if GUIe == True: objtree.item(oid, text=target["name"])
def importobj(target):
@ -480,6 +447,8 @@ def importobj(target):
oid = add(target["id"])
id = gamedata[oid]
id["name"] = target["name"]
if "SID" in target:
id["SID"] = target["SID"]
if GUIe == True: objtree.item(oid, text=target["name"])
#create arguments
outargs = {}
@ -611,7 +580,7 @@ def testing():
except:
pass
running = True
testproc = multiprocessing.Process(target=execgame, args=(prepgamedata(), clog.get()))
testproc = multiprocessing.Process(target=execgame, args=(prepspecified(gamedata), clog.get()))
testproc.start()
def run():
@ -641,9 +610,15 @@ def run():
i = gamedata[i]
if i["id"] != "sound" and i["id"] != "rawsound": continue
maingame.sounds[i["args"]["spath"]] = i["args"]["sdata"]
print(i["args"]["spath"])
for i in gamedata:
i = gamedata[i]
if i["id"] != "obj": continue
objid = i["args"]["ID"]
maingame._SIDS[i["SID"]] = objid
maingame._objects = copy.deepcopy(preview._objects)
"""
objects = copy.deepcopy(preview._objects)
maingame._objects = objects
maingame._objects = objects"""
scripts = []
for i in gamedata:
i = gamedata[i]
@ -692,7 +667,7 @@ def build():
target = target+"/out"
print("building started")
print("generating HEGF file...")
hegf = str(prepgamedata())
hegf = str(prepspecified(gamedata))
file = open(target+"/game.HEGF", 'w')
file.write(hegf)
file.close()
@ -811,6 +786,7 @@ def GUIinit():
atritree.heading("#1", text=LH.string("attribute-val"))
atritree.tag_bind("FA", "<Double-1>", halatribute)
atritree.tag_bind("OA", "<Double-1>", HMPC)
atritree.tag_bind("SID", "<Double-1>", copySID)
atritree.grid(row=2, column=0)
#right click menu

View File

@ -37,7 +37,13 @@ the key to an object is its ID and the value is the object class.
to access the renderer (which is also normally bad practice) use HASHGAME._renderer, this gives you access to the running renderer class.
How to correctly access/add/remove an object:
to safely access an Object (no failsafes tho) you can use HASHGAME.getobjbyid(\<ID>).
to safely access an Object (no failsafes tho) you can use HASHGAME.getobjbyid(\<ID>), but to find your desired's object ID can be hard especially because it is randomly generated each time your game runs. Thats why there are SID's.
#### SID's
SID's are ID's of objects that always stay the same. You can view the SID of an object under the HASHENGINE editor under an object's attributes. Double click on the SID attribute to copy the SID to your clipboard.
Now to access an object trough it's SID use HASHGAME.getobjbySID(\<SID>) this will return the object class.
to add an Object to the running game use HASHGAME.addobj(\<target object>).
to remove an object from the running game use HASHGAME.removeobj(\<target object class>) or HASHGAME.removeobjbyid(\<ID>).

View File

@ -1 +0,0 @@
[{'id': 'obj', 'name': 'testobj', 'args': {'anchored': False, 'char': '#', 'collide': True, 'friction': 0, 'gravity': 0, 'acceleration': {'x': 0, 'y': 0, 'ARGID': 'vector2'}, 'bcolor': {'b': 0, 'g': 255, 'r': 255, 'ARGID': 'color3'}, 'fcolor': {'b': 0, 'g': 0, 'r': 255, 'ARGID': 'color3'}, 'position': {'x': 5, 'y': 5, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}, {'id': 'script', 'name': 'skript pos test', 'args': {'code': 'import random\nimport time\ntime.sleep(3)\nobjects = list(HASHGAME._objects.values())\nobject = objects[0]\nstartpos = object.position\nwhile True:\n\tobject.position = startpos + HASHBASE.vector2(random.randint(-3, 3), random.randint(-3, 3))\n\ttime.sleep(.01)'}}]

1
tests/SIDOBJTEST 100644
View File

@ -0,0 +1 @@
[[{'id': 'obj', 'name': 'Objekt', 'SID': 'cBDzZOjVkPyhFYiKEdtuaFQlxlLgqzfcrlervYNhMehnTaOKXyJYgaqzHCtkiPCgtIECpsHCSKLGsARxRxzcsuyBTWJKUKSCfOGeTxKmehhilRcyHdxWEjzuTyeVsZpvmIONqmMJGGvAuuAGYNWYUfTqQxlErAxIqPocgaQtSJqwExzDThQrKkVoduzVCGcfoGxxXCgRKHvgbYabsdQWRvEVTgRBPVtDmPpIDhKyMBEOuXeGTWkZxqmeiaocirz', 'args': {'anchored': False, 'char': ' ', 'collide': True, 'friction': 0, 'gravity': 0, 'acceleration': {'x': 0, 'y': 0, 'ARGID': 'vector2'}, 'bcolor': {'b': 255, 'g': 255, 'r': 255, 'ARGID': 'color3'}, 'fcolor': {'b': 0, 'g': 0, 'r': 0, 'ARGID': 'color3'}, 'position': {'x': 0, 'y': 0, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}], {}]

View File

@ -0,0 +1 @@
[[{'id': 'script', 'name': 'Skript', 'SID': 'hehe speicher daten manipulation!', 'args': {'code': ''}}], {}]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[[{'id': 'obj', 'name': 'testobj', 'SID': 'ufHpZVRQOqwkWnIHOptIiGdnarlzIGCowDxGDVsCkQclSNpFZMVjUFeqBGlULgAwBnrZvIBHlzDGQfHOdHMPjDujjvjzMhjldZBUzUOKsBkhySuMIXRIirwtVbTnENGYyLfGcWCuSEdWVrsUhskDRSlIzumZSxUICNbdHuhwjmnuKlHDJTAMTihzyYClwGxRTSszGNfokgvfbKFpItNknVKoVVjQdplvAQfuSlvAPJuDMhPcgPsVpPBXkUJnpRH', 'args': {'anchored': False, 'char': '#', 'collide': True, 'friction': 0, 'gravity': 0, 'acceleration': {'x': 0, 'y': 0, 'ARGID': 'vector2'}, 'bcolor': {'b': 0, 'g': 255, 'r': 255, 'ARGID': 'color3'}, 'fcolor': {'b': 0, 'g': 0, 'r': 255, 'ARGID': 'color3'}, 'position': {'x': 5, 'y': 5, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}, {'id': 'script', 'name': 'skript pos test', 'SID': 'fIpbcfzqVEzGCzECEpWvVdKDOADFMunXHuoUEedeForBPRuuNBiRXKgntFjnZIZqgAaXWGEbQRxfeEPqxyJCIhFmKpUlsceNdNvmPKWrFFLFRkGOSVLLxJCqZEluUKSoKSILZGSSgtZEaaOQUGdaeVRqxyEHBKyehpdunyBFQIdBWpyVlPiLuhTyJbARFsDZooFJfCqCCjFgHEIqtLAMaUWHAmXqVrSyvcyiSmLdaXVpPjyzNNZyPqSqFGrznZX', 'args': {'code': 'import random\nimport time\ntime.sleep(3)\nprint("BTW this thing is updated! uses the SID system now!")\nobject = HASHGAME.getobjbySID("ufHpZVRQOqwkWnIHOptIiGdnarlzIGCowDxGDVsCkQclSNpFZMVjUFeqBGlULgAwBnrZvIBHlzDGQfHOdHMPjDujjvjzMhjldZBUzUOKsBkhySuMIXRIirwtVbTnENGYyLfGcWCuSEdWVrsUhskDRSlIzumZSxUICNbdHuhwjmnuKlHDJTAMTihzyYClwGxRTSszGNfokgvfbKFpItNknVKoVVjQdplvAQfuSlvAPJuDMhPcgPsVpPBXkUJnpRH")\norigin = HASHBASE.vector2(object.position.x, object.position.y)\nwhile True:\n\tobject.position = origin + HASHBASE.vector2(random.randint(-3, 3), random.randint(-3, 3))\n\ttime.sleep(0.1)'}}], {}]