示例#1
0
	def openFile(self, path):
		""" Opens a file """
		try:
			if self._lighting_mode == 0:
				map = loaders.loadMapFile(path, self.engine)
			else:
				map = loaders.loadMapFile(path, self.engine, extensions = {'lights': True})
			return self.newMapView(map)
		except:
			traceback.print_exc(sys.exc_info()[1])
			errormsg = u"Opening map failed:\n"
			errormsg += u"File: "+unicode(path, sys.getfilesystemencoding())+u"\n"
			errormsg += u"Error: "+unicode(sys.exc_info()[1])
			ErrorDialog(errormsg)
			return None
示例#2
0
	def openFile(self, path):
		""" Opens a file """
		parts = path.split(os.sep)

		for mapview in self._mapviewlist:
			if path == mapview._map.getFilename():
				self.getStatusBar().text = u"Map already loaded, omitting map " + parts[-1]
				return
		
		events.onOpenMapFile.send(sender=self, path=path)
		
		try:
			map = None
			fife_loader = fife.MapLoader(self.engine.getModel(), self.engine.getVFS(), self.engine.getImageManager(), self.engine.getRenderBackend())
			if self._lighting_mode == 0 and fife_loader.isLoadable(path):
				map = fife_loader.load(path)
			else:
				# TODO: vtchill - once lights are supported by the c++ map loader this can be removed
				map = loaders.loadMapFile(path, self.engine, extensions = {'lights': True})
				
			if map:
				self.getStatusBar().text = u"Loaded map: " + parts[-1]
				return self.newMapView(map)
			else:
				self.getStatusBar().text = u"Map could not be loaded: " + parts[-1]
				return None
		except:
			traceback.print_exc(sys.exc_info()[1])
			errormsg = u"Opening map failed:\n"
			errormsg += u"File: "+unicode(path, sys.getfilesystemencoding())+u"\n"
			errormsg += u"Error: "+unicode(sys.exc_info()[1])
			ErrorDialog(errormsg)
			return None
示例#3
0
	def openFile(self, path):
		""" Opens a file """
		parts = path.split(os.sep)

		for mapview in self._mapviewlist:
			if path == mapview._map.getFilename():
				self.getStatusBar().text = u"Map already loaded, omitting map " + parts[-1]
				return
		
		events.onOpenMapFile.send(sender=self, path=path)
		
		try:
			map = None
			fife_loader = fife.MapLoader(self.engine.getModel(), self.engine.getVFS(), self.engine.getImageManager(), self.engine.getRenderBackend())
			if self._lighting_mode == 0 and fife_loader.isLoadable(path):
				map = fife_loader.load(path)
			else:
				# TODO: vtchill - once lights are supported by the c++ map loader this can be removed
				map = loaders.loadMapFile(path, self.engine, extensions = {'lights': True})
				
			if map:
				self.getStatusBar().text = u"Loaded map: " + parts[-1]
				return self.newMapView(map)
			else:
				self.getStatusBar().text = u"Map could not be loaded: " + parts[-1]
				return None
		except:
			traceback.print_exc(sys.exc_info()[1])
			errormsg = u"Opening map failed:\n"
			errormsg += u"File: "+unicode(path, sys.getfilesystemencoding())+u"\n"
			errormsg += u"Error: "+unicode(sys.exc_info()[1])
			ErrorDialog(errormsg)
			return None
示例#4
0
	def openFile(self, path):
		""" Opens a file """
		try:
			if self._lighting_mode == 0:
				loader = fife.MapLoader(self.engine.getModel(), self.engine.getVFS(), self.engine.getImageManager(), self.engine.getRenderBackend())
				if loader.isLoadable(path):
					map = loader.load(path)
					print 'map loaded: %s' % (map.getFilename())
				else:
					print 'map could not be loaded: %s' % (map.getFilename())
			else:
				# TODO: vtchill - once lights are supported by the c++ map loader this can be removed
				map = loaders.loadMapFile(path, self.engine, extensions = {'lights': True})
				
			if map:
				return self.newMapView(map)
			else:
				return None
		except:
			traceback.print_exc(sys.exc_info()[1])
			errormsg = u"Opening map failed:\n"
			errormsg += u"File: "+unicode(path, sys.getfilesystemencoding())+u"\n"
			errormsg += u"Error: "+unicode(sys.exc_info()[1])
			ErrorDialog(errormsg)
			return None
示例#5
0
	def loadLevel(self, filename):
		"""
		Load a xml map and setup cameras.
		"""
		
		self.resetKeys()
		
		self._filename = filename
		self.reset()
		
		#specific imports that needed to be added
		#@todo: you should be able to add file imports via the map editor
		loadImportFile(self.obj_loader, "objects/projectiles/bullet1/object.xml", self._engine)
		loadImportFile(self.obj_loader,"objects/projectiles/fireball/object.xml", self._engine)
		
		self._map = loadMapFile(self._filename, self._engine)

		self._scene = Scene(self, self._engine, self._map.getLayer('objects'), self._soundmanager)
		self._scene.initScene(self._map)

		self.initCameras()

		self._hudwindow.show()
		self._gameover.hide()
		self._winner.hide()
		
		self._starttime = self._timemanager.getTime()
		
		self._genericrenderer = fife.GenericRenderer.getInstance(self.cameras['main'])
		self._genericrenderer.clearActiveLayers()
		self._genericrenderer.addActiveLayer(self._map.getLayer('boundingbox'))
		self._genericrenderer.setEnabled(True)
示例#6
0
 def openFile(self, path):
     """ Opens a file """
     try:
         if self._lighting_mode == 0:
             map = loaders.loadMapFile(path, self.engine)
         else:
             map = loaders.loadMapFile(path,
                                       self.engine,
                                       extensions={'lights': True})
         return self.newMapView(map)
     except:
         traceback.print_exc(sys.exc_info()[1])
         errormsg = u"Opening map failed:\n"
         errormsg += u"File: " + unicode(
             path, sys.getfilesystemencoding()) + u"\n"
         errormsg += u"Error: " + unicode(sys.exc_info()[1])
         ErrorDialog(errormsg)
         return None
示例#7
0
    def load(self, filename):
        self.filename = filename
        self.reset()

        self.map = loadMapFile(filename, self.engine, extensions = {'lights': True})

        self.maplistener = MapListener(self.map)

        self.initAgents()
        self.initCameras()
示例#8
0
    def load(self, filename):
        """
		Load a xml map and setup agents and cameras.
		"""

        self.filename = filename
        self.reset()
        self.map = loadMapFile(filename, self.engine, extensions={"lights": True})
        self.maplistener = MapListener(self.map)

        self.initAgents()
        self.initCameras()

        if int(TDS.get("FIFE", "PlaySounds")):
            # play track as background music
            self.music = self.soundmanager.createSoundEmitter("music/rio_de_hola.ogg")
            self.music.looping = True
            self.music.gain = 128.0
            self.music.play()

            self.waves = self.soundmanager.createSoundEmitter("sounds/waves.ogg")
            self.waves.looping = True
            self.waves.gain = 16.0
            self.waves.play()
示例#9
0
文件: gamemap.py 项目: parpg/parpg
    def load(self, filename):
        """Load a map given the filename.
           @type filename: String
           @param filename: Name of map to load
           @return: None"""
        self.reset()

        self.map = loadMapFile(filename, self.engine)

        self.agent_layer = self.map.getLayer('ObjectLayer')
        self.top_layer = self.map.getLayer('TopLayer')      
            
        # it's possible there's no transition layer
        size = len('TransitionLayer')
        for layer in self.map.getLayers():
            # could be many layers, but hopefully no more than 3
            if(layer.getId()[:size] == 'TransitionLayer'):
                self.transitions.append(self.map.getLayer(layer.getId()))

        """ Initialize the camera.
        Note that if we have more than one camera in a map file
        we will have to rework how self.my_cam_id works. To make sure
        the proper camera is set as the 'main' camera.
        At this point we also set the viewport to the current resolution."""
        for cam in self.map.getCameras():
            width = self.engine.getSettings().getScreenWidth()
            height = self.engine.getSettings().getScreenHeight()
            viewport = fife.Rect(0, 0, width, height)
            cam.setViewPort(viewport)
            self.my_cam_id = cam.getId()
            self.cameras[self.my_cam_id] = cam
            cam.resetRenderers()
        
        self.target_rotation = self.cameras[self.my_cam_id].getRotation()

        self.outline_renderer = (
            fife.InstanceRenderer.getInstance(self.cameras[self.my_cam_id])
        )

        # set the render text
        rend = fife.FloatingTextRenderer.getInstance(
            self.cameras[self.my_cam_id]
        )
        font = pychan.manager.hook.guimanager.createFont(
            'fonts/rpgfont.png',
            0,
            self.settings.get("FIFE", "FontGlyphs")
        )

        rend.setFont(font)
        rend.activateAllLayers(self.map)
        rend.setEnabled(True)
        
        # Activate the grid renderer on all layers
        rend = self.cameras['map_camera'].getRenderer('GridRenderer')
        rend.activateAllLayers(self.map)
         
        # Activate the grid renderer on all layers
        rend = fife.CoordinateRenderer.getInstance(
            self.cameras[self.my_cam_id]
        )
        rend.setColor(0, 0, 0)
        rend.addActiveLayer(self.map.getLayer("GroundLayer"))

        # Make World aware that this is now the active map.
        self.model.active_map = self
示例#10
0
	def _loadMap(self, filename, purpose, port=False, location=None, direction=None):
		"""
		_loadMap Function
		Deletes the old map and loads a new one. Also initilises cameras.
		
		Keyword Arguments
		filename - String, path to the map file
		purpose - String, LEVEL or MENU
		"""
		self._model.deleteMap(self._map)
		self._map = None
		self._npcs = {}
		self._npclist = False
		self._mapsettings = SimpleXMLSerializer(filename=filename +".config")
		self._eventtracker = None
		
		
		if purpose == 'LEVEL':
			# Hide any active GUIs
			self._hideAllGuis()
			
			# Pump the engine to force it to move to a new frame
			self._engine.pump()
			
			# If the loading menu is loaded, show it
			if self._loadingmenu != None:
				self._loadingmenu.show()
				loadwindow = self._loadingmenu.findChild(name="loadwindow")
				autoposition.placeWidget(loadwindow, 'automatic')
			
			# Load the map
			self._map = loadMapFile(filename, self._engine, self._loadLevelMapCallback)
			
		elif purpose == 'MENU':
			# Hide any active GUIs
			self._hideAllGuis()
			
			# Pump the engine to force it to move to a new frame
			self._engine.pump()
			
			# If the loading menu is loaded, show it
			if self._loadingmenu != None:
				self._loadingmenu.show()
				loadwindow = self._loadingmenu.findChild(name="loadwindow")
				autoposition.placeWidget(loadwindow, 'automatic')
				
			# Load the map
			self._map = loadMapFile(filename, self._engine, self._loadMenuMapCallback)
		
		# Start (or clear) the camera array
		self._cameras = {}
		
		# For each camera in the map
		for cam in self._map.getCameras():
			# Get the camera ID
			camera_id = cam.getId()
			# Add the camera with that ID to the array
			self._cameras[camera_id] = cam
			# Reset the camera
			cam.resetRenderers()
			
		if purpose == 'LEVEL':
			# Start the player character
			self._startPlayerActor()
			if location != None:
				self._player._agent.setLocation(location)
			if direction != None:
				self._player._agent.setFacingLocation(direction)
			if self._hud != None:
				self._hud.show()
			
			self._loadLevelMapCallback("", 0.775)
		
		# Start the floating text renderer
		renderer = fife.FloatingTextRenderer.getInstance(self._cameras['main'])
		textfont = self._engine.getGuiManager().createFont('fonts/rpgfont.png', 0, str(self._setting.get("FIFE", "FontGlyphs")))
		renderer.changeDefaultFont(textfont)
		renderer.setDefaultBackground(0,0,0,0)
		renderer.setDefaultBorder(0,0,0,0)
		renderer.activateAllLayers(self._map)
		renderer.setEnabled(True)
		
		if purpose == 'LEVEL':
			self._loadLevelMapCallback("", 0.8)
		else:
			self._loadMenuMapCallback("", 0.8)
	
		if self._mapsettings.get("map", "usewaypoints", False):
			self._waypoints = self._mapsettings._deserializeList(self._mapsettings.get("map", "waypoints", ""))
		else:
			self._waypoints = None

		if purpose == 'LEVEL':
			self._loadLevelMapCallback("", 0.825)
		else:
			self._loadMenuMapCallback("", 0.825)
		
		if self._mapsettings.get("map", "useobjects", False):
			self._objects = objectmanager.ObjectManager(self)
			objlist = self._mapsettings._deserializeList(self._mapsettings.get("map", "objectlist", False))
			for file in objlist:
				self._objects._loadObjects(file)
		
		if purpose == 'LEVEL':
			self._loadLevelMapCallback("", 0.85)
		else:
			self._loadMenuMapCallback("", 0.85)
		
		if self._mapsettings.get("map", "dynamicnpcs", False):
			self._npclist = self._mapsettings._deserializeDict(self._mapsettings.get("map", "npclist", False))
			if self._npclist != False:
				for id, name in self._npclist.iteritems():
					self._npcs[name] = npc.NPC(self._setting, self._model, id, self._map.getLayer('player'), self, True, name)
		
		if purpose == 'LEVEL':
			self._loadLevelMapCallback("", 0.9)
		else:
			self._loadMenuMapCallback("", 0.9)
		
		self._eventtracker = eventtracker.EventTracker(self._engine, self._model, self._sounds, self)
		if self._mapsettings.get("map", "useevents", False):
			eventlist = self._mapsettings._deserializeList(self._mapsettings.get("map", "eventslist", ""))
			for file in eventlist:
				self._eventtracker._addEvent(file)
				
		if purpose == 'LEVEL':
			self._loadLevelMapCallback("", 0.95)
		else:
			self._loadMenuMapCallback("", 0.95)
			
		self._drift = {}
		self._drift = self._mapsettings._deserializeDict(self._mapsettings.get("map", "drift", "use : False"))
		if self._drift["use"] == "True":
			self._drift["use"] = True
			self._drift["x"] = float(self._drift["x"])
			self._drift["y"] = float(self._drift["y"])

			start = self._drift["start"].partition(",")
			loc = fife.Location(self._map.getLayer('player'))
			loc.setExactLayerCoordinates(fife.ExactModelCoordinate(float(start[0]), float(start[2])))
			self._cameras['main'].setLocation(loc)
		else:
			self._drift["use"] = False
		
		self._gamestate = purpose