SEQ fix
parent
d8b2a9f69d
commit
19a78eb3bf
|
@ -206,7 +206,7 @@ class seqobj:
|
||||||
|
|
||||||
def moveby(self, pos):
|
def moveby(self, pos):
|
||||||
for i in self._objects:
|
for i in self._objects:
|
||||||
i.position + pos
|
i.position += pos
|
||||||
|
|
||||||
class game:
|
class game:
|
||||||
def __init__(self, size=[10, 10], renderer=stdrend, sounddir=""):
|
def __init__(self, size=[10, 10], renderer=stdrend, sounddir=""):
|
||||||
|
|
36
main.py
36
main.py
|
@ -475,20 +475,25 @@ def importobj(target):
|
||||||
id["args"].update(outargs)
|
id["args"].update(outargs)
|
||||||
return oid
|
return oid
|
||||||
|
|
||||||
def load(cleargame=True, GUI=True, path=""):
|
def load(cleargame=True, GUI=True, path="", override=False):
|
||||||
if GUI == True:
|
if GUI == True:
|
||||||
file = filedialog.askopenfile()
|
file = filedialog.askopenfile()
|
||||||
else:
|
elif override == False:
|
||||||
file = open(path, 'r')
|
file = open(path, 'r')
|
||||||
tempwin = tk.Tk()
|
tempwin = tk.Tk()
|
||||||
ptext = tk.Label(tempwin, text="NONE")
|
ptext = tk.Label(tempwin, text="NONE")
|
||||||
ptext.place(y=30)
|
ptext.place(y=30)
|
||||||
stat = tk.Label(tempwin, text="NONE")
|
stat = tk.Label(tempwin, text="NONE")
|
||||||
stat.place(y=50)
|
stat.place(y=50)
|
||||||
|
if override == False:
|
||||||
target = file.read()
|
target = file.read()
|
||||||
file.close()
|
file.close()
|
||||||
|
else:
|
||||||
|
target = override
|
||||||
target = ast.literal_eval(target)
|
target = ast.literal_eval(target)
|
||||||
if cleargame:
|
if cleargame:
|
||||||
|
global models
|
||||||
|
models = []
|
||||||
clear()
|
clear()
|
||||||
if len(target) == 0: return
|
if len(target) == 0: return
|
||||||
if not isinstance(target[0], list):
|
if not isinstance(target[0], list):
|
||||||
|
@ -520,13 +525,16 @@ def load(cleargame=True, GUI=True, path=""):
|
||||||
if id:
|
if id:
|
||||||
ids[count-1] = id
|
ids[count-1] = id
|
||||||
count += 1
|
count += 1
|
||||||
if GUIe == True:
|
|
||||||
for i in target[1]:
|
for i in target[1]:
|
||||||
tempid = genid()
|
tempid = genid()
|
||||||
objtree.insert("", tk.END, text=i, image=icons["model"], iid=tempid, tags=("HASHMODEL",))
|
if GUIe == True: objtree.insert("", tk.END, text=i, image=icons["model"], iid=tempid, tags=("HASHMODEL",))
|
||||||
|
temp = []
|
||||||
for f in target[1][i]:
|
for f in target[1][i]:
|
||||||
|
if GUIe == True:
|
||||||
objtree.detach(ids[f])
|
objtree.detach(ids[f])
|
||||||
objtree.move(ids[f], tempid, "end")
|
objtree.move(ids[f], tempid, "end")
|
||||||
|
temp.append(ids[f])
|
||||||
|
models.append(temp)
|
||||||
tempwin.destroy()
|
tempwin.destroy()
|
||||||
preview.render()
|
preview.render()
|
||||||
|
|
||||||
|
@ -617,21 +625,28 @@ 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"]
|
||||||
skip = []
|
#skip = []
|
||||||
for i in gamedata:
|
for i in gamedata:
|
||||||
GID = i
|
GID = i
|
||||||
i = gamedata[i]
|
i = gamedata[i]
|
||||||
if i["id"] != "obj": continue
|
if i["id"] != "obj": continue
|
||||||
objid = i["args"]["ID"]
|
objid = i["args"]["ID"]
|
||||||
maingame._SIDS[i["SID"]] = objid
|
maingame._SIDS[i["SID"]] = objid
|
||||||
if objtree.parent(GID) != "" and not objtree.parent(GID) in skip:
|
"""if objtree.parent(GID) != "" and not objtree.parent(GID) in skip:
|
||||||
skip.append(objtree.parent(GID))
|
skip.append(objtree.parent(GID))
|
||||||
out = ""
|
out = ""
|
||||||
out2 = []
|
out2 = []
|
||||||
for f in objtree.get_children(objtree.parent(GID)):
|
for f in objtree.get_children(objtree.parent(GID)):
|
||||||
out = out + gamedata[f]["SID"][:5]
|
out = out + gamedata[f]["SID"][:5]
|
||||||
out2.append(f)
|
out2.append(f)
|
||||||
maingame._SEQSIDS[out] = out2
|
maingame._SEQSIDS[out] = out2"""
|
||||||
|
for i in models:
|
||||||
|
out = []
|
||||||
|
SEQSID = ""
|
||||||
|
for f in i:
|
||||||
|
SEQSID = SEQSID + gamedata[f]["SID"][:5]
|
||||||
|
out.append(gamedata[f]["args"]["ID"])
|
||||||
|
maingame._SEQSIDS[SEQSID] = out
|
||||||
|
|
||||||
maingame._objects = copy.deepcopy(preview._objects)
|
maingame._objects = copy.deepcopy(preview._objects)
|
||||||
"""
|
"""
|
||||||
|
@ -777,6 +792,8 @@ def GUIinit():
|
||||||
global preview
|
global preview
|
||||||
global GUIe
|
global GUIe
|
||||||
global clog
|
global clog
|
||||||
|
global models
|
||||||
|
models = []
|
||||||
GUIe = True
|
GUIe = True
|
||||||
container = tk.Tk()
|
container = tk.Tk()
|
||||||
container.bind("<KeyPress>", updatepreviewcam, add="+")
|
container.bind("<KeyPress>", updatepreviewcam, add="+")
|
||||||
|
@ -966,10 +983,11 @@ def execgame(gametree, shouldlog=True):
|
||||||
global GUIe
|
global GUIe
|
||||||
global preview
|
global preview
|
||||||
global clog
|
global clog
|
||||||
|
global models
|
||||||
preview = hashengine.game(renderer=nullrend, sounddir="/")
|
preview = hashengine.game(renderer=nullrend, sounddir="/")
|
||||||
GUIe = False
|
GUIe = False
|
||||||
for i in gametree[0]:
|
models = []
|
||||||
importobj(i)
|
load(False, False, "", str(gametree))
|
||||||
clog = shouldlog
|
clog = shouldlog
|
||||||
run()
|
run()
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
[[{'id': 'obj', 'name': 'Objekt', 'SID': 'cUwnltshBNeQQFvuwfXuUzsaHaJKyxSqwztnBteAIHrqzsOgEljfWOOGmzgCLgsuYxfyTyMehQXFcQWHCLmBWCMAPieboGymJOoNPKboUUtSuJUvjLLFYycsukzeHVBGcIUfZzJBJYUoFVTBhYKuLqYpwWrIWrEdUPjPpXUhKGEuolPGBHYmativzBekLKGEEKvpIWvPQoDhoAzVZaevzQAisacPettAjoEynVhDkSUggmsTjXqqutysffacbzD', 'args': {'anchored': True, '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': 5, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}, {'id': 'obj', 'name': 'Objekt', 'SID': 'kzjhJQJZTwwBnsqFbMMWwoubynoPJVuFLPGlTMODHNbtIkqmYlCdwDQAgXEGrNemqizGeVajNuLScIftEjGfMgUVhFPYdXFDkKdyHJVdTascWZDJmZPmhTSiYWhnsvONfVvmHOmVeJrwHgjeHgDChAEkDXrDLbhoqVkpVvNaQgpecMqHaojBRGqlaDysXUYBSILmzOHbsllKaPxyPeGWNDTQkViUqdfPmfAYknybhPcGowVWzPaIijmbkFxYxyZ', 'args': {'anchored': True, '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': 1, 'y': 5, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}, {'id': 'obj', 'name': 'Objekt', 'SID': 'ypuYPxrQJbjLqPCIRSUjaSLKTjYRWFkldnHeHzaDuqTFcKbAVuqmKwadBqCrCyoNarxWlSCzIeeBpTIUCXNGWbMKtsmIsxUawwictmxqSRDwZyOdeqPYeMEeJaxwbpIovYpbHvbMglAfaOnQCXKqfStBXYURpfxUCrzDVnJzJMbuxWVHksdZQSjhChZTVAZrSChBrRQhkYCnsJqwxhEzrhjZgWIgaGopmAgQZnFFtQltSVovxbqvvTkquUEdswM', 'args': {'anchored': True, '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': 2, 'y': 5, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}, {'id': 'script', 'name': 'Skript', 'SID': 'nWvowGAstSdSoUbpAoSoXlogKgfAApqyiiCEcfcEOUnCvthUiozkobNUlUNbiBdrzKdajEXAkrHbwQtGMExMWpDYoXRUVecdfvGYntJnKYdviiXSdcrsoTldVBOBQUgWylLBysTmVipXvBtyjOXOtvgrOqKWcdRjRNRhXqdNBRwCBrbpfHVxJIbGIttQZFYoypouuYexsLAwDtxlJdhZhYYpyQJTpJtGmLVFNcnJWUYejTDanpUfCVJZkfbRLXC', 'args': {'code': 'import time\nobj = HASHGAME.getobjseqbySID("cUwnlkzjhJypuYP")\ntime.sleep(3)\nobj.moveby(HASHBASE.vector2(0, 3))'}}], {'Erstellte Objekte': [0, 1, 2]}]
|
|
@ -0,0 +1,378 @@
|
||||||
|
import tkinter as tk
|
||||||
|
import string
|
||||||
|
import random
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import wave
|
||||||
|
import os
|
||||||
|
|
||||||
|
class stdrend:
|
||||||
|
def __init__(self, size, cam):
|
||||||
|
self._size = size
|
||||||
|
self._grid = {}
|
||||||
|
self._win = tk.Tk()
|
||||||
|
|
||||||
|
tkeys = list(string.ascii_letters)
|
||||||
|
self._keys = {}
|
||||||
|
for i in tkeys:
|
||||||
|
self._keys[i] = False
|
||||||
|
self._win.bind("<KeyPress>", self.keypupd)
|
||||||
|
self._win.bind("<KeyRelease>", self.keydupd)
|
||||||
|
|
||||||
|
for y in range(size[1]):
|
||||||
|
for x in range(size[0]):
|
||||||
|
temp = tk.Label(text=" ")
|
||||||
|
temp.grid(row=y, column=x)
|
||||||
|
self._win.update()
|
||||||
|
self._grid[f"{x}:{y}"] = temp
|
||||||
|
|
||||||
|
def keypupd(self, event):
|
||||||
|
event = event.char
|
||||||
|
if event in self._keys:
|
||||||
|
self._keys[event] = True
|
||||||
|
|
||||||
|
def keydupd(self, event):
|
||||||
|
event = event.char
|
||||||
|
if event in self._keys:
|
||||||
|
self._keys[event] = False
|
||||||
|
|
||||||
|
def getkeys(self):
|
||||||
|
return self._keys
|
||||||
|
|
||||||
|
def coltohex(self, target):
|
||||||
|
colors = []
|
||||||
|
target = [target.r, target.g, target.b]
|
||||||
|
for i in target:
|
||||||
|
colors.append(("0"*(2-len(hex(i)[2:])))+hex(i)[2:])
|
||||||
|
out = ""
|
||||||
|
for i in colors:
|
||||||
|
out = out + i
|
||||||
|
return "#"+out
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self._win.update()
|
||||||
|
|
||||||
|
def pix(self, x, y, text, bcolor, fcolor):
|
||||||
|
if f"{x}:{y}" in self._grid:
|
||||||
|
self._grid[f"{x}:{y}"].config(text=text, bg=self.coltohex(bcolor), fg=self.coltohex(fcolor))
|
||||||
|
|
||||||
|
class color3:
|
||||||
|
def __init__(self, r=0, g=0, b=0):
|
||||||
|
self.r = r
|
||||||
|
self.g = g
|
||||||
|
self.b = b
|
||||||
|
self._type = "color3"
|
||||||
|
|
||||||
|
def __add__(self, v):
|
||||||
|
temp = color3(self.r+v.r, self.g+v.g, self.b+v.b)
|
||||||
|
temp.r = temp.r%255
|
||||||
|
temp.g = temp.g%255
|
||||||
|
temp.b = temp.b%255
|
||||||
|
return temp
|
||||||
|
|
||||||
|
def __sub__(self, v):
|
||||||
|
temp = color3(self.r-v.r, self.g-v.g, self.b-v.b)
|
||||||
|
temp.r = temp.r%255
|
||||||
|
temp.g = temp.g%255
|
||||||
|
temp.b = temp.b%255
|
||||||
|
return temp
|
||||||
|
|
||||||
|
def __mul__(self, v):
|
||||||
|
temp = color3(self.r*v.r, self.g*v.g, self.b*v.b)
|
||||||
|
temp.r = temp.r%255
|
||||||
|
temp.g = temp.g%255
|
||||||
|
temp.b = temp.b%255
|
||||||
|
return temp
|
||||||
|
|
||||||
|
def __iadd__(self, v):
|
||||||
|
temp = color3(self.r+v.r, self.g+v.g, self.b+v.b)
|
||||||
|
temp.r = temp.r%255
|
||||||
|
temp.g = temp.g%255
|
||||||
|
temp.b = temp.b%255
|
||||||
|
return temp
|
||||||
|
|
||||||
|
def __isub__(self, v):
|
||||||
|
temp = color3(self.r-v.r, self.g-v.g, self.b-v.b)
|
||||||
|
temp.r = temp.r%255
|
||||||
|
temp.g = temp.g%255
|
||||||
|
temp.b = temp.b%255
|
||||||
|
return temp
|
||||||
|
|
||||||
|
def __imul__(self, v):
|
||||||
|
temp = color3(self.r*v.r, self.g*v.g, self.b*v.b)
|
||||||
|
temp.r = temp.r%255
|
||||||
|
temp.g = temp.g%255
|
||||||
|
temp.b = temp.b%255
|
||||||
|
return temp
|
||||||
|
|
||||||
|
class vector2:
|
||||||
|
def __init__(self, x=0, y=0):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self._type = "vector2"
|
||||||
|
|
||||||
|
def _magnitude(self):
|
||||||
|
return abs(self.x+self.y)
|
||||||
|
|
||||||
|
def __add__(self, v):
|
||||||
|
return vector2(self.x+v.x, self.y+v.y)
|
||||||
|
|
||||||
|
def __sub__(self, v):
|
||||||
|
return vector2(self.x-v.x, self.y-v.y)
|
||||||
|
|
||||||
|
def __mul__(self, v):
|
||||||
|
return vector2(self.x*v.x, self.y*v.y)
|
||||||
|
|
||||||
|
def __iadd__(self, v):
|
||||||
|
return vector2(self.x+v.x, self.y+v.y)
|
||||||
|
|
||||||
|
def __isub__(self, v):
|
||||||
|
return vector2(self.x-v.x, self.y-v.y)
|
||||||
|
|
||||||
|
def __imul__(self, v):
|
||||||
|
return vector2(self.x*v.x, self.y*v.y)
|
||||||
|
|
||||||
|
class NULL:
|
||||||
|
def __init__(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
class enum:
|
||||||
|
def __init__(self, sel):
|
||||||
|
self._sel = dict(sel)
|
||||||
|
for i in self._sel:
|
||||||
|
setattr(self, i, self._sel[i])
|
||||||
|
|
||||||
|
def getposssel(self):
|
||||||
|
return list(self._sel.keys())
|
||||||
|
|
||||||
|
def loadsound(path):
|
||||||
|
with wave.open(path) as fd:
|
||||||
|
frames = fd.readframes(1000000000)
|
||||||
|
return frames
|
||||||
|
|
||||||
|
cammode = enum({"editable": 0, "follow": 1})
|
||||||
|
|
||||||
|
class event:
|
||||||
|
def __init__(self):
|
||||||
|
self._attached = []
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
threads = []
|
||||||
|
for i in self._attached:
|
||||||
|
temp = threading.Thread(target=i)
|
||||||
|
temp.start()
|
||||||
|
threads.append(temp)
|
||||||
|
return threads
|
||||||
|
|
||||||
|
def attach(self, target):
|
||||||
|
self._attached.append(target)
|
||||||
|
|
||||||
|
class obj:
|
||||||
|
def __init__(self):
|
||||||
|
self.position = vector2()
|
||||||
|
self.char = " "
|
||||||
|
self.ID = 0
|
||||||
|
self.gravity = 0
|
||||||
|
self.acceleration = vector2()
|
||||||
|
self.velocity = vector2()
|
||||||
|
self.friction = 0
|
||||||
|
self.collide = True
|
||||||
|
self.anchored = False
|
||||||
|
self.bcolor = color3(255, 255, 255)
|
||||||
|
self.fcolor = color3()
|
||||||
|
self._touching = event()
|
||||||
|
|
||||||
|
class model:
|
||||||
|
def __init__(self, objects):
|
||||||
|
self._objects = objects
|
||||||
|
self.ID = 0
|
||||||
|
|
||||||
|
class camera(obj):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.mode = cammode.editable
|
||||||
|
self.subject = None
|
||||||
|
self.collide = False
|
||||||
|
self.touch = False
|
||||||
|
self.char = " "
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
if self.mode == cammode.follow and self.subject:
|
||||||
|
self.position = self.subject.position
|
||||||
|
|
||||||
|
class seqobj:
|
||||||
|
def __init__(self, objects):
|
||||||
|
self._objects = objects
|
||||||
|
|
||||||
|
def moveby(self, pos):
|
||||||
|
for i in self._objects:
|
||||||
|
i.position += pos
|
||||||
|
|
||||||
|
class game:
|
||||||
|
def __init__(self, size=[10, 10], renderer=stdrend, sounddir=""):
|
||||||
|
if renderer == None: raise TypeError("Renderer class needed!")
|
||||||
|
self.sounds = {}
|
||||||
|
self.currentsounds = []
|
||||||
|
for i in os.listdir(sounddir):
|
||||||
|
if not "." in i: continue
|
||||||
|
if i.split(".")[1] != "wav": continue
|
||||||
|
self.sounds[i.split(".")[0]] = loadsound(sounddir+"/"+i)
|
||||||
|
self._size = size
|
||||||
|
self._objects = {}
|
||||||
|
self._SIDS = {}
|
||||||
|
self._SEQSIDS = {}
|
||||||
|
self.camera = camera()
|
||||||
|
self._renderer = renderer(size, self.camera)
|
||||||
|
self._threads = []
|
||||||
|
|
||||||
|
def getobjbySID(self, target):
|
||||||
|
return self._objects[self._SIDS[target]]
|
||||||
|
|
||||||
|
def getobjseqbySID(self, target):
|
||||||
|
out = []
|
||||||
|
for i in self._SEQSIDS[target]:
|
||||||
|
out.append(self._objects[i])
|
||||||
|
return seqobj(out)
|
||||||
|
|
||||||
|
def isdown(self, key):
|
||||||
|
temp = self._renderer.getkeys()
|
||||||
|
if key in temp:
|
||||||
|
return temp[key]
|
||||||
|
|
||||||
|
def collidingpos(self, pos, ignore):
|
||||||
|
out = []
|
||||||
|
for i in self._objects:
|
||||||
|
i = self._objects[i]
|
||||||
|
if i in ignore: continue
|
||||||
|
if (i.position-pos)._magnitude() < 1 and i.collide == True:
|
||||||
|
out.append(i)
|
||||||
|
return out
|
||||||
|
|
||||||
|
def colliding(self, target):
|
||||||
|
out = []
|
||||||
|
if target.collide == False: return []
|
||||||
|
out = self.collidingpos(target.position, [target,])
|
||||||
|
return out
|
||||||
|
|
||||||
|
def handlecollision(self, target: obj, target2: obj):
|
||||||
|
if target2.anchored == True:
|
||||||
|
target.velocity = vector2()
|
||||||
|
else:
|
||||||
|
half = vector2(target.velocity.x/2, target.velocity.y/2)
|
||||||
|
target.velocity = vector2(half.x, half.y)
|
||||||
|
target2.velocity = half
|
||||||
|
self._threads.extend(target._touching.execute())
|
||||||
|
self._threads.extend(target2._touching.execute())
|
||||||
|
|
||||||
|
def calcphysobj(self, target: obj):
|
||||||
|
opos = vector2(target.position.x, target.position.y)
|
||||||
|
collide = False
|
||||||
|
if target.anchored == True: return [opos, collide]
|
||||||
|
if target.collide == True:
|
||||||
|
colliding = self.collidingpos(target.position+target.velocity, [target,])
|
||||||
|
for i in colliding:
|
||||||
|
target._touching.execute()
|
||||||
|
i._touching.execute()
|
||||||
|
self.handlecollision(target, i)
|
||||||
|
collide = True
|
||||||
|
target.position += target.velocity
|
||||||
|
target.velocity += vector2(0, target.gravity)
|
||||||
|
target.velocity += target.acceleration
|
||||||
|
temp = 2
|
||||||
|
if target.friction != 0:
|
||||||
|
temp = 2 / target.friction
|
||||||
|
x = target.velocity.x
|
||||||
|
y = target.velocity.y
|
||||||
|
if x != 0:
|
||||||
|
x = x/temp
|
||||||
|
if y != 0:
|
||||||
|
y = y/temp
|
||||||
|
target.velocity = vector2(x, y)
|
||||||
|
return [opos, collide]
|
||||||
|
|
||||||
|
def calcphysmodel(self, target: model):
|
||||||
|
for i in target._objects:
|
||||||
|
self.calcphysobj(i)
|
||||||
|
|
||||||
|
def addobj(self, obj):
|
||||||
|
id = ""
|
||||||
|
for i in range(256):
|
||||||
|
id = id + random.choice(list(string.ascii_letters))
|
||||||
|
obj.ID = id
|
||||||
|
self._objects[id] = obj
|
||||||
|
|
||||||
|
def removeobj(self, obj):
|
||||||
|
self._objects.pop(obj.ID)
|
||||||
|
obj.ID = NULL()
|
||||||
|
|
||||||
|
def removeobjbyid(self, id):
|
||||||
|
self._objects.pop(id).ID = NULL()
|
||||||
|
|
||||||
|
def between(self, min, max, target):
|
||||||
|
if min < target < max: return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def getobjbyid(self, id):
|
||||||
|
return self._objects[id]
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
tochange = []
|
||||||
|
for x in range(self._size[0]):
|
||||||
|
for y in range(self._size[1]):
|
||||||
|
tochange.append((x, y))
|
||||||
|
#self._renderer.pix(x, y, " ", color3(255, 255, 255), color3(255, 255, 255))
|
||||||
|
for i in list(self._objects.values()):
|
||||||
|
if isinstance(i, obj):
|
||||||
|
pos = i.position + self.camera.position
|
||||||
|
if not self.between(-1, self._size[0], pos.x) or not self.between(-1, self._size[1], pos.y): continue#
|
||||||
|
pos = vector2(round(pos.x), round(pos.y))
|
||||||
|
self._renderer.pix(pos.x, pos.y, i.char, i.bcolor, i.fcolor)
|
||||||
|
if (pos.x, pos.y) in tochange: tochange.remove((pos.x, pos.y))
|
||||||
|
if isinstance(i, model):
|
||||||
|
for tobj in i._objects:
|
||||||
|
pos = tobj.position + self.camera.position
|
||||||
|
if not self.between(-1, self._size[0], pos.x) or not self.between(-1, self._size[1], pos.y): continue#
|
||||||
|
pos = vector2(round(pos.x), round(pos.y))
|
||||||
|
self._renderer.pix(pos.x, pos.y, tobj.char, tobj.bcolor, tobj.fcolor)
|
||||||
|
if (pos.x, pos.y) in tochange: tochange.remove((pos.x, pos.y))
|
||||||
|
for i in tochange:
|
||||||
|
self._renderer.pix(i[0], i[1], " ", color3(255, 255, 255), color3(255, 255, 255))
|
||||||
|
self._renderer.update()
|
||||||
|
|
||||||
|
def startscript(self, target):
|
||||||
|
temp = threading.Thread(target=target)
|
||||||
|
temp.start()
|
||||||
|
self._threads.append(temp)
|
||||||
|
|
||||||
|
def stopscripts(self):
|
||||||
|
for i in self._threads:
|
||||||
|
i.join(.0)
|
||||||
|
|
||||||
|
def stopsounds(self):
|
||||||
|
for i in self.currentsounds:
|
||||||
|
i.stop()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
testgame = game(sounddir="testsound")
|
||||||
|
object = obj()
|
||||||
|
object.char = "#"
|
||||||
|
object.anchored = False
|
||||||
|
object.position = vector2(5, 5)
|
||||||
|
object.gravity = 1
|
||||||
|
floor = obj()
|
||||||
|
floor.char = "#"
|
||||||
|
floor.anchored = True
|
||||||
|
floor.position = vector2(5, 9)
|
||||||
|
floor.gravity = 0
|
||||||
|
floor.bcolor = color3(255, 255, 255)
|
||||||
|
testgame.addobj(object)
|
||||||
|
testgame.addobj(floor)
|
||||||
|
testgame.render()
|
||||||
|
print(object.ID)
|
||||||
|
while True:
|
||||||
|
testgame.calcphysobj(object)
|
||||||
|
testgame.calcphysobj(floor)
|
||||||
|
testgame.render()
|
||||||
|
time.sleep(0)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
import player
|
||||||
|
import ast
|
||||||
|
file = open("game.HEGF", 'r')
|
||||||
|
file = file.read()
|
||||||
|
file = ast.literal_eval(file)
|
||||||
|
player.execgame(file)
|
|
@ -0,0 +1,230 @@
|
||||||
|
'''Thread-safe version of tkinter.
|
||||||
|
|
||||||
|
Copyright (c) 2014, Andrew Barnert
|
||||||
|
|
||||||
|
Based on mtTkinter (for Python 2.x), copyright (c) 2009, Allen B. Taylor
|
||||||
|
|
||||||
|
This module is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
import mttkinter as tkinter
|
||||||
|
# Use "t." as usual.
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
from mtt import *
|
||||||
|
# Use tkinter module definitions as usual.
|
||||||
|
|
||||||
|
This module modifies the original tkinter module in memory, making all
|
||||||
|
functionality thread-safe. It does this by wrapping the Tk class' tk
|
||||||
|
instance with an object that diverts calls through an event queue when
|
||||||
|
the call is issued from a thread other than the thread in which the Tk
|
||||||
|
instance was created. The events are processed in the creation thread
|
||||||
|
via an 'after' event.
|
||||||
|
|
||||||
|
The modified Tk class accepts two additional keyword parameters on its
|
||||||
|
__init__ method:
|
||||||
|
mtDebug:
|
||||||
|
0 = No debug output (default)
|
||||||
|
1 = Minimal debug output
|
||||||
|
...
|
||||||
|
9 = Full debug output
|
||||||
|
mtCheckPeriod:
|
||||||
|
Amount of time in milliseconds (default 100) between checks for
|
||||||
|
out-of-thread events when things are otherwise idle. Decreasing
|
||||||
|
this value can improve GUI responsiveness, but at the expense of
|
||||||
|
consuming more CPU cycles.
|
||||||
|
|
||||||
|
Note that, because it modifies the original tkinter module (in memory),
|
||||||
|
other modules that use tkinter (e.g., Pmw) reap the benefits automagically
|
||||||
|
as long as mttkinter is imported at some point before extra threads are
|
||||||
|
created.
|
||||||
|
|
||||||
|
Author: Allen B. Taylor, a.b.taylor@gmail.com
|
||||||
|
'''
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
if sys.version_info[0] == 2:
|
||||||
|
# Python 2
|
||||||
|
from Tkinter import *
|
||||||
|
import Queue as queue
|
||||||
|
else:
|
||||||
|
# Python 3
|
||||||
|
from tkinter import *
|
||||||
|
import queue
|
||||||
|
|
||||||
|
|
||||||
|
class _Tk(object):
|
||||||
|
"""Wrapper for underlying attribute tk of class Tk"""
|
||||||
|
|
||||||
|
def __init__(self, tk, mt_debug=0, mt_check_period=10):
|
||||||
|
"""
|
||||||
|
:param tk: Tkinter.Tk.tk Tk interpreter object
|
||||||
|
:param mt_debug: Determines amount of debug output.
|
||||||
|
0 = No debug output (default)
|
||||||
|
1 = Minimal debug output
|
||||||
|
...
|
||||||
|
9 = Full debug output
|
||||||
|
:param mt_check_period: Amount of time in milliseconds (default
|
||||||
|
10) between checks for out-of-thread events when things are
|
||||||
|
otherwise idle. Decreasing this value can improve GUI
|
||||||
|
responsiveness, but at the expense of consuming more CPU
|
||||||
|
cycles.
|
||||||
|
|
||||||
|
# TODO: Replace custom logging functionality with standard
|
||||||
|
# TODO: logging.Logger for easier access and standardization
|
||||||
|
"""
|
||||||
|
self._tk = tk
|
||||||
|
|
||||||
|
# Create the incoming event queue
|
||||||
|
self._event_queue = queue.Queue(1)
|
||||||
|
|
||||||
|
# Identify the thread from which this object is being created
|
||||||
|
# so we can tell later whether an event is coming from another
|
||||||
|
# thread.
|
||||||
|
self._creation_thread = threading.current_thread()
|
||||||
|
|
||||||
|
# Create attributes for kwargs
|
||||||
|
self._debug = mt_debug
|
||||||
|
self._check_period = mt_check_period
|
||||||
|
# Destroying flag to be set by the .destroy() hook
|
||||||
|
self._destroying = False
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
"""
|
||||||
|
Diverts attribute accesses to a wrapper around the underlying tk
|
||||||
|
object.
|
||||||
|
"""
|
||||||
|
return _TkAttr(self, getattr(self._tk, name))
|
||||||
|
|
||||||
|
|
||||||
|
class _TkAttr(object):
|
||||||
|
"""Thread-safe callable attribute wrapper"""
|
||||||
|
|
||||||
|
def __init__(self, tk, attr):
|
||||||
|
self._tk = tk
|
||||||
|
self._attr = attr
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Thread-safe method invocation. Diverts out-of-thread calls
|
||||||
|
through the event queue. Forwards all other method calls to the
|
||||||
|
underlying tk object directly.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Check if we're in the creation thread
|
||||||
|
if threading.current_thread() == self._tk._creation_thread:
|
||||||
|
# We're in the creation thread; just call the event directly
|
||||||
|
if self._tk._debug >= 8 or \
|
||||||
|
self._tk._debug >= 3 and self._attr.__name__ == 'call' and \
|
||||||
|
len(args) >= 1 and args[0] == 'after':
|
||||||
|
print('Calling event directly:', self._attr.__name__, args, kwargs)
|
||||||
|
return self._attr(*args, **kwargs)
|
||||||
|
else:
|
||||||
|
if not self._tk._destroying:
|
||||||
|
# We're in a different thread than the creation thread;
|
||||||
|
# enqueue the event, and then wait for the response.
|
||||||
|
response_queue = queue.Queue(1)
|
||||||
|
if self._tk._debug >= 1:
|
||||||
|
print('Marshalling event:', self._attr.__name__, args, kwargs)
|
||||||
|
self._tk._event_queue.put((self._attr, args, kwargs, response_queue), True, 1)
|
||||||
|
is_exception, response = response_queue.get(True, None)
|
||||||
|
|
||||||
|
# Handle the response, whether it's a normal return value or
|
||||||
|
# an exception.
|
||||||
|
if is_exception:
|
||||||
|
ex_type, ex_value, ex_tb = response
|
||||||
|
raise ex_type(ex_value, ex_tb)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def _Tk__init__(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Hook for Tkinter.Tk.__init__ method
|
||||||
|
:param self: Tk instance
|
||||||
|
:param args, kwargs: Arguments for Tk initializer
|
||||||
|
"""
|
||||||
|
# We support some new keyword arguments that the original __init__ method
|
||||||
|
# doesn't expect, so separate those out before doing anything else.
|
||||||
|
new_kwnames = ('mt_check_period', 'mt_debug')
|
||||||
|
new_kwargs = {
|
||||||
|
kw_name: kwargs.pop(kw_name) for kw_name in new_kwnames
|
||||||
|
if kwargs.get(kw_name, None) is not None
|
||||||
|
}
|
||||||
|
|
||||||
|
# Call the original __init__ method, creating the internal tk member.
|
||||||
|
self.__original__init__mtTkinter(*args, **kwargs)
|
||||||
|
|
||||||
|
# Replace the internal tk member with a wrapper that handles calls from
|
||||||
|
# other threads.
|
||||||
|
self.tk = _Tk(self.tk, **new_kwargs)
|
||||||
|
|
||||||
|
# Set up the first event to check for out-of-thread events.
|
||||||
|
self.after_idle(_check_events, self)
|
||||||
|
|
||||||
|
|
||||||
|
# Define a hook for class Tk's destroy method.
|
||||||
|
def _Tk_destroy(self):
|
||||||
|
self.tk._destroying = True
|
||||||
|
self.__original__destroy()
|
||||||
|
|
||||||
|
|
||||||
|
def _check_events(tk):
|
||||||
|
"""Checks events in the queue on a given Tk instance"""
|
||||||
|
|
||||||
|
used = False
|
||||||
|
try:
|
||||||
|
# Process all enqueued events, then exit.
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
# Get an event request from the queue.
|
||||||
|
method, args, kwargs, response_queue = tk.tk._event_queue.get_nowait()
|
||||||
|
except queue.Empty:
|
||||||
|
# No more events to process.
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# Call the event with the given arguments, and then return
|
||||||
|
# the result back to the caller via the response queue.
|
||||||
|
used = True
|
||||||
|
if tk.tk._debug >= 2:
|
||||||
|
print('Calling event from main thread:', method.__name__, args, kwargs)
|
||||||
|
try:
|
||||||
|
response_queue.put((False, method(*args, **kwargs)))
|
||||||
|
except SystemExit:
|
||||||
|
raise # Raises original SystemExit
|
||||||
|
except Exception:
|
||||||
|
# Calling the event caused an exception; return the
|
||||||
|
# exception back to the caller so that it can be raised
|
||||||
|
# in the caller's thread.
|
||||||
|
from sys import exc_info # Python 2 requirement
|
||||||
|
ex_type, ex_value, ex_tb = exc_info()
|
||||||
|
response_queue.put((True, (ex_type, ex_value, ex_tb)))
|
||||||
|
finally:
|
||||||
|
# Schedule to check again. If we just processed an event, check
|
||||||
|
# immediately; if we didn't, check later.
|
||||||
|
if used:
|
||||||
|
tk.after_idle(_check_events, tk)
|
||||||
|
else:
|
||||||
|
tk.after(tk.tk._check_period, _check_events, tk)
|
||||||
|
|
||||||
|
|
||||||
|
"""Perform in-memory modification of Tkinter module"""
|
||||||
|
# Replace Tk's original __init__ with the hook.
|
||||||
|
Tk.__original__init__mtTkinter = Tk.__init__
|
||||||
|
Tk.__init__ = _Tk__init__
|
||||||
|
|
||||||
|
# Replace Tk's original destroy with the hook.
|
||||||
|
Tk.__original__destroy = Tk.destroy
|
||||||
|
Tk.destroy = _Tk_destroy
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
||||||
|
[[{'id': 'obj', 'name': 'Objekt', 'SID': 'cUwnltshBNeQQFvuwfXuUzsaHaJKyxSqwztnBteAIHrqzsOgEljfWOOGmzgCLgsuYxfyTyMehQXFcQWHCLmBWCMAPieboGymJOoNPKboUUtSuJUvjLLFYycsukzeHVBGcIUfZzJBJYUoFVTBhYKuLqYpwWrIWrEdUPjPpXUhKGEuolPGBHYmativzBekLKGEEKvpIWvPQoDhoAzVZaevzQAisacPettAjoEynVhDkSUggmsTjXqqutysffacbzD', 'args': {'anchored': True, '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': 5, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}, {'id': 'obj', 'name': 'Objekt', 'SID': 'kzjhJQJZTwwBnsqFbMMWwoubynoPJVuFLPGlTMODHNbtIkqmYlCdwDQAgXEGrNemqizGeVajNuLScIftEjGfMgUVhFPYdXFDkKdyHJVdTascWZDJmZPmhTSiYWhnsvONfVvmHOmVeJrwHgjeHgDChAEkDXrDLbhoqVkpVvNaQgpecMqHaojBRGqlaDysXUYBSILmzOHbsllKaPxyPeGWNDTQkViUqdfPmfAYknybhPcGowVWzPaIijmbkFxYxyZ', 'args': {'anchored': True, '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': 1, 'y': 5, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}, {'id': 'obj', 'name': 'Objekt', 'SID': 'ypuYPxrQJbjLqPCIRSUjaSLKTjYRWFkldnHeHzaDuqTFcKbAVuqmKwadBqCrCyoNarxWlSCzIeeBpTIUCXNGWbMKtsmIsxUawwictmxqSRDwZyOdeqPYeMEeJaxwbpIovYpbHvbMglAfaOnQCXKqfStBXYURpfxUCrzDVnJzJMbuxWVHksdZQSjhChZTVAZrSChBrRQhkYCnsJqwxhEzrhjZgWIgaGopmAgQZnFFtQltSVovxbqvvTkquUEdswM', 'args': {'anchored': True, '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': 2, 'y': 5, 'ARGID': 'vector2'}, 'velocity': {'x': 0, 'y': 0, 'ARGID': 'vector2'}}}, {'id': 'script', 'name': 'Skript', 'SID': 'nWvowGAstSdSoUbpAoSoXlogKgfAApqyiiCEcfcEOUnCvthUiozkobNUlUNbiBdrzKdajEXAkrHbwQtGMExMWpDYoXRUVecdfvGYntJnKYdviiXSdcrsoTldVBOBQUgWylLBysTmVipXvBtyjOXOtvgrOqKWcdRjRNRhXqdNBRwCBrbpfHVxJIbGIttQZFYoypouuYexsLAwDtxlJdhZhYYpyQJTpJtGmLVFNcnJWUYejTDanpUfCVJZkfbRLXC', 'args': {'code': 'import time\nobj = HASHGAME.getobjseqbySID("cUwnlkzjhJypuYP")\ntime.sleep(3)\nobj.moveby(HASHBASE.vector2(0, 3))'}}], {'Erstellte Objekte': [0, 1, 2]}]
|
Loading…
Reference in New Issue