class TypingHandler(): def __init__(self, keyboard): self.oP = OutPipe("TypingHandler", 0) self.eI = EngineInterface() self.keyboard = keyboard self.letters = { self.eI.e.AKEY: "a", self.eI.e.BKEY: "b", self.eI.e.CKEY: "c", self.eI.e.DKEY: "d", self.eI.e.EKEY: "e", self.eI.e.FKEY: "f", self.eI.e.GKEY: "g", self.eI.e.HKEY: "h", self.eI.e.IKEY: "i", self.eI.e.JKEY: "j", self.eI.e.KKEY: "k", self.eI.e.LKEY: "l", self.eI.e.MKEY: "m", self.eI.e.NKEY: "n", self.eI.e.OKEY: "o", self.eI.e.PKEY: "p", self.eI.e.QKEY: "q", self.eI.e.RKEY: "r", self.eI.e.SKEY: "s", self.eI.e.TKEY: "t", self.eI.e.UKEY: "u", self.eI.e.VKEY: "v", self.eI.e.WKEY: "w", self.eI.e.XKEY: "x", self.eI.e.YKEY: "y", self.eI.e.ZKEY: "z", } self.specials = { self.eI.e.ZEROKEY: "0", self.eI.e.ONEKEY: "1", self.eI.e.TWOKEY: "2", self.eI.e.THREEKEY: "3", self.eI.e.FOURKEY: "4", self.eI.e.FIVEKEY: "5", self.eI.e.SIXKEY: "6", self.eI.e.SEVENKEY: "7", self.eI.e.EIGHTKEY: "8", self.eI.e.NINEKEY: "9", self.eI.e.ACCENTGRAVEKEY: "`", self.eI.e.BACKSLASHKEY: "\\", self.eI.e.COMMAKEY: ",", self.eI.e.EQUALKEY: "=", self.eI.e.LEFTBRACKETKEY: "[", self.eI.e.MINUSKEY: "-", self.eI.e.PERIODKEY: ".", self.eI.e.QUOTEKEY: "'", self.eI.e.RIGHTBRACKETKEY: "]", self.eI.e.SEMICOLONKEY: ";", self.eI.e.SLASHKEY: "/", self.eI.e.SPACEKEY: " ", } self.oP("Initialized.") def process(self): scene = self.eI.getOverlayScene() for obj in scene.objects: if "Text" in obj and "TextEntry" in obj: if obj["TextEntry"]: self.enterText(obj) def enterText(self, obj): oldText = obj["Text"] newText = oldText for keycode in self.keyboard.active_events.keys(): if self.keyboard.active_events[ keycode] == self.eI.l.KX_INPUT_JUST_ACTIVATED: if keycode in self.letters.keys(): letter = self.letters[keycode] if self.caps(): letter = letter.upper() newText += letter elif keycode in self.specials.keys(): letter = self.specials[keycode] newText += letter elif keycode == self.eI.e.BACKSPACEKEY: newText = newText[:len(newText) - 1] obj["Text"] = newText def caps(self): return self.eI.e.RIGHTSHIFTKEY in self.keyboard.active_events.keys( ) or self.eI.e.LEFTSHIFTKEY in self.keyboard.active_events.keys( ) or self.eI.e.CAPSLOCKKEY in self.keyboard.active_events.keys()
class Launcher(): def __init__(self): #Remove engine log try: os.remove(ENGINE_PATH + "engine_log" + TEXT_EXT) except: pass #Remove net logs try: for i in os.listdir(NET_PATH): os.remove(NET_PATH + i) except: pass #Create net path try: os.mkdir(NET_PATH) except: pass self.oP = OutPipe("Launcher", 0) for line in self.getSystemInfo(): self.oP(line) self.cR = ConfigReader(ENGINE_PATH + "engine") self.sE = ScriptExecuter() self.eI = EngineInterface() self.eI.preLoad() self.eI.preLoadEpi() #Sloppy, removes the blacker that covers up starting glitches self.eI.getOverlayScene().objects["BlackScreen"].endObject() self.sound = SoundEngine() self.sound.preLoadAudio() self.s = None self.c = None self.output = True self.oP("Initialized.") def enableShader(self, index, text): self.oP("Activating shader pass #%i" % index) controller = bge.logic.getCurrentController() filterActuator = controller.actuators["filter"] filterActuator.mode = bge.logic.RAS_2DFILTER_CUSTOMFILTER filterActuator.passNumber = index filterActuator.shaderText = text controller.activate(filterActuator) controller.deactivate(filterActuator) def disableShader(self, index): self.oP("Deactivating shader pass #%i" % index) controller = bge.logic.getCurrentController() filterActuator = controller.actuators["filter"] filterActuator.mode = bge.logic.RAS_2DFILTER_DISABLED filterActuator.passNumber = index controller.activate(filterActuator) controller.deactivate(filterActuator) def bootSystem(self): self.output = int(self.cR.get("LAUNCHER", "la_output")) dedicated = int(self.cR.get("LAUNCHER", "la_dedicated")) if dedicated: lobby = int(self.cR.get("LAUNCHER", "la_dedicated_fast")) self.bootServer() self.s.configure("sv_game", lobby) self.s.configure("sv_dedicated", 1) else: self.bootClient() def getSystemInfo(self): f = open(ENGINE_PATH + "system" + TEXT_EXT, "r") try: data = eval(f.read()) return [ "EpiEngine v%.2f" % data["version"], "Built for BGE %.2f" % data["targetVersion"], "Running %s %.2f" % (data["game"], data["gameVersion"]), "Built %s" % data["date"], ] except: return "EpiEngine launching." f.close() def bootClient(self): self.c = Client() #self.sE.addContext("Client", self.c) #self.sE.execute(bootScript) for option in self.cR.getAllOptions("CLIENT"): self.c.configure(option, self.cR.get("CLIENT", option)) def bootServer(self): #bootScript = self.cR.get("SERVER", "sv_startscript") #addr = self.cR.get("SERVER", "sv_addr") #port = self.cR.get("SERVER", "sv_port") self.s = Server() #self.sE.addContext("Server", self.s) #self.sE.execute(bootScript) # #self.s.configure("sv_addr", addr) #self.s.configure("sv_port", int(port)) for option in self.cR.getAllOptions("SERVER"): self.s.configure(option, self.cR.get("SERVER", option)) def configureServer(self, level, gamemode): if self.s: self.s.configure("level", level) self.s.configure("gamemode", gamemode) def loop(self): self.sound.loop() try: if hasattr(self.c, "loop"): self.c.loop() except: self.oP("Failure in client loop: %s" % str(traceback.format_exc())) try: if hasattr(self.s, "loop"): self.s.loop() except: self.oP("Failure in server loop: %s" % str(traceback.format_exc())) def pushConsoleCommand(self, command): if hasattr(self, "s") and self.s: self.s.pushConsoleCommand(command) if hasattr(self, "c") and self.c: self.c.pushConsoleCommand(command)