added SID system and update documentation
parent
a8810fbb63
commit
06fbfa4051
|
@ -211,10 +211,14 @@ class game:
|
||||||
self.sounds[i.split(".")[0]] = loadsound(sounddir+"/"+i)
|
self.sounds[i.split(".")[0]] = loadsound(sounddir+"/"+i)
|
||||||
self._size = size
|
self._size = size
|
||||||
self._objects = {}
|
self._objects = {}
|
||||||
|
self._SIDS = {}
|
||||||
self.camera = camera()
|
self.camera = camera()
|
||||||
self._renderer = renderer(size, self.camera)
|
self._renderer = renderer(size, self.camera)
|
||||||
self._threads = []
|
self._threads = []
|
||||||
|
|
||||||
|
def getobjbySID(self, target):
|
||||||
|
return self._objects[self._SIDS[target]]
|
||||||
|
|
||||||
def isdown(self, key):
|
def isdown(self, key):
|
||||||
temp = self._renderer.getkeys()
|
temp = self._renderer.getkeys()
|
||||||
if key in temp:
|
if key in temp:
|
||||||
|
|
|
@ -37,4 +37,5 @@
|
||||||
"export": "Exportieren",
|
"export": "Exportieren",
|
||||||
"import": "Importieren",
|
"import": "Importieren",
|
||||||
"clog": "Logs erstellen",
|
"clog": "Logs erstellen",
|
||||||
|
"copied": "Kopiert!",
|
||||||
}
|
}
|
|
@ -37,4 +37,5 @@
|
||||||
"export": "Export",
|
"export": "Export",
|
||||||
"import": "Import",
|
"import": "Import",
|
||||||
"clog": "Create logs",
|
"clog": "Create logs",
|
||||||
|
"copied": "Copied!",
|
||||||
}
|
}
|
76
main.py
76
main.py
|
@ -53,49 +53,6 @@ version = "HE2.2-Hashengine V2.2"
|
||||||
cooldown = False
|
cooldown = False
|
||||||
gamedata = {}
|
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):
|
def prepspecified(target):
|
||||||
out = []
|
out = []
|
||||||
tempwin = tk.Tk()
|
tempwin = tk.Tk()
|
||||||
|
@ -112,7 +69,7 @@ def prepspecified(target):
|
||||||
bar.step(count/len(gamedata))
|
bar.step(count/len(gamedata))
|
||||||
count += 1
|
count += 1
|
||||||
tempwin.update()
|
tempwin.update()
|
||||||
temp = {"id": i["id"], "name": i["name"]}
|
temp = {"id": i["id"], "name": i["name"], "SID": i["SID"],}
|
||||||
tempargs = {}
|
tempargs = {}
|
||||||
tosearch = {}
|
tosearch = {}
|
||||||
for arg in i["args"]:
|
for arg in i["args"]:
|
||||||
|
@ -303,7 +260,7 @@ def add(objtype, parent="", render=True):
|
||||||
for i in dir(obj):
|
for i in dir(obj):
|
||||||
if i.startswith("_"): continue
|
if i.startswith("_"): continue
|
||||||
args[i] = getattr(obj, i)
|
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()
|
id = genid()
|
||||||
if GUIe == True: objtree.insert(parent, tk.END, text=LH.string(objtype), image=icons[objtype], iid=id, tags=("objsel"))
|
if GUIe == True: objtree.insert(parent, tk.END, text=LH.string(objtype), image=icons[objtype], iid=id, tags=("objsel"))
|
||||||
gamedata[id] = temp
|
gamedata[id] = temp
|
||||||
|
@ -396,6 +353,13 @@ def getattributes(target):
|
||||||
out[i] = getattr(target, i)
|
out[i] = getattr(target, i)
|
||||||
return out
|
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):
|
def updatribute(event):
|
||||||
global currentat
|
global currentat
|
||||||
target = objtree.focus()
|
target = objtree.focus()
|
||||||
|
@ -413,6 +377,7 @@ def updatribute(event):
|
||||||
temp = getattributes(gamedata[target]["args"][i])
|
temp = getattributes(gamedata[target]["args"][i])
|
||||||
for f in temp:
|
for f in temp:
|
||||||
atritree.insert(root, tk.END, text=f, values=(temp[f]), tags=("FA", ))
|
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):
|
def halatribute(event):
|
||||||
target = atritree.focus()
|
target = atritree.focus()
|
||||||
|
@ -453,7 +418,7 @@ def updatepreviewcam(char):
|
||||||
|
|
||||||
def save():
|
def save():
|
||||||
target = filedialog.asksaveasfile()
|
target = filedialog.asksaveasfile()
|
||||||
target.write(str(prepgamedata()))
|
target.write(str(prepspecified(gamedata)))
|
||||||
target.close()
|
target.close()
|
||||||
messagebox.showinfo(LH.string("suc"), LH.string("save-suc"))
|
messagebox.showinfo(LH.string("suc"), LH.string("save-suc"))
|
||||||
|
|
||||||
|
@ -471,6 +436,8 @@ def importsound(target):
|
||||||
gamedata[oid]["name"] = target["name"]
|
gamedata[oid]["name"] = target["name"]
|
||||||
gamedata[oid]["args"]["sdata"] = base64.b64decode(target["args"]["sdata"])
|
gamedata[oid]["args"]["sdata"] = base64.b64decode(target["args"]["sdata"])
|
||||||
gamedata[oid]["args"]["spath"] = target["args"]["spath"]
|
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"])
|
if GUIe == True: objtree.item(oid, text=target["name"])
|
||||||
|
|
||||||
def importobj(target):
|
def importobj(target):
|
||||||
|
@ -480,6 +447,8 @@ def importobj(target):
|
||||||
oid = add(target["id"])
|
oid = add(target["id"])
|
||||||
id = gamedata[oid]
|
id = gamedata[oid]
|
||||||
id["name"] = target["name"]
|
id["name"] = target["name"]
|
||||||
|
if "SID" in target:
|
||||||
|
id["SID"] = target["SID"]
|
||||||
if GUIe == True: objtree.item(oid, text=target["name"])
|
if GUIe == True: objtree.item(oid, text=target["name"])
|
||||||
#create arguments
|
#create arguments
|
||||||
outargs = {}
|
outargs = {}
|
||||||
|
@ -611,7 +580,7 @@ def testing():
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
running = True
|
running = True
|
||||||
testproc = multiprocessing.Process(target=execgame, args=(prepgamedata(), clog.get()))
|
testproc = multiprocessing.Process(target=execgame, args=(prepspecified(gamedata), clog.get()))
|
||||||
testproc.start()
|
testproc.start()
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
@ -641,9 +610,15 @@ def run():
|
||||||
i = gamedata[i]
|
i = gamedata[i]
|
||||||
if i["id"] != "sound" and i["id"] != "rawsound": continue
|
if i["id"] != "sound" and i["id"] != "rawsound": continue
|
||||||
maingame.sounds[i["args"]["spath"]] = i["args"]["sdata"]
|
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)
|
objects = copy.deepcopy(preview._objects)
|
||||||
maingame._objects = objects
|
maingame._objects = objects"""
|
||||||
scripts = []
|
scripts = []
|
||||||
for i in gamedata:
|
for i in gamedata:
|
||||||
i = gamedata[i]
|
i = gamedata[i]
|
||||||
|
@ -692,7 +667,7 @@ def build():
|
||||||
target = target+"/out"
|
target = target+"/out"
|
||||||
print("building started")
|
print("building started")
|
||||||
print("generating HEGF file...")
|
print("generating HEGF file...")
|
||||||
hegf = str(prepgamedata())
|
hegf = str(prepspecified(gamedata))
|
||||||
file = open(target+"/game.HEGF", 'w')
|
file = open(target+"/game.HEGF", 'w')
|
||||||
file.write(hegf)
|
file.write(hegf)
|
||||||
file.close()
|
file.close()
|
||||||
|
@ -811,6 +786,7 @@ def GUIinit():
|
||||||
atritree.heading("#1", text=LH.string("attribute-val"))
|
atritree.heading("#1", text=LH.string("attribute-val"))
|
||||||
atritree.tag_bind("FA", "<Double-1>", halatribute)
|
atritree.tag_bind("FA", "<Double-1>", halatribute)
|
||||||
atritree.tag_bind("OA", "<Double-1>", HMPC)
|
atritree.tag_bind("OA", "<Double-1>", HMPC)
|
||||||
|
atritree.tag_bind("SID", "<Double-1>", copySID)
|
||||||
atritree.grid(row=2, column=0)
|
atritree.grid(row=2, column=0)
|
||||||
|
|
||||||
#right click menu
|
#right click menu
|
||||||
|
|
|
@ -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.
|
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:
|
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 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>).
|
to remove an object from the running game use HASHGAME.removeobj(\<target object class>) or HASHGAME.removeobjbyid(\<ID>).
|
||||||
|
|
||||||
|
|
|
@ -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)'}}]
|
|
|
@ -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'}}}], {}]
|
|
@ -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
|
@ -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)'}}], {}]
|
Loading…
Reference in New Issue