diff --git a/main.py b/main.py index 38e173c..3e21125 100644 --- a/main.py +++ b/main.py @@ -709,10 +709,12 @@ def testing(): def APIGEN(): global APIPLUG global maingame + global savpreviewe API = {"print": log, "HASHBASE": hashengine} API["HASHGAME"] = maingame API["SOUND"] = lambda data: gsound(data, maingame) API["PATHFIND"] = hashengine.pathfinding(maingame._size, list(maingame._objects.values()), maingame) + API["SAVMANG"] = savemanager(savpreviewe) for i in APIPLUG: exec(i, globals()) temp = globals()["PLUGINAPIFUNC"]() @@ -846,7 +848,7 @@ file = open("game.HEGF", 'r') file = file.read() temp = loadplugins(False) replacelh() -execgame(file, False, fAPIPLUG=temp[0], fRUNPLUG=temp[1]) +execgame(file, False, fAPIPLUG=temp[0], fRUNPLUG=temp[1], False) """) print("done.") print("building finished!") @@ -1246,13 +1248,15 @@ def aposy(old): if str(tempvar).split(".")[1] == "0": return int(tempvar) return tempvar -def execgame(gametree, shouldlog=True, fAPIPLUG=[], fRUNPLUG=[]): +def execgame(gametree, shouldlog=True, fAPIPLUG=[], fRUNPLUG=[], savpreview=True): global GUIe global preview global clog global models global APIPLUG global RUNPLUG + global savpreviewe + savpreviewe = savpreview APIPLUG = fAPIPLUG RUNPLUG = fRUNPLUG preview = hashengine.game(renderer=nullrend, sounddir="/") @@ -1295,6 +1299,24 @@ class sound(): self.spath = os.path.basename(new).split(".")[0] self.sdata = hashengine.loadsound(new) +class savemanager: + def __init__(self, preview=False): + self.preview = preview + self.savefile = "HESF" + self.temp = {} + + def get(self): + if self.preview == True: return self.temp + return ast.literal_eval(open(self.savefile, 'r').read()) + + def save(self, new): + if self.preview == True: + self.temp = new + return + file = open(self.savefile, 'w') + file.write(str(new)) + file.close() + global types global ignoreat global valtypes diff --git a/scriptingdocumentation.md b/scriptingdocumentation.md index 7005b97..6f8befc 100644 --- a/scriptingdocumentation.md +++ b/scriptingdocumentation.md @@ -77,3 +77,8 @@ to stop the sound use \.stop() and to yield until the sound is done playi Hashengine has an built pathfinding system (A*). to use it, use PATHFIND.find_path(\, \). it returns an list of vector2's representing every single waypoint. +## SAVMANG + +### the save manager also called in the API **SAVMANG** is used for save data + +**SAVMANG** is used for saving user save data. use SAVMANG.get() to get the current save data and SAVEMANG.set(\) to override the save data. when using it within a script in test mode, it will save in a temporary dictionary which is NOT shared amongst scripts.