def load(self): self.mapCursor = [0, 0] loader = AssetLoader() self.maps = {} self.mapsData = {} areasConfig = loader.getConfig(Globals.AreasConfigPath) for area in areasConfig: self.maps[area] = loader.getMap(areasConfig[area]['inAreaMap']) self.mapsData[area] = {} roomsConfig = loader.getConfig(areasConfig[area]['roomsConfig']) for room in roomsConfig: # mapsData maps string area id * string room id -> # [0] string readable name of room # [1] string description of room # [2] int row number of room's tile on map # [3] int col number of room's tile on map # [4] string conditional if conditions must be fulfilled to show room, else None self.mapsData[area][room] = ( roomsConfig[room]['mapName'] if 'mapName' in roomsConfig[room] \ else roomsConfig[room]['name'], roomsConfig[room]['description'], roomsConfig[room]['r'], roomsConfig[room]['c'], roomsConfig[room]['showIf'] if 'showIf' in roomsConfig[room] else None, )
def load(self): self.maps = [] self.colorMasks = [] self.travelMasks = [] mapslst = Globals.MapsPaths loader = AssetLoader() for threetup in mapslst: self.maps.append(loader.getMap(threetup[0])) self.colorMasks.append(loader.getMap(threetup[1])) self.travelMasks.append(loader.getMap(threetup[2])) self.entrances = ([], []) self.areaInfo = {} areaConfig = loader.getConfig(Globals.AreasConfigPath) for area in areaConfig: entranceList = areaConfig[area]['entrances'] mapId = areaConfig[area]['mapId'] for entrance in entranceList: roomId = entrance['roomId'] r = entrance['r'] c = entrance['c'] # self.entrances has two lists, one per world, with tuples formatted as # [0] int row of tile with entrance # [1] int col of tile with entrance # [2] string area id # [3] string room id self.entrances[mapId].append((r, c, area, roomId)) # self.areaInfo maps area id -> (string title, string subtitle) self.areaInfo[area] = (areaConfig[area]['name'], areaConfig[area]['subtitle'] \ if 'subtitle' in areaConfig[area] else '')
def load(self): artslst = Globals.InAreaPaths loader = AssetLoader() self.maps = [] self.details = [] self.names = [] for element in artslst: self.maps.append(loader.getMap(element[0])) self.details.append( loader.getConfig(os.path.join('rooms', element[1]))) for item in self.details[0]: self.names.append(item)
def load(self): self.maps = [] self.colorMasks = [] self.travelMasks = [] mapslst = Globals.MapsPaths loader = AssetLoader() for threetup in mapslst: self.maps.append(loader.getMap(threetup[0])) self.colorMasks.append(loader.getMap(threetup[1])) self.travelMasks.append(loader.getMap(threetup[2])) self.entrances = ([], []) areaConfig = loader.getConfig(Globals.AreasConfigPath) for area in areaConfig: entranceList = areaConfig[area]['entrances'] mapId = areaConfig[area]['mapId'] for entrance in entranceList: roomId = entrance['roomId'] r = entrance['r'] c = entrance['c'] self.entrances[mapId].append((r, c, area, roomId))
def refreshCommandList(self): """ Updates cmdMap to contain all commands player can type """ # locate the rooms and objects configs loader = AssetLoader() area = loader.getConfig(Globals.AreasConfigPath)[self.areaId] items = loader.getConfig(Globals.ItemsConfigPath) rooms = loader.getConfig(area['roomsConfig']) objects = loader.getConfig(area['objectsConfig']) # locate the relevant scripts cmdMap = {} roomScript = loader.getScript(rooms[self.roomId]['script']) objectNames = [] objectScripts = [] for obj in rooms[self.roomId]['objects']: objectNames.append(objects[obj]['name']) objectScripts.append(loader.getScript(objects[obj]['script'])) # fill out the mapping, starting with 'go to' cmdMap['go to'] = {} for neighbor in rooms[self.roomId]['neighbors']: neighborName = rooms[neighbor]['name'] neighborScript = loader.getScript(rooms[neighbor]['script']) neighborReaction = None for action in neighborScript: if action[0] == 'go to': neighborReaction = action[1] cmdMap['go to'][neighborName] = neighborReaction # go through actions to take on room for action in roomScript: # ignore 'go to' current room (not possible) if action[0] == 'go to': continue cmdMap[action[0]] = action[1] # prefill 'use <item>' cmdMap['use'] = {} inventory = self.inventory for item in inventory: if int(inventory[item]) == 0: continue itemName = items[item]['name'] cmdMap['use'][itemName] = None # go through actions to take on objects for i in range(len(objectScripts)): objScript = objectScripts[i] objName = objectNames[i] for action in objScript: # "use .. on" needs special treatment for inventory items verbWords = action[0].split() if verbWords[0] == 'use' and verbWords[-1] == 'on': itemWord = ' '.join(verbWords[1:-1]) itemKey = loader.reverseItemLookup(itemWord) targetPhrase = 'on ' + objName if itemKey == '': raise Exception( 'script item name', itemWord, 'not found in items configuration file') if itemKey in inventory and int( inventory[itemKey]) > 0: if cmdMap['use'][itemWord] is None: cmdMap['use'][itemWord] = {} cmdMap['use'][itemWord][targetPhrase] = action[1] # all other verbs are straightforward else: if action[0] not in cmdMap: cmdMap[action[0]] = {} cmdMap[action[0]][objName] = action[1] self.cmdMap = cmdMap
def refreshCommandList(self): """ Updates GameState cmdMap to contain all commands player can type """ # Helper method to see if rooms or objects are visible in game def isVisible(self, obj): # if parameter is part of config possibly containing showIf if isinstance(obj, dict): if 'showIf' in obj: conditionVal = obj['showIf'] return self.evaluateConditionTree(conditionVal) # if parameter is tuple of (verb, reaction, condition) if isinstance(obj, tuple): if obj[0].startswith('_'): # verbs starting with underscore are not publicly visible return False if obj[2] is not None: # evaluate the condition return self.evaluateCondition(obj[2].split('_')) return True # visible by default # locate the rooms and objects configs loader = AssetLoader() gs = GameState() area = loader.getConfig(Globals.AreasConfigPath)[gs.areaId] items = loader.getConfig(Globals.ItemsConfigPath) rooms = loader.getConfig(area['roomsConfig']) objects = loader.getConfig(area['objectsConfig']) # locate the relevant scripts cmdMap = {} roomScript = loader.getScript(rooms[gs.roomId]['script']) objectNames = [] objectScripts = [] for obj in rooms[gs.roomId]['objects']: if not isVisible(self, objects[obj]): continue # do not show the object if conditions not met objectNames.append(objects[obj]['name']) objectScripts.append(loader.getScript(objects[obj]['script'])) # fill out the mapping, starting with 'go to' cmdMap['go to'] = {} for neighbor in rooms[gs.roomId]['neighbors']: if not isVisible(self, rooms[neighbor]): continue # do not show the room if conditions not met neighborName = rooms[neighbor]['name'] neighborScript = loader.getScript(rooms[neighbor]['script']) neighborReaction = None for action in neighborScript: if not isVisible(self, action): continue if action[0] == 'go to': neighborReaction = action[1] if neighborReaction: cmdMap['go to'][neighborName] = neighborReaction # go through actions to take on room for action in roomScript: # ignore 'go to' current room (not possible) if action[0] == 'go to' or not isVisible(self, action): continue cmdMap[action[0]] = action[1] # prefill 'use <item>', 'give <item>', 'show <item>' itemActionPhrases = [('use', 'on'), ('give', 'to'), ('show', 'to')] # go through actions to take on objects for i in range(len(objectScripts)): objScript = objectScripts[i] objName = objectNames[i] for action in objScript: if not isVisible(self, action): continue verbWords = action[0].split() # "use .. on", "give ... to", "show ... to" needs special treatment for inventory items for prefix, suffix in itemActionPhrases: if verbWords[0] == prefix and verbWords[-1] == suffix: itemWord = ' '.join(verbWords[1:-1]) itemKey = loader.reverseItemLookup(itemWord) targetPhrase = suffix + ' ' + objName if itemKey == '': raise Exception('script item name', itemWord ,'not found in items configuration file') if itemKey in gs.inventory and int(gs.inventory[itemKey]) > 0: if prefix not in cmdMap: cmdMap[prefix] = {} if itemWord not in cmdMap[prefix]: cmdMap[prefix][itemWord] = {} cmdMap[prefix][itemWord][targetPhrase] = action[1] break # all other verbs are straightforward else: if action[0] not in cmdMap: cmdMap[action[0]] = {} cmdMap[action[0]][objName] = action[1] gs.cmdMap = cmdMap