base system

main
Justus Jan Nico Wolff 2024-05-11 23:20:47 +02:00
parent 2d17887635
commit 6329f77d3b
5 changed files with 158 additions and 32 deletions

View File

@ -1,27 +0,0 @@
class main():
def IND(self, index):
print("Indexing is not supported with this instruction")
return (1)
def EXEC(self, params):
end = "\n"
flush = False
text = ""
if len(params) > 0:
text = params[0]
if len(params) > 1:
end = params[1]
if len(params) > 2:
flush = bool(params[2])
if len(params) > 3:
return (1)
print(text, end=end, flush=flush)
return (0, None)
def ATR(self, target):
print("Getting an attribute is not supported with this instruction")
return (1)
def STAT(self, params):
print("Statements are not supported with this instruction")
return (1)
def OP(self, arg1, arg2):
print("Operations are not supported with this instruction")
return (1)

View File

@ -169,6 +169,9 @@ class game:
if min < target < max: return True
return False
def getobjbyid(self, id):
return self._objects[id]
def render(self):
for i in list(self._objects.values()):
pos = i.position + self.camera.position

View File

@ -10,4 +10,13 @@
"rename": "Umbenennen",
"delete": "Loeschen",
"NN": "Neuer Name:",
"save": "Speichern",
"attribute": "Attribut",
"attribute-val": "Wert",
"newval": "Neuen Wert eingeben",
"error": "Fehler",
"SCE": "Länge des neuen Wertes muss 1 sein!",
"true": "Wahr",
"false": "Falsch",
"objs": "Objekte",
}

View File

@ -10,4 +10,13 @@
"rename": "Rename",
"delete": "Delete",
"NN": "New name:",
"save": "Save",
"attribute": "Attribute",
"attribute-val": "Value",
"newval": "Enter new value",
"error": "Error",
"SCE": "Length of the new value must be 1!",
"true": "True",
"false": "False",
"objs": "Objects"
}

142
main.py
View File

@ -3,6 +3,7 @@ import sys
sys.dont_write_bytecode = True
import mtTkinter as tk
from tkinter import ttk as tkk
from tkinter import messagebox
import PCPL
import langsys
import time
@ -34,7 +35,7 @@ class script:
PCPL.LIS("HASHBASE")
PCPL.run(self.code)
class preview:
class previewrend:
def __init__(self, size, container, offset):
self._size = size
self._grid = {}
@ -70,14 +71,23 @@ def selectlang(new):
def add(objtype):
global objtree
crucial = ["obj"]
obj = getattr(types, objtype)()
temp = {"id": objtype, "args": dir(obj), "name": LH.string(objtype)}
args = {}
for i in dir(obj):
if i.startswith("_"): continue
args[i] = getattr(obj, i)
temp = {"id": objtype, "args": args, "name": LH.string(objtype)}
id = ""
chars = list(string.ascii_letters)
for i in range(255):
id = id + random.choice(chars)
objtree.insert("", tk.END, text=LH.string(objtype), image=icons[objtype], iid=id)
objtree.insert("", tk.END, text=LH.string(objtype), image=icons[objtype], iid=id, tags=("objsel"))
gamedata[id] = temp
if objtype in crucial:
preview.addobj(obj)
gamedata[id]["args"]["ID"] = obj.ID
preview.render()
def renameobj():
target = objtree.focus()
@ -90,6 +100,7 @@ def renameobj():
def delobj():
target = objtree.focus()
if target == "": return
atritree.delete(*atritree.get_children())
objtree.delete(target)
gamedata.pop(target)
@ -99,10 +110,56 @@ def rpopup(event):
finally:
rmenu.grab_release()
def getattributes(target):
out = {}
for i in dir(target):
if i.startswith("_"): continue
out[i] = getattr(target, i)
return out
def updatribute(event):
global currentat
target = objtree.focus()
currentat = target
atritree.delete(*atritree.get_children())
for i in gamedata[target]["args"]:
if i in ignoreat: continue
if i in valtypes:
val = gamedata[target]["args"][i]
atritree.insert("", tk.END, text=i, values=(val))
else:
root = atritree.insert("", tk.END, text=i)
temp = getattributes(gamedata[target]["args"][i])
for f in temp:
atritree.insert(root, tk.END, text=f, values=(temp[f]))
def halatribute(event):
target = atritree.focus()
name = atritree.item(target, "text")
parent = atritree.parent(target)
if name in valtypes:
if parent == "":
new = valtypes[name](gamedata[currentat]["args"][name])
gamedata[currentat]["args"][name] = new
if "ID" in gamedata[currentat]["args"]:
temp = preview.getobjbyid(gamedata[currentat]["args"]["ID"])
setattr(temp, name, new)
atritree.item(target, values=(new))
else:
parent = atritree.item(parent, "text")
new = valtypes[name](getattr(gamedata[currentat]["args"][parent], name))
setattr(gamedata[currentat]["args"][parent], name, new)
atritree.item(target, values=(new))
preview.render()
def GUIinit():
global container
global objtree
global rmenu
global atritree
global currentat
global preview
container = tk.Tk()
global icons
@ -111,9 +168,22 @@ def GUIinit():
for i in os.listdir("icons"):
icons[i.split(".")[0]] = tk.PhotoImage(file=f"icons/{i}")
#preview init
preview = hashengine.game(renderer=lambda size: previewrend(size, container=container, offset=[0, 0]))
#tree init
objtree = tkk.Treeview(container)
objtree.grid()
objtree = tkk.Treeview(container, selectmode="browse")
objtree.heading("#0", text=LH.string("objs"))
objtree.tag_bind("objsel", "<<TreeviewSelect>>", updatribute)
objtree.grid(row=10, column=11)
#attribute tree init
currentat = "temp"
atritree = tkk.Treeview(container, columns=("#1"), selectmode="browse")
atritree.heading("#0", text=LH.string("attribute"))
atritree.heading("#1", text=LH.string("attribute-val"))
atritree.bind("<Double-1>", halatribute)
atritree.grid(row=11, column=11)
#right click menu
rmenu = tk.Menu(container, tearoff=0)
@ -129,6 +199,7 @@ def GUIinit():
menu.add_cascade(label=LH.string("file"), menu=filemenu)
filemenu.add_command(label=LH.string("new"))
filemenu.add_command(label=LH.string("open"))
filemenu.add_command(label=LH.string("save"))
filemenu.add_separator()
filemenu.add_command(label=LH.string("exit"), command=container.quit)
@ -144,8 +215,69 @@ def GUIinit():
container.mainloop()
def ats(mode, old):
#mode 0 = string
#mode 1 = single character
out = easygui.enterbox(LH.string("newval"), LH.string("newval"))
if out:
if mode == 1 and len(out) != 1:
messagebox.showerror(LH.string("error"), LH.string("SCE"))
return "N"
return out
else:
return "N"
def anum(old):
out = easygui.integerbox(LH.string("newval"), LH.string("newval"), lowerbound=-9999999999, upperbound=9999999999)
if out:
return out
else:
return 0
def abool(old):
out = easygui.boolbox(LH.string("newval"), LH.string("newval"), (LH.string("true"), LH.string("false")))
return out
def acode(old):
out = easygui.textbox(LH.string("newval"), LH.string("newval"), old)
if out:
return out
else:
return "NULL"
global types
global icon
global ignoreat
global valtypes
types = hashengine.enum({"obj": hashengine.obj, "script": script})
icon = hashengine.enum({"obj": "icons/object.png", "script": "icons/script.pngg"})
ignoreat = ["ID", "execute"]
"""self.position = vector2()
self.char = " "
self.ID = 0
self.gravity = 0
self.acceleration = vector2()
self.velocity = vector2()
self.friction = 0
self.collide = True
self.touch = True
self.anchored = False
self.bcolor = color3(255, 255, 255)
self.fcolor = color3()"""
valtypes = {
"char": lambda old: ats(1, old),
"gravity": anum,
"x": anum,
"y": anum,
"z": anum,
"r": anum,
"g": anum,
"b": anum,
"friction": anum,
"collide": abool,
"touch": abool,
"anchored": abool,
"code": acode,
}
GUIinit()