コード例 #1
0
ファイル: gamemodel.py プロジェクト: parpg/parpg
 def addAgent(self, namespace, agent):
     """Adds an agent to the agents dictionary
     @param namespace: the namespace where the agent is to be added to
     @type namespace: str
     @param agent: The agent to be added
     @type agent: dict """
     from fife.extensions.serializers.xml_loader_tools import loadImportFile
     if not self.agents.has_key(namespace):
         self.agents[namespace] = {}
         
     agent_values = agent.values()[0]
     unique_agent_id = self.createUniqueID(agent.keys()[0])
     del agent[agent.keys()[0]]
     agent[unique_agent_id] = agent_values
     self.agents[namespace].update(agent)
     object_model = ""
     if agent_values["Entity"].has_key("graphics") \
        and agent_values["Entity"]["graphics"].has_key("gfx"): 
         object_model = agent_values["Entity"]["graphics"]["gfx"]
     elif agent_values.has_key("Template"):
         template = self.object_db[agent_values["Template"]]
         object_model = template["graphics"]["gfx"]
     else:
         object_model = self.GENERIC_ITEM_GFX
     import_file = self.agent_import_files[object_model]
     loadImportFile(self.obj_loader, import_file, self.engine)
コード例 #2
0
 def addAgent(self, namespace, agent):
     """Adds an agent to the agents dictionary
     @param namespace: the namespace where the agent is to be added to
     @type namespace: str
     @param agent: The agent to be added
     @type agent: dict """
     from fife.extensions.serializers.xml_loader_tools import loadImportFile
     if not self.agents.has_key(namespace):
         self.agents[namespace] = {}
         
     agent_values = agent.values()[0]
     unique_agent_id = self.createUniqueID(agent.keys()[0])
     del agent[agent.keys()[0]]
     agent[unique_agent_id] = agent_values
     self.agents[namespace].update(agent)
     object_model = ""
     if agent_values.has_key("ObjectModel"): 
         object_model =  agent_values["ObjectModel"]
     elif agent_values["ObjectType"] == "MapItem":
         object_data = self.object_db[agent_values["ItemType"]]
         object_model = object_data["gfx"] if object_data.has_key("gfx") \
                     else "generic_item"
     else:
         object_model = self.object_db[agent_values["ObjectType"]]["gfx"]
     import_file = self.agent_import_files[object_model]
     loadImportFile(self.obj_loader, import_file, self.engine)
コード例 #3
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)
コード例 #4
0
    def parse_imports(self, mapelt, map):
        """ load all objects defined as import into memory
		
		@type	mapelt:	object
		@param	mapelt:	ElementTree root
		@return	FIFE map object			
		@rtype	object
		"""
        parsedImports = {}

        if self.callback:
            tmplist = mapelt.findall('import')
            i = float(0)

        for item in mapelt.findall('import'):
            _file = item.get('file')
            if _file:
                _file = reverse_root_subfile(self.source, _file)
            _dir = item.get('dir')
            if _dir:
                _dir = reverse_root_subfile(self.source, _dir)

            # Don't parse duplicate imports
            if (_dir, _file) in parsedImports:
                if self.debug: print("Duplicate import:", (_dir, _file))
                continue
            parsedImports[(_dir, _file)] = 1

            if _file and _dir:
                loadImportFile(self.obj_loader, '/'.join(_dir, _file),
                               self.engine, self.debug)
            elif _file:
                loadImportFile(self.obj_loader, _file, self.engine, self.debug)
            elif _dir:
                loadImportDirRec(self.obj_loader, _dir, self.engine,
                                 self.debug)
                map.importDirs.append(_dir)
            else:
                if self.debug: print('Empty import statement?')

            if self.callback:
                i += 1
                self.callback(self.msg['imports'],
                              float(i / float(len(tmplist)) * 0.25 + 0.25))
コード例 #5
0
ファイル: xmlmap.py プロジェクト: squiddy/fifengine
    def parse_imports(self, mapelt, map):
        """ load all objects defined as import into memory
		
		@type	mapelt:	object
		@param	mapelt:	ElementTree root
		@return	FIFE map object			
		@rtype	object
		"""
        parsedImports = {}

        if self.callback:
            tmplist = mapelt.findall("import")
            i = float(0)

        for item in mapelt.findall("import"):
            _file = item.get("file")
            if _file:
                _file = reverse_root_subfile(self.source, _file)
            _dir = item.get("dir")
            if _dir:
                _dir = reverse_root_subfile(self.source, _dir)

                # Don't parse duplicate imports
            if (_dir, _file) in parsedImports:
                if self.debug:
                    print "Duplicate import:", (_dir, _file)
                continue
            parsedImports[(_dir, _file)] = 1

            if _file and _dir:
                loadImportFile(self.obj_loader, "/".join(_dir, _file), self.engine, self.debug)
            elif _file:
                loadImportFile(self.obj_loader, _file, self.engine, self.debug)
            elif _dir:
                loadImportDirRec(self.obj_loader, _dir, self.engine, self.debug)
                map.importDirs.append(_dir)
            else:
                if self.debug:
                    print "Empty import statement?"

            if self.callback:
                i += 1
                self.callback(self.msg["imports"], float(i / float(len(tmplist)) * 0.25 + 0.25))
コード例 #6
0
	def importFile(self, path, filename):
		file = os.path.normpath(os.path.join(path, filename))
		# FIXME: This is necassary for the files to be loaded properly.
		#		 The loader should be fixed to support native (windows)
		#		 path separators.
		file = file.replace('\\', '/') 
		
		try:
			if os.path.isfile(file):
				loadImportFile(self.obj_loader, file, self.engine)
			else:
				raise file+ " is not a file!"
		except:
			traceback.print_exc(sys.exc_info()[1])
			errormsg = u"Importing file failed:\n"
			errormsg += u"File: "+unicode(file)+u"\n"
			errormsg += u"Error: "+unicode(sys.exc_info()[1])
			ErrorDialog(errormsg)
			return None
		
		events.onObjectsImported.send(sender=self)
コード例 #7
0
    def importFile(self, path, filename):
        file = os.path.normpath(os.path.join(path, filename))
        # FIXME: This is necassary for the files to be loaded properly.
        #		 The loader should be fixed to support native (windows)
        #		 path separators.
        file = file.replace('\\', '/')

        try:
            if os.path.isfile(file):
                loadImportFile(self.obj_loader, file, self.engine)
            else:
                raise file + " is not a file!"
        except:
            traceback.print_exc(sys.exc_info()[1])
            errormsg = u"Importing file failed:\n"
            errormsg += u"File: " + unicode(file) + u"\n"
            errormsg += u"Error: " + unicode(sys.exc_info()[1])
            ErrorDialog(errormsg)
            return None

        events.onObjectsImported.send(sender=self)