plugin system update
parent
c30eeba0f2
commit
18b8ee5554
42
main.py
42
main.py
|
@ -73,8 +73,8 @@ global cooldown
|
|||
global version
|
||||
global plugindir
|
||||
version = "HE2.2-Hashengine V2.2"
|
||||
#plugindir = "plugins"
|
||||
plugindir = "testplugins"
|
||||
plugindir = "plugins"
|
||||
#plugindir = "testplugins"
|
||||
cooldown = False
|
||||
gamedata = {}
|
||||
|
||||
|
@ -689,12 +689,13 @@ def testing():
|
|||
global running
|
||||
global clog
|
||||
global APIPLUG
|
||||
global RUNPLUG
|
||||
try:
|
||||
if running == True: return
|
||||
except:
|
||||
pass
|
||||
running = True
|
||||
testproc = multiprocessing.Process(target=execgame, args=(prepspecified(gamedata), clog.get(), APIPLUG))
|
||||
testproc = multiprocessing.Process(target=execgame, args=(prepspecified(gamedata), clog.get(), APIPLUG, RUNPLUG))
|
||||
testproc.start()
|
||||
|
||||
def APIGEN():
|
||||
|
@ -778,6 +779,10 @@ def run():
|
|||
#gameloopsc = script()
|
||||
#gameloopsc.code = gamescript
|
||||
#maingame.startscript(lambda: gameloopsc.execute(APIGEN(), log))
|
||||
log("executing plugins")
|
||||
for i in RUNPLUG:
|
||||
exec(i, globals())
|
||||
log("done")
|
||||
log("game test started!!!")
|
||||
log("---------------------")
|
||||
for i in scripts:
|
||||
|
@ -831,10 +836,12 @@ import ast
|
|||
file = open("game.HEGF", 'r')
|
||||
file = file.read()
|
||||
file = ast.literal_eval(file)
|
||||
player.execgame(file, fAPIPLUG=player.loadplugins(False))
|
||||
temp = fAPIPLUG=player.loadplugins(False)
|
||||
player.execgame(file, fAPIPLUG=temp[0], fRUNPLUG=temp[1])
|
||||
""")
|
||||
print("done.")
|
||||
print("building finished!")
|
||||
messagebox.showinfo(LH.string("done"), LH.string("suc"))
|
||||
|
||||
def importPS():
|
||||
target = filedialog.askopenfile()
|
||||
|
@ -948,15 +955,18 @@ def ungridobjtrees():
|
|||
def loadplugins(GUIe=True):
|
||||
global APIPLUG
|
||||
for pluginname in os.listdir(plugindir):
|
||||
file = open(plugindir+"/"+pluginname, 'r')
|
||||
plugindata = file.read()
|
||||
plugindata = ast.literal_eval(plugindata)
|
||||
file.close()
|
||||
if "init" in plugindata and GUIe == True:
|
||||
exec(plugindata["init"], globals())
|
||||
if "API" in plugindata:
|
||||
APIPLUG.append(plugindata["API"])
|
||||
return APIPLUG
|
||||
if pluginname.split(".")[1] == "plg":
|
||||
file = open(plugindir+"/"+pluginname, 'r')
|
||||
plugindata = file.read()
|
||||
plugindata = ast.literal_eval(plugindata)
|
||||
file.close()
|
||||
if "init" in plugindata and GUIe == True:
|
||||
exec(plugindata["init"], globals())
|
||||
if "API" in plugindata:
|
||||
APIPLUG.append(plugindata["API"])
|
||||
if "run" in plugindata:
|
||||
RUNPLUG.append(plugindata["run"])
|
||||
return [APIPLUG, RUNPLUG]
|
||||
|
||||
def GUIinit():
|
||||
global container
|
||||
|
@ -1170,13 +1180,15 @@ def aposy(old):
|
|||
return old
|
||||
return tempvar
|
||||
|
||||
def execgame(gametree, shouldlog=True, fAPIPLUG=[]):
|
||||
def execgame(gametree, shouldlog=True, fAPIPLUG=[], fRUNPLUG=[]):
|
||||
global GUIe
|
||||
global preview
|
||||
global clog
|
||||
global models
|
||||
global APIPLUG
|
||||
global RUNPLUG
|
||||
APIPLUG = fAPIPLUG
|
||||
RUNPLUG = fRUNPLUG
|
||||
preview = hashengine.game(renderer=nullrend, sounddir="/")
|
||||
GUIe = False
|
||||
models = []
|
||||
|
@ -1214,6 +1226,8 @@ global DCTE
|
|||
global gamexsize
|
||||
global gameysize
|
||||
global APIPLUG
|
||||
global RUNPLUG
|
||||
RUNPLUG = []
|
||||
APIPLUG = []
|
||||
gamexsize = 10
|
||||
gameysize = 10
|
||||
|
|
|
@ -1 +1 @@
|
|||
[[{'id': 'script', 'name': 'Skript', 'SID': 'pESBBUtxhoOcWqInhNTdqqqxonEoVbvhJQjHsuSCvsKorTpsPXvWbfElhVTeFmwSZPkFdgBQIoeHNfiBmqXjnRzeIIyokRTJtXXeSyIkxyWqYDOnwNWnVFtWXWoLPJkfcxLFKNJvdClNbgEcZNWJOqgPbTfunPEFeXzUyFYZadEeCIndNkYhWNjaZkIhhEKvdgVCjrLjmpbosAvOeSlhxEyTfJnrBgJgMSMeJOSPQRuMQMwZgjyCSldZtPJuiXA', 'args': {'code': 'from tkinter import messagebox\nmessagebox.showinfo(plugin, plugin)'}}], {}, 10, 10]
|
||||
[[], {}, 10, 10]
|
|
@ -4,4 +4,5 @@ import ast
|
|||
file = open("game.HEGF", 'r')
|
||||
file = file.read()
|
||||
file = ast.literal_eval(file)
|
||||
player.execgame(file, fAPIPLUG=player.loadplugins(False))
|
||||
temp = fAPIPLUG=player.loadplugins(False)
|
||||
player.execgame(file, fAPIPLUG=temp[0], fRUNPLUG=temp[1])
|
||||
|
|
|
@ -689,12 +689,13 @@ def testing():
|
|||
global running
|
||||
global clog
|
||||
global APIPLUG
|
||||
global RUNPLUG
|
||||
try:
|
||||
if running == True: return
|
||||
except:
|
||||
pass
|
||||
running = True
|
||||
testproc = multiprocessing.Process(target=execgame, args=(prepspecified(gamedata), clog.get(), APIPLUG))
|
||||
testproc = multiprocessing.Process(target=execgame, args=(prepspecified(gamedata), clog.get(), APIPLUG, RUNPLUG))
|
||||
testproc.start()
|
||||
|
||||
def APIGEN():
|
||||
|
@ -705,7 +706,6 @@ def APIGEN():
|
|||
for i in APIPLUG:
|
||||
exec(i, globals())
|
||||
temp = globals()["PLUGINAPIFUNC"]()
|
||||
print(temp)
|
||||
API.update(temp)
|
||||
return API
|
||||
|
||||
|
@ -779,6 +779,10 @@ def run():
|
|||
#gameloopsc = script()
|
||||
#gameloopsc.code = gamescript
|
||||
#maingame.startscript(lambda: gameloopsc.execute(APIGEN(), log))
|
||||
log("executing plugins")
|
||||
for i in RUNPLUG:
|
||||
exec(i, globals())
|
||||
log("done")
|
||||
log("game test started!!!")
|
||||
log("---------------------")
|
||||
for i in scripts:
|
||||
|
@ -832,7 +836,8 @@ import ast
|
|||
file = open("game.HEGF", 'r')
|
||||
file = file.read()
|
||||
file = ast.literal_eval(file)
|
||||
player.execgame(file, fAPIPLUG=player.loadplugins(False))
|
||||
temp = fAPIPLUG=player.loadplugins(False)
|
||||
player.execgame(file, fAPIPLUG=temp[0], fRUNPLUG=temp[1])
|
||||
""")
|
||||
print("done.")
|
||||
print("building finished!")
|
||||
|
@ -957,7 +962,9 @@ def loadplugins(GUIe=True):
|
|||
exec(plugindata["init"], globals())
|
||||
if "API" in plugindata:
|
||||
APIPLUG.append(plugindata["API"])
|
||||
return APIPLUG
|
||||
if "run" in plugindata:
|
||||
RUNPLUG.append(plugindata["run"])
|
||||
return [APIPLUG, RUNPLUG]
|
||||
|
||||
def GUIinit():
|
||||
global container
|
||||
|
@ -1062,7 +1069,7 @@ def GUIinit():
|
|||
menu.add_cascade(label=LH.string("langs"), menu=langmenu)
|
||||
for i in LH.getlangs():
|
||||
langmenu.add_command(label=i, command=lambda i=i: selectlang(i))
|
||||
|
||||
loadplugins()
|
||||
container.mainloop()
|
||||
|
||||
# attribute changers
|
||||
|
@ -1171,13 +1178,15 @@ def aposy(old):
|
|||
return old
|
||||
return tempvar
|
||||
|
||||
def execgame(gametree, shouldlog=True, fAPIPLUG=[]):
|
||||
def execgame(gametree, shouldlog=True, fAPIPLUG=[], fRUNPLUG=[]):
|
||||
global GUIe
|
||||
global preview
|
||||
global clog
|
||||
global models
|
||||
global APIPLUG
|
||||
global RUNPLUG
|
||||
APIPLUG = fAPIPLUG
|
||||
RUNPLUG = fRUNPLUG
|
||||
preview = hashengine.game(renderer=nullrend, sounddir="/")
|
||||
GUIe = False
|
||||
models = []
|
||||
|
@ -1215,6 +1224,8 @@ global DCTE
|
|||
global gamexsize
|
||||
global gameysize
|
||||
global APIPLUG
|
||||
global RUNPLUG
|
||||
RUNPLUG = []
|
||||
APIPLUG = []
|
||||
gamexsize = 10
|
||||
gameysize = 10
|
||||
|
|
|
@ -13,4 +13,8 @@ addmenu = tk.Menu(menu)
|
|||
menu.add_cascade(label="exampleplugin", menu=addmenu)
|
||||
addmenu.add_command(label="NULL", command=print())
|
||||
""",
|
||||
"run": """
|
||||
from tkinter import messagebox
|
||||
messagebox.showinfo("PLUGIN TEST", "PLUGIN TEST")
|
||||
""",
|
||||
}
|
|
@ -13,4 +13,8 @@ addmenu = tk.Menu(menu)
|
|||
menu.add_cascade(label="exampleplugin", menu=addmenu)
|
||||
addmenu.add_command(label="NULL", command=print())
|
||||
""",
|
||||
"run": """
|
||||
from tkinter import messagebox
|
||||
messagebox.showinfo("PLUGIN TEST", "PLUGIN TEST")
|
||||
""",
|
||||
}
|
Loading…
Reference in New Issue