def load(self): # update the parameters in the parameters classes: Knows, Settings # Knows for param in self.params['Knows']: if isKnows(param) and hasattr(Knows, param): setattr( Knows, param, SMBool(self.params['Knows'][param][0], self.params['Knows'][param][1], ['{}'.format(param)])) # Settings ## hard rooms for hardRoom in ['X-Ray', 'Gauntlet']: if hardRoom in self.params['Settings']: Settings.hardRooms[hardRoom] = Settings.hardRoomsPresets[ hardRoom][self.params['Settings'][hardRoom]] ## bosses for boss in ['Kraid', 'Phantoon', 'Draygon', 'Ridley', 'MotherBrain']: if boss in self.params['Settings']: Settings.bossesDifficulty[ boss] = Settings.bossesDifficultyPresets[boss][ self.params['Settings'][boss]] ## hellruns for hellRun in ['Ice', 'MainUpperNorfair', 'LowerNorfair']: if hellRun in self.params['Settings']: Settings.hellRuns[hellRun] = Settings.hellRunPresets[hellRun][ self.params['Settings'][hellRun]] # Controller for button in self.params['Controller']: if isButton(button): setattr(Controller, button, self.params['Controller'][button])
def validatePresetsParams(self, action): if action == 'Create': preset = self.vars.presetCreate else: preset = self.vars.preset if IS_NOT_EMPTY()(preset)[1] is not None: return (False, "Preset name is empty") if IS_ALPHANUMERIC()(preset)[1] is not None: return (False, "Preset name must be alphanumeric") if IS_LENGTH(32)(preset)[1] is not None: return (False, "Preset name must be max 32 chars") if action in ['Create', 'Update']: if IS_NOT_EMPTY()(self.vars.password)[1] is not None: return (False, "Password is empty") if IS_ALPHANUMERIC()(self.vars.password)[1] is not None: return (False, "Password must be alphanumeric") if IS_LENGTH(32)(self.vars.password)[1] is not None: return (False, "Password must be max 32 chars") # check that there's not two buttons for the same action map = {} for button in Controller.__dict__: if isButton(button): value = self.vars[button] if button == "Moonwalk": if value not in [None, 'on', 'off']: return ( False, "Invalid value for Moonwalk: {}".format(value)) else: if value is None: return (False, "Button {} not set".format(button)) else: if value in map: return ( False, "Action {} set for two buttons: {} and {}". format(value, button, map[value])) map[value] = button if self.vars.currenttab not in [ 'Global', 'Techniques1', 'Techniques2', 'Techniques3', 'Techniques4', 'Techniques5', 'Techniques6', 'Techniques7', 'Techniques8', 'Mapping' ]: return (False, "Wrong value for current tab: [{}]".format( self.vars.currenttab)) return (True, None)
def printToScreen(self): print("self.params: {}".format(self.params)) print("loaded knows: ") for knows in Knows.__dict__: if isKnows(knows): print("{}: {}".format(knows, Knows.__dict__[knows])) print("loaded settings:") for setting in Settings.__dict__: if isSettings(setting): print("{}: {}".format(setting, Settings.__dict__[setting])) print("loaded controller:") for button in Controller.__dict__: if isButton(button): print("{}: {}".format(button, Controller.__dict__[button])) print("loaded score: {}".format(self.params['score']))
def genJsonFromParams(self, vars): paramsDict = {'Knows': {}, 'Settings': {}, 'Controller': {}} # Knows for var in Knows.__dict__: if isKnows(var): boolVar = vars[var + "_bool"] if boolVar is None: paramsDict['Knows'][var] = [False, 0] else: diffVar = vars[var + "_diff"] if diffVar is not None: paramsDict['Knows'][var] = [True, text2diff[diffVar]] # Settings for hellRun in ['Ice', 'MainUpperNorfair', 'LowerNorfair']: value = vars[hellRun] if value is not None: paramsDict['Settings'][hellRun] = value for boss in ['Kraid', 'Phantoon', 'Draygon', 'Ridley', 'MotherBrain']: value = vars[boss] if value is not None: paramsDict['Settings'][boss] = value for room in ['X-Ray', 'Gauntlet']: value = vars[room] if value is not None: paramsDict['Settings'][room] = value # Controller for button in Controller.__dict__: if isButton(button): value = vars[button] if value is None: paramsDict['Controller'][button] = Controller.__dict__[ button] else: if button == "Moonwalk": if value != None and value == "on": paramsDict['Controller'][button] = True else: paramsDict['Controller'][button] = False else: paramsDict['Controller'][button] = value return paramsDict
def completePreset(params): # add missing knows for know in Knows.__dict__: if isKnows(know): if know not in params['Knows'].keys(): params['Knows'][know] = Knows.__dict__[know] # add missing settings for boss in ['Kraid', 'Phantoon', 'Draygon', 'Ridley', 'MotherBrain']: if boss not in params['Settings']: params['Settings'][boss] = 'Default' for hellrun in ['Ice', 'MainUpperNorfair', 'LowerNorfair']: if hellrun not in params['Settings']: params['Settings'][hellrun] = 'Default' for hardroom in ['X-Ray', 'Gauntlet']: if hardroom not in params['Settings']: params['Settings'][hardroom] = 'Default' # add missing controller buttons for button in Controller.__dict__: if isButton(button): if button not in params['Controller'].keys(): params['Controller'][button] = Controller.__dict__[button]