Exemple #1
0
    def parse_object(self, object):
        """

		"""
        if self.node.tag != 'object':
            raise InvalidFormat('Expected <object> tag, but found <%s>.' %
                                self.node.tag)

        _id = object.get('id')
        if not _id:
            raise InvalidFormat('<object> declared without an id attribute.')
        _id = str(_id)

        nspace = object.get('namespace')
        if not nspace:
            raise InvalidFormat(
                '<object> %s declared without a namespace attribute.' %
                str(_id))
        nspace = str(nspace)

        obj = None
        parent = object.get('parent', None)
        if parent:
            query = self.metamodel.getObjects('id', str(parent))
            if len(query) == 0:
                raise NotFound('No objects found with identifier %s.' %
                               str(parent))
            elif len(query) > 1:
                raise NameClash('%d objects found with identifier %s.' %
                                (len(query), str(parent)))
            parent = query[0]

        # check if model already has this object
        if not bool(self.model.getObject(_id, nspace)):
            obj = self.model.createObject(_id, nspace, parent)
        else:
            print(
                NameClash(
                    'Tried to create already existing object \n\t...ignoring: %s, %s'
                    % (_id, nspace)))
            return

        obj.setFilename(self.source)
        fife.ObjectVisual.create(obj)
        obj.setBlocking(bool(int(object.get('blocking', False))))
        obj.setStatic(bool(int(object.get('static', False))))

        pather = object.get('pather', 'RoutePather')
        obj.setPather(self.model.getPather(pather))

        self.parse_images(object, obj)
        self.parse_actions(object, obj)
Exemple #2
0
	def parse_actions(self, objelt, object):
		"""
		
		"""
		for action in objelt.findall('action'):
			id = action.get('id')
			if not id:
				raise InvalidFormat('<action> declared without an id attribute.')

			act_obj = object.createAction(str(id))
			fife.ActionVisual.create(act_obj)
			self.parse_animations(action, act_obj)
Exemple #3
0
	def _validateTree(self):
		""" 
		Iterates the XML tree and prints warning when an invalid tag is found.
		
		Raises an InvalidFormat exception if there is a format error.
		"""
		for c in self._root_element.getchildren():
			if c.tag != "Module":
				raise InvalidFormat("Invalid tag in " + self._file + \
									". Expected Module, got: " + c.tag)
			elif c.get("name", "") == "":
				raise InvalidFormat("Invalid tag in " + self._file + \
									". Module name is empty.")
			else:
				for e in c.getchildren():
					if e.tag != "Setting":
						raise InvalidFormat("Invalid tag in " + self._file + \
											" in module: " + c.tag + \
											". Expected Setting, got: " + \
											e.tag)
					elif c.get("name", "") == "":
						raise InvalidFormat("Invalid tag in " + self._file + \
											" in module: " + c.tag + \
											". Setting name is empty" + e.tag)
Exemple #4
0
	def parse_animations(self, actelt, action):
		"""
		
		"""
		pass
		for anim in actelt.findall('animation'):
			source = anim.get('source')
			if not source:
				raise InvalidFormat('Animation declared with no source location.')

			# animation paths are relative to this resource's path
			path = self.filename.split('/')
			path.pop()
			path.append(str(source))

			animation = loadXMLAnimation(self.engine, '/'.join(path))
			action.get2dGfxVisual().addAnimation(int( anim.get('direction', 0) ), animation)
			action.setDuration(animation.getDuration())
Exemple #5
0
	def parse_images(self, objelt, object):
		"""
		
		"""
		for image in objelt.findall('image'):
			source = image.get('source')
			if not source:
				raise InvalidFormat('<image> declared without a source attribute.')

			# paths are relative to this resource's path
			path = self.filename.split('/')
			path.pop()
			path.append(str(source))

			img = self.imgMgr.create('/'.join(path))
			img.setXShift(int( image.get('x_offset', 0) ))
			img.setYShift(int( image.get('y_offset', 0) ))
			
			object.get2dGfxVisual().addStaticImage(int( image.get('direction', 0) ), img.getHandle())