def initMapLoading(self, name): # Check if there are MapProperties for this map by looking into the # savegame dict object. shelf = get_savegame() try: # Dictionary of saved map properties saveds = shelf['saved_maps'] # Properties of this particular map properties = saveds[name] except KeyError: # No properties found properties = None # If this map hasn't been loaded yet, do so and place it inside the map dict if not MapFactory.mapAlreadyLoaded(name): # Map is loading. Change game state and notify other controllers # that a loading process is going on right now self.state = STATE_GAME_MAP_LOADING self.evManager.post(GameStateChangedEvent(self.state)) MapFactory.loadMap(name, properties) else: # If it has already been loaded, change the map on your own # (no need for a 1-frame loading screen, amirite?) m = MapFactory.getMap(name) if properties is not None: m.setInteractives(properties.scripts, properties.objects) method = m.init_method self.changeMap(m, method)
def switchToMainMenu(self): # Pause all things GlobalServices.getAudioDevice().stopAll() # Close and delete the temporary shelf reset_savegame() # Delete the Map cache as well MapFactory.clearMaps() # Change state self.state = STATE_MAIN_MENU self.evManager.post(GameStateChangedEvent(self.state))
def add_to_map(shelf, constant, mapname, name, rect, callback, imagefile=None, block=False): # Local imports from src.model.Script import Script, TeleportScript from src.model.Clickable import Clickable, TeleportClickable from src.model import MapFactory mapref = MapFactory.getMap(mapname) image = None if constant == SCRIPT: ObjectClass = Script elif constant == TELEPORTSCRIPT: ObjectClass = TeleportScript elif constant in [OBJECT, TELEPORTOBJECT]: if imagefile is not None: imagefile = os.path.join(PATH_GRAPHICS_TILES, imagefile) image = pygame.image.load(imagefile).convert_alpha() if constant == OBJECT: ObjectClass = Clickable elif constant == TELEPORTOBJECT: ObjectClass = TeleportClickable c = ObjectClass(name, rect, callback, mapref, image, imagefile) if constant == OBJECT: if block: c.setBlocked(block) add_object_to_map_properties(shelf, mapname, constant, c)
def add_object_to_map_properties(shelf, key, constant, obj): dic = shelf['saved_maps'] if key in dic: dic[key].add(constant, obj) shelf['saved_maps'] = dic # Try to add it to the actual Map object as well from src.model import MapFactory m = MapFactory.getMap(key) if m is not None: m.addObject(constant, obj)
def remove_object_from_map_properties(shelf, key, constant, obj, keepblocked=False): dic = shelf['saved_maps'] # Try to remove it from the actual Map object first (this way, sprites get removed) from src.model import MapFactory m = MapFactory.getMap(key) if m is not None: m.removeObject(obj, keepblocked) # Remove it from the map properties if key in dic: dic[key].remove(constant, obj) shelf['saved_maps'] = dic
def remove_from_map(shelf, constant, mapname, name): # Local import from src.model import MapFactory # This part is relevant when a script removes an object # on the map where it is on itself. m = MapFactory.getMap(mapname) if m is not None: ref = m.getObjectByName(name) m.removeObject(ref) # Delete the entry in the map's MapProperties dic = shelf['saved_maps'] if mapname in dic: dic[mapname].remove(constant, name) shelf['saved_maps'] = dic