diff --git a/hashengine.py b/hashengine.py index 9609471..1babb8c 100644 --- a/hashengine.py +++ b/hashengine.py @@ -4,13 +4,8 @@ class game(): import sys import subprocess import pkg_resources - import os print("initializing hashengine and installing dependencies if missing") - self.linecount = 0 - if os.name == 'nt': - required = {'sounddevice', 'soundfile', 'windows-curses'} - else: - required = {'sounddevice', 'soundfile'} + required = {'keyboard', 'sounddevice', 'soundfile'} installed = {pkg.key for pkg in pkg_resources.working_set} missing = required - installed @@ -21,14 +16,21 @@ class game(): print(i) subprocess.check_call([python, '-m', 'pip', 'install', i], stdout=sys.stdout) print("done") + import os + import ctypes import string + def isAdmin(): + try: + is_admin = (os.getuid() == 0) + except AttributeError: + is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 + return is_admin + if not isAdmin(): + print("error: hashengine needs to be run as an admin") + input("enter to continue...") + exit() self.osmodule = __import__("os") - import curses - self.screen = curses.initscr() - self.screen.nodelay(1) - self.screen.keypad(True) - curses.noecho() - curses.endwin() + self.keyboard = __import__("keyboard") try: self.sounddevice = __import__("sounddevice") except OSError: @@ -52,52 +54,19 @@ class game(): self.map["{}:{}".format(i, f)] = " " self.objects = [] - + def round2(self, target): from decimal import localcontext, Decimal, ROUND_HALF_UP with localcontext() as ctx: ctx.rounding = ROUND_HALF_UP return Decimal(target).to_integral_value() - - def getobjbypos(self, x, y): - for i in self.objects: - if i.x == x and i.y == y: - return i - return False - - def setobj(self, obj, x, y): - for i in range(len(self.objects)): - index = i - i = self.objects[i] - if i.x == x and i.y == y: - self.objects[index] = obj - - def calculateupobj(self, y, x, velocity): - import curses - import time - curses.endwin() - velocity = abs(velocity) - if y >= 2 and y < self.size.lines: - if self.getobjbypos(x, y) != False: - print("y: {}, x: {}, velocity: {}".format(y, x, velocity)) - obj = self.getobjbypos(x, y) - obj.y += velocity - self.calculateupobj(obj.y+(-abs(velocity))-1, obj.x, velocity) - return - else: - return def update(self): - import curses - curses.noecho() - curses.endwin() - temp = self.screen.getch() for i in self.pressedkeys: - if temp == ord(i): + if self.keyboard.is_pressed(i): self.pressedkeys[i] = True else: self.pressedkeys[i] = False - curses.flushinp() self.futuremap = self.map.copy() for i in self.objects: @@ -118,10 +87,8 @@ class game(): if "{}:{}".format(self.round2(i.y-i.yvelocity), self.round2(i.x)) in self.map: if self.map["{}:{}".format(self.round2(i.y-i.yvelocity), self.round2(i.x))] == " ": i.y -= i.yvelocity - self.calculateupobj(i.y+(-abs(i.yvelocity))-1, i.x, i.yvelocity) else: i.y -= i.yvelocity - self.calculateupobj(i.y+(-abs(i.yvelocity))-1, i.x, i.yvelocity) else: i.y = i.targety i.targety = None @@ -191,6 +158,33 @@ class game(): self.sounddevice.wait() else: return + + def getattributes(self, target): + import inspect + temp = [] + for i in inspect.getmembers(target): + if not i[0].startswith('_'): + if not inspect.ismethod(i[1]): + temp.append(i) + return temp + + def convertgametostring(self): + temp = [] + for i in self.objects: + temp.append(self.getattributes(i)) + return str(temp) + + def loadgamestring(self, target, clearexisting=True): + import ast + target = ast.literal_eval(target) + if clearexisting: + self.objects = [] + for i in target: + temp = object("#") + for f in i: + temp.__setattr__(f[0], f[1]) + self.addobj(temp) + class object(): def __init__(self, character, gravity=0.1, x=0, y=0, antixforce=0.1): @@ -234,5 +228,4 @@ if __name__ == "__main__": box.xvelocity = -1 elif "q" in keys and keys["q"] == True: exit() - time.sleep(0.01) - + time.sleep(0.05) diff --git a/plugincompiler.py b/plugincompiler.py new file mode 100644 index 0000000..75c5edc --- /dev/null +++ b/plugincompiler.py @@ -0,0 +1,26 @@ +file = open("targetplugin.py", 'r') +file = file.readlines() +name = input("name: ") +plugin = {} +plugin["name"] = name +tempbefore = "" +tempafter = "" +set = "" +for i in file: + if i == "#before\n": + set = "before" + elif i == "#after\n": + set = "after" + else: + if set == "before": + i = i.replace('"', "'") + tempbefore = tempbefore + i + if set == "after": + i = i.replace('"', "'") + tempafter = tempafter + i +plugin["main"] = {} +plugin["main"]["onupdatebefore"] = tempbefore +plugin["main"]["onupdateafter"] = tempafter +file = open("outplugin.plugin", 'w') +file.write(str(plugin)) +file.close() diff --git a/targetplugin.py b/targetplugin.py new file mode 100644 index 0000000..b65a546 --- /dev/null +++ b/targetplugin.py @@ -0,0 +1,2 @@ +#before +#after \ No newline at end of file