extra features

main
Justus Jan Nico Wolff 2024-05-17 13:28:28 +02:00
parent 769c9067d2
commit 309f93461a
6 changed files with 59 additions and 47 deletions

View File

@ -195,25 +195,6 @@ class camera(obj):
if self.mode == cammode.follow and self.subject: if self.mode == cammode.follow and self.subject:
self.position = self.subject.position self.position = self.subject.position
def COBS(target: str, offset=vector2(), ignore=[" ",]):
target = target.split("\n")
out = []
for i in range(len(target)):
y = i
i = target[i]
for f in range(len(i)):
x = f
f = i[x]
if f in ignore:
continue
temp = obj()
temp.char = f
temp.position = vector2(x, y)+offset
temp.anchored = True
temp.collide = True
out.append(temp)
return out
class game: class game:
def __init__(self, size=[10, 10], renderer=stdrend, sounddir=""): def __init__(self, size=[10, 10], renderer=stdrend, sounddir=""):
if renderer == None: raise TypeError("Renderer class needed!") if renderer == None: raise TypeError("Renderer class needed!")

View File

@ -29,4 +29,6 @@
"building": "Bauen", "building": "Bauen",
"build": "Bauen", "build": "Bauen",
"sound": "Sound", "sound": "Sound",
"IPS": "Python Skript importieren",
"COBS": "Objekte durch String erstellen",
} }

View File

@ -29,4 +29,6 @@
"building": "Building", "building": "Building",
"build": "Build", "build": "Build",
"sound": "Sound", "sound": "Sound",
"IPS": "Import python script",
"COBS": "Create objects by string",
} }

View File

@ -1,8 +0,0 @@
Log file start!
Preparing API...
Done!
main game initalised!
copying sounds...
objects transferred!
game test started!!!
---------------------

View File

@ -1,8 +0,0 @@
Log file start!
Preparing API...
Done!
main game initalised!
copying sounds...
objects transferred!
game test started!!!
---------------------

67
main.py
View File

@ -39,6 +39,8 @@ import multiprocessing
global gamedata global gamedata
global cooldown global cooldown
global version
version = "HE2.2-Hashengine V2.2"
cooldown = False cooldown = False
gamedata = {} gamedata = {}
@ -82,13 +84,16 @@ class script:
def __init__(self): def __init__(self):
self.code = "" self.code = ""
def execute(self, API): def execute(self, API, log):
#old code for PCPL code execution, replaced with python code execution #old code for PCPL code execution, replaced with python code execution
""" """
PCPL.resetvar() PCPL.resetvar()
PCPL.LIS("HASHBASE") PCPL.LIS("HASHBASE")
PCPL.run(self.code)""" PCPL.run(self.code)"""
exec(self.code, API) try:
exec(self.code, API)
except Exception as e:
log(f"[GAME] Exception occured in script: {e}")
class previewrend: class previewrend:
def __init__(self, size, cam, container, offset): def __init__(self, size, cam, container, offset):
@ -291,9 +296,12 @@ def updatribute(event):
for i in gamedata[target]["args"]: for i in gamedata[target]["args"]:
if i in ignoreat: continue if i in ignoreat: continue
if i in valtypes:
if i in valtypes and not i in DCTE:
val = gamedata[target]["args"][i] val = gamedata[target]["args"][i]
atritree.insert("", tk.END, text=i, values=(val)) atritree.insert("", tk.END, text=i, values=(val))
elif i in valtypes and i in DCTE:
atritree.insert("", tk.END, text=i, values=("<DCTE>"))
else: else:
root = atritree.insert("", tk.END, text=i) root = atritree.insert("", tk.END, text=i)
temp = getattributes(gamedata[target]["args"][i]) temp = getattributes(gamedata[target]["args"][i])
@ -311,12 +319,14 @@ def halatribute(event):
if "ID" in gamedata[currentat]["args"]: if "ID" in gamedata[currentat]["args"]:
temp = preview.getobjbyid(gamedata[currentat]["args"]["ID"]) temp = preview.getobjbyid(gamedata[currentat]["args"]["ID"])
setattr(temp, name, new) setattr(temp, name, new)
atritree.item(target, values=(new)) if not name in DCTE: atritree.item(target, values=(new))
if name in DCTE: atritree.item(target, values=("<DCTE>"))
else: else:
parent = atritree.item(parent, "text") parent = atritree.item(parent, "text")
new = valtypes[name](getattr(gamedata[currentat]["args"][parent], name)) new = valtypes[name](getattr(gamedata[currentat]["args"][parent], name))
setattr(gamedata[currentat]["args"][parent], name, new) setattr(gamedata[currentat]["args"][parent], name, new)
atritree.item(target, values=(new)) if not name in DCTE: atritree.item(target, values=(new))
if name in DCTE: atritree.item(target, values=("<DCTE>"))
preview.render() preview.render()
def updatepreviewcam(char): def updatepreviewcam(char):
@ -329,7 +339,7 @@ def updatepreviewcam(char):
if char == "s": preview.camera.position -= hashengine.vector2(y=1) if char == "s": preview.camera.position -= hashengine.vector2(y=1)
if char == "d": preview.camera.position -= hashengine.vector2(x=1) if char == "d": preview.camera.position -= hashengine.vector2(x=1)
preview.render() preview.render()
time.sleep(0) time.sleep(.0)
cooldown = False cooldown = False
def save(): def save():
@ -450,6 +460,8 @@ def run():
logfile = logfile + "S" + str(i) logfile = logfile + "S" + str(i)
print("done") print("done")
log("Log file start!") log("Log file start!")
log(f"date: year: {temp[0]} month: {temp[1]} day: {temp[2]} hour: {temp[3]} min.: {temp[4]}, sec.: {temp[5]}")
log(f"Version: {version}")
log("Preparing API...") log("Preparing API...")
API = {"print": log, "HASHBASE": hashengine} API = {"print": log, "HASHBASE": hashengine}
log("Done!") log("Done!")
@ -487,11 +499,11 @@ while True:
""" """
gameloopsc = script() gameloopsc = script()
gameloopsc.code = gamescript gameloopsc.code = gamescript
maingame.startscript(lambda: gameloopsc.execute(API)) maingame.startscript(lambda: gameloopsc.execute(API, log))
log("game test started!!!") log("game test started!!!")
log("---------------------") log("---------------------")
for i in scripts: for i in scripts:
maingame.startscript(lambda: i.execute(API)) maingame.startscript(lambda: i.execute(API, log))
window.mainloop() window.mainloop()
def muladd(target): def muladd(target):
@ -532,6 +544,35 @@ player.execgame(file)
print("done.") print("done.")
print("building finished!") print("building finished!")
def importPS():
target = filedialog.askopenfile()
if target:
temp = add("script")
gamedata[temp]["args"]["code"] = str(target.read())
target.close()
def COBS(target: str, offset=hashengine.vector2(), ignore=[" ",]):
target = target.split("\n")
for i in range(len(target)):
y = i
i = target[i]
for f in range(len(i)):
x = f
f = i[x]
if f in ignore:
continue
temp = add("obj")
#gamedata[temp]["args"]["ID"]
gamedata[temp]["args"]["char"] = f
setattr(preview.getobjbyid(gamedata[temp]["args"]["ID"]), "char", f)
gamedata[temp]["args"]["position"] = hashengine.vector2(x, y)+offset
setattr(preview.getobjbyid(gamedata[temp]["args"]["ID"]), "position", hashengine.vector2(x, y)+offset)
gamedata[temp]["args"]["anchored"] = True
setattr(preview.getobjbyid(gamedata[temp]["args"]["ID"]), "anchored", True)
gamedata[temp]["args"]["collide"] = True
setattr(preview.getobjbyid(gamedata[temp]["args"]["ID"]), "collide", True)
preview.render()
def GUIinit(): def GUIinit():
global container global container
global objtree global objtree
@ -590,6 +631,9 @@ def GUIinit():
addmenu.add_command(label=LH.string("obj"), command=lambda: add("obj")) addmenu.add_command(label=LH.string("obj"), command=lambda: add("obj"))
addmenu.add_command(label=LH.string("script"), command=lambda: add("script")) addmenu.add_command(label=LH.string("script"), command=lambda: add("script"))
addmenu.add_command(label=LH.string("sound"), command=lambda: add("sound")) addmenu.add_command(label=LH.string("sound"), command=lambda: add("sound"))
addmenu.add_separator()
addmenu.add_command(label=LH.string("IPS"), command=importPS)
addmenu.add_command(label=LH.string("COBS"), command=lambda: COBS(acode(" ")))
#addmenu.add_command(label=LH.string("obj"), command=lambda: muladd("obj")) #addmenu.add_command(label=LH.string("obj"), command=lambda: muladd("obj"))
testmenu = tk.Menu(menu) testmenu = tk.Menu(menu)
@ -637,10 +681,7 @@ def anum(old):
def abool(old): def abool(old):
out = easygui.boolbox(LH.string("newval"), LH.string("newval"), (LH.string("true"), LH.string("false"))) out = easygui.boolbox(LH.string("newval"), LH.string("newval"), (LH.string("true"), LH.string("false")))
if out: return out
return out
else:
return old
def acode(old): def acode(old):
out = easygui.textbox(LH.string("newval"), LH.string("newval"), old) out = easygui.textbox(LH.string("newval"), LH.string("newval"), old)
@ -684,9 +725,11 @@ global valtypes
global extypes global extypes
global attypes global attypes
global crucial global crucial
global DCTE
crucial = ["obj"] crucial = ["obj"]
types = hashengine.enum({"obj": hashengine.obj, "script": script, "rawsound": rsound, "sound": lambda: sound(apath("", [("Wave files", ".wave .wav")]))}) types = hashengine.enum({"obj": hashengine.obj, "script": script, "rawsound": rsound, "sound": lambda: sound(apath("", [("Wave files", ".wave .wav")]))})
ignoreat = ["ID", "execute", "sdata"] ignoreat = ["ID", "execute", "sdata"]
DCTE = ["code"]
"""self.position = vector2() """self.position = vector2()
self.char = " " self.char = " "
self.ID = 0 self.ID = 0