Ejemplo n.º 1
0
	def _setAnimation(self, anim):
		if anim is not None:
			if isinstance(anim, fife.Animation):
				self._anim = anim
			else:
				if anim is not "":
					# use xml loader
					self._anim = loadXMLAnimation(get_manager().hook.engine, anim)
			self.real_widget.setAnimation(self._anim)
Ejemplo n.º 2
0
	def _setAnimation(self, anim):
		if anim is not None:
			if isinstance(anim, fife.Animation):
				self._anim = anim
			else:
				if anim != "":
					# use xml loader
					self._anim = loadXMLAnimation(get_manager().hook.engine, anim)
			self.real_widget.setAnimation(self._anim)
Ejemplo n.º 3
0
	def animation_light(self):
		if not self._instances[0]: return
		self.lightrenderer.removeAll(str(self._widgets["group"]._getText()))

		animation = str(self._widgets["animation"]._getText())
		if animation == "": return
		rloc = animation
		ani = loadXMLAnimation(self.engine, rloc)
		self._light["animation"] = ani
		node = fife.RendererNode(self._instances[0])
		self.lightrenderer.addAnimation(str(self._widgets["group"]._getText()),
											node,
											self._light["animation"],
											self._light["src"],
											self._light["dst"],)
Ejemplo n.º 4
0
    def animation_light(self):
        if not self._instances[0]: return
        self.lightrenderer.removeAll(str(self._widgets["group"]._getText()))

        animation = str(self._widgets["animation"]._getText())
        if animation == "": return
        rloc = animation
        ani = loadXMLAnimation(self.engine, rloc)
        self._light["animation"] = ani
        node = fife.RendererNode(self._instances[0])
        self.lightrenderer.addAnimation(
            str(self._widgets["group"]._getText()),
            node,
            self._light["animation"],
            self._light["src"],
            self._light["dst"],
        )
Ejemplo n.º 5
0
    def add_light_from_animation(self, group, animation, agent=None,
                                 layer=None, location=None, point=None,
                                 blend_mode=(-1, -1)):
        """Adds a light that uses an animation lightmap.

        Arguments:

            group: The name of the group the light should be put in.

            animation: The path to a xml file that contains the animation data
            or a fife.Animation.

            agent: The name of the agent the light should be attached too. If
            empty or None this will be ignored. Please note that the layer and
            location have to be set if this is empty or None.

            layer: The name of the layer the light originates from. Lights will
            illuminate lower layers, but not higher ones. If empty or None this
            will be ignored.

            location: The relative or absolute location of the agent depending
            on whether the agent was set or not. A list with two or three
            values.
            If None this will be ignored.

            point: The relative or absolute window position of the light as
            a list with 2 values or a fife.Point.
            This differs from location as it is in pixels and (0, 0) is the
            upper left position of the window.

            blend_mode: A list with 2 values for the source and
            destination blend modes. If not passed the default values of FIFE
            will be used.

        Returns:
            The light info of the added light
        """
        node = self.__create_render_node(agent, layer, location, point)
        if not isinstance(animation, fife.Animation):
            animation = xmlanimation.loadXMLAnimation(
                self.__application.engine,
                animation)
        light_renderer = self.get_light_renderer()
        light_renderer.addAnimation(group, node, animation, *blend_mode)
        return light_renderer.getLightInfo(group)[-1]
Ejemplo n.º 6
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())
Ejemplo n.º 7
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())
Ejemplo n.º 8
0
    def setUp(self):
        template = '../data/wolf_walk/wolf_walk_%s.xml'
        dirnames = ['e', 'ne', 'n', 'nw', 'w', 'sw', 's', 'se']
        files = map(lambda dirname: template % dirname, dirnames)

        self.engine = getEngine()

        _map = self.engine.getModel().createMap("map001")

        self.grid = fife.SquareGrid()
        self.grid.thisown = 0

        self.layer = _map.createLayer("Layer001", self.grid)

        self.target = fife.Location(self.layer)

        self.obj = fife.Object("object001", 'plaa')
        fife.ObjectVisual.create(self.obj)
        self.pather = fife.RoutePather()

        self.obj.setPather(self.pather)
        self.action = self.obj.createAction('walk')
        fife.ActionVisual.create(self.action)

        for index, direction in enumerate(dirnames):
            degree = 45 * index
            self.action.get2dGfxVisual().addAnimation(
                degree, loadXMLAnimation(self.engine, files[index]))

        self.ground = fife.Object("ground", 'plaa')
        image = self.engine.getImageManager().load('../data/earth_1.png')
        fife.ObjectVisual.create(self.ground)
        self.ground.get2dGfxVisual().addStaticImage(0, image.getHandle())
        self.ground.img = self.engine.getImageManager().get(image.getHandle())

        for y in xrange(-2, 3):
            for x in xrange(-2, 3):
                inst = self.layer.createInstance(self.ground,
                                                 fife.ModelCoordinate(x, y))
                fife.InstanceVisual.create(inst)

        self.inst = self.layer.createInstance(self.obj,
                                              fife.ModelCoordinate(-2, -2))
        fife.InstanceVisual.create(self.inst)
Ejemplo n.º 9
0
	def setUp(self):
		template = 'tests/data/wolf_walk/wolf_walk_%s.xml'
		dirnames = ['e', 'ne', 'n', 'nw', 'w', 'sw', 's', 'se']
		files = [template % dirname for dirname in dirnames]

		self.engine = getEngine()
		
		self.map = self.engine.getModel().createMap("map001")
		self.grid = self.engine.getModel().getCellGrid("square")
		
		self.layer = self.map.createLayer("Layer001", self.grid)
		self.layer.setWalkable(True)
		self.layer.createCellCache()
		
		self.target = fife.Location(self.layer)
	
		self.obj = fife.Object("object001", 'plaa')
		fife.ObjectVisual.create(self.obj)
		self.pather = fife.RoutePather()
				
		self.obj.setPather(self.pather)
		self.action = self.obj.createAction('walk')
		fife.ActionVisual.create(self.action)

		for index, direction in enumerate(dirnames):
			degree = 45 * index
			self.action.get2dGfxVisual().addAnimation(degree, loadXMLAnimation(self.engine, files[index]))

		self.ground = fife.Object("ground", 'plaa')
		image = self.engine.getImageManager().load('tests/data/earth_1.png')
		fife.ObjectVisual.create(self.ground)
		self.ground.get2dGfxVisual().addStaticImage(0, image.getHandle())
		self.ground.img = self.engine.getImageManager().get(image.getHandle())
		
		for y in range(-2,3):
			for x in range(-2,3):
				inst = self.layer.createInstance(self.ground, fife.ModelCoordinate(x,y))
				fife.InstanceVisual.create(inst)
				
		self.inst = self.layer.createInstance(self.obj, fife.ModelCoordinate(-2,-2))
		fife.InstanceVisual.create(self.inst)
Ejemplo n.º 10
0
    def setUp(self):
        template = "../data/wolf_walk/wolf_walk_%s.xml"
        dirnames = ["e", "ne", "n", "nw", "w", "sw", "s", "se"]
        files = map(lambda dirname: template % dirname, dirnames)

        self.engine = getEngine()

        _map = self.engine.getModel().createMap("map001")

        self.grid = fife.SquareGrid()
        self.grid.thisown = 0

        self.layer = _map.createLayer("Layer001", self.grid)

        self.target = fife.Location(self.layer)

        self.obj = fife.Object("object001", "plaa")
        fife.ObjectVisual.create(self.obj)
        self.pather = fife.RoutePather()

        self.obj.setPather(self.pather)
        self.action = self.obj.createAction("walk")
        fife.ActionVisual.create(self.action)

        for index, direction in enumerate(dirnames):
            degree = 45 * index
            self.action.get2dGfxVisual().addAnimation(degree, loadXMLAnimation(self.engine, files[index]))

        self.ground = fife.Object("ground", "plaa")
        image = self.engine.getImageManager().load("../data/earth_1.png")
        fife.ObjectVisual.create(self.ground)
        self.ground.get2dGfxVisual().addStaticImage(0, image.getHandle())
        self.ground.img = self.engine.getImageManager().get(image.getHandle())

        for y in xrange(-2, 3):
            for x in xrange(-2, 3):
                inst = self.layer.createInstance(self.ground, fife.ModelCoordinate(x, y))
                fife.InstanceVisual.create(inst)

        self.inst = self.layer.createInstance(self.obj, fife.ModelCoordinate(-2, -2))
        fife.InstanceVisual.create(self.inst)
Ejemplo n.º 11
0
	def parse_lights(self, layerelt, layer):
		""" create light nodes

		@type	layerelt:	object
		@param	layerelt:	ElementTree layer branch
		@type	layer:	object
		@param	layer:	FIFE layer object
		"""
		_LIGHT_DEFAULT_BLENDING_SRC = -1
		_LIGHT_DEFAULT_BLENDING_DST = -1
		_LIGHT_DEFAULT_SUBDIVISIONS = 32
		_LIGHT_DEFAULT_CAM_ID = 'default'
		_LIGHT_DEFAULT_INTENSITY = 128
		_LIGHT_DEFAULT_RADIUS = 10.0

		print("Processing lights ... ")
		lightelt = layerelt.find('lights')
		if not lightelt:
			print("\tno lights found on layer %s" % layer.getId())
			return

		lights = []
		for attr in ('l', 'light', 'lgt'):
			lights.extend(lightelt.findall(attr))

		for light in lights:
			group = light.get('group')
			if not group:
				print("Light has no group. Omitting...")
				continue

			blending_src = light.get('src')
			if not blending_src:
				blending_src = _LIGHT_DEFAULT_BLENDING_SRC
			blending_dst = light.get('dst')
			if not blending_dst:
				blending_dst = _LIGHT_DEFAULT_BLENDING_DST

			_x = light.get('x')
			if not _x: _x = 0
			_y = light.get('y')
			if not _y: _y = 0
			_z = light.get('y')
			if not _z: _z = 0

			node = {}
			node['blending_src'] = int(blending_src)
			node['blending_dst'] = int(blending_dst)
			node['layer'] = layer.getId()
			node['position'] = int(_x), int(_y), int(_z)

			# where is the light? *sing*
			instance_id = light.get('instance')
			node['instance'] = None
			if instance_id and layer.getInstance(instance_id):
				node['instance'] = instance_id

			type = light.get('type')
			if type:
				s_ref = light.get('s_ref')
				if not s_ref: s_ref = -1
				node['s_ref'] = int(s_ref)
				a_ref = light.get('a_ref')
				if not a_ref: a_ref = 0.0
				node['a_ref'] = float(a_ref)

				if type == 'image':
					image = light.get('image')
					if not image:
						print("Light has no image. Omitting...")
						continue
					node['type'] = 'image'
					image = reverse_root_subfile(self.source, image)
					img = self.image_manager.create(image)
					node['image'] = img
				elif type == 'animation':
					animation = light.get('animation')
					if not animation:
						print("Light has no animation. Omitting...")
						continue
					node['type'] = 'animation'
					animation = reverse_root_subfile(self.source, animation)
					anim = loadXMLAnimation(self.engine, animation)
					node['animation'] = anim
				elif type == 'simple':
					node['type'] = type
					radius = light.get('radius')
					if not radius: radius = _LIGHT_DEFAULT_RADIUS
					node['radius'] = float(radius)

					subdivisions = light.get('subdivisions')
					if not subdivisions:
						subdivisions = _LIGHT_DEFAULT_SUBDIVISIONS
					node['subdivisions'] = int(subdivisions)

					intensity = light.get('intensity')
					if not intensity:
						intensity = _LIGHT_DEFAULT_INTENSITY
					node['intensity'] = int(intensity)

					xstretch = light.get('xstretch')
					if not xstretch: xstretch = 1.0
					ystretch = light.get('ystretch')
					if not ystretch: ystretch = 1.0
					node['stretch'] = float(xstretch), float(ystretch)

					color = light.get('color')
					if not color: color = '%d,%d,%d' % (255, 255, 255)
					node['color'] = ([int(c) for c in color.split(',')])

			else:
				continue

			cam_id = light.get('camera_id')
			if not cam_id: cam_id = _LIGHT_DEFAULT_CAM_ID

			if not cam_id in self.light_data:
				self.light_data[cam_id] = {}
			if group not in self.light_data[cam_id]:
				self.light_data[cam_id][group] = []

			self.light_data[cam_id][group].append(node)

		for camera, groups in self.light_data.items():
			print("Lights for camera %s" % camera)
			for group, lights in groups.items():
				print(group, lights)
Ejemplo n.º 12
0
    def parse_lights(self, layerelt, layer):
        """ create light nodes
		
		@type	layerelt:	object
		@param	layerelt:	ElementTree layer branch
		@type	layer:	object
		@param	layer:	FIFE layer object
		"""
        _LIGHT_DEFAULT_BLENDING_SRC = -1
        _LIGHT_DEFAULT_BLENDING_DST = -1
        _LIGHT_DEFAULT_SUBDIVISIONS = 32
        _LIGHT_DEFAULT_CAM_ID = 'default'
        _LIGHT_DEFAULT_INTENSITY = 128
        _LIGHT_DEFAULT_RADIUS = 10.0

        print("Processing lights ... ")
        lightelt = layerelt.find('lights')
        if not lightelt:
            print("\tno lights found on layer %s" % layer.getId())
            return

        lights = []
        for attr in ('l', 'light', 'lgt'):
            lights.extend(lightelt.findall(attr))

        for light in lights:
            group = light.get('group')
            if not group:
                print("Light has no group. Omitting...")
                continue

            blending_src = light.get('src')
            if not blending_src:
                blending_src = _LIGHT_DEFAULT_BLENDING_SRC
            blending_dst = light.get('dst')
            if not blending_dst:
                blending_dst = _LIGHT_DEFAULT_BLENDING_DST

            _x = light.get('x')
            if not _x: _x = 0
            _y = light.get('y')
            if not _y: _y = 0
            _z = light.get('y')
            if not _z: _z = 0

            node = {}
            node['blending_src'] = int(blending_src)
            node['blending_dst'] = int(blending_dst)
            node['layer'] = layer.getId()
            node['position'] = int(_x), int(_y), int(_z)

            # where is the light? *sing*
            instance_id = light.get('instance')
            node['instance'] = None
            if instance_id and layer.getInstance(instance_id):
                node['instance'] = instance_id

            type = light.get('type')
            if type:
                s_ref = light.get('s_ref')
                if not s_ref: s_ref = -1
                node['s_ref'] = int(s_ref)
                a_ref = light.get('a_ref')
                if not a_ref: a_ref = 0.0
                node['a_ref'] = float(a_ref)

                if type == 'image':
                    image = light.get('image')
                    if not image:
                        print("Light has no image. Omitting...")
                        continue
                    node['type'] = 'image'
                    image = reverse_root_subfile(self.source, image)
                    img = self.image_manager.create(image)
                    node['image'] = img
                elif type == 'animation':
                    animation = light.get('animation')
                    if not animation:
                        print("Light has no animation. Omitting...")
                        continue
                    node['type'] = 'animation'
                    animation = reverse_root_subfile(self.source, animation)
                    anim = loadXMLAnimation(self.engine, animation)
                    node['animation'] = anim
                elif type == 'simple':
                    node['type'] = type
                    radius = light.get('radius')
                    if not radius: radius = _LIGHT_DEFAULT_RADIUS
                    node['radius'] = float(radius)

                    subdivisions = light.get('subdivisions')
                    if not subdivisions:
                        subdivisions = _LIGHT_DEFAULT_SUBDIVISIONS
                    node['subdivisions'] = int(subdivisions)

                    intensity = light.get('intensity')
                    if not intensity:
                        intensity = _LIGHT_DEFAULT_INTENSITY
                    node['intensity'] = int(intensity)

                    xstretch = light.get('xstretch')
                    if not xstretch: xstretch = 1.0
                    ystretch = light.get('ystretch')
                    if not ystretch: ystretch = 1.0
                    node['stretch'] = float(xstretch), float(ystretch)

                    color = light.get('color')
                    if not color: color = '%d,%d,%d' % (255, 255, 255)
                    node['color'] = ([int(c) for c in color.split(',')])

            else:
                continue

            cam_id = light.get('camera_id')
            if not cam_id: cam_id = _LIGHT_DEFAULT_CAM_ID

            if not cam_id in self.light_data:
                self.light_data[cam_id] = {}
            if group not in self.light_data[cam_id]:
                self.light_data[cam_id][group] = []

            self.light_data[cam_id][group].append(node)

        for camera, groups in self.light_data.items():
            print("Lights for camera %s" % camera)
            for group, lights in groups.items():
                print(group, lights)
Ejemplo n.º 13
0
    def parse_lights(self, layerelt, layer):
        """ create light nodes
		
		@type	layerelt:	object
		@param	layerelt:	ElementTree layer branch
		@type	layer:	object
		@param	layer:	FIFE layer object
		"""
        _LIGHT_DEFAULT_BLENDING_SRC = -1
        _LIGHT_DEFAULT_BLENDING_DST = -1
        _LIGHT_DEFAULT_SUBDIVISIONS = 32
        _LIGHT_DEFAULT_CAM_ID = "default"
        _LIGHT_DEFAULT_INTENSITY = 128
        _LIGHT_DEFAULT_RADIUS = 10.0

        print "Processing lights ... "
        lightelt = layerelt.find("lights")
        if not lightelt:
            print "\tno lights found on layer %s" % layer.getId()
            return

        lights = []
        for attr in ("l", "light", "lgt"):
            lights.extend(lightelt.findall(attr))

        for light in lights:
            group = light.get("group")
            if not group:
                print "Light has no group. Omitting..."
                continue

            blending_src = light.get("src")
            if not blending_src:
                blending_src = _LIGHT_DEFAULT_BLENDING_SRC
            blending_dst = light.get("dst")
            if not blending_dst:
                blending_dst = _LIGHT_DEFAULT_BLENDING_DST

            _x = light.get("x")
            if not _x:
                _x = 0
            _y = light.get("y")
            if not _y:
                _y = 0
            _z = light.get("y")
            if not _z:
                _z = 0

            node = {}
            node["blending_src"] = int(blending_src)
            node["blending_dst"] = int(blending_dst)
            node["layer"] = layer.getId()
            node["position"] = int(_x), int(_y), int(_z)

            # where is the light? *sing*
            instance_id = light.get("instance")
            node["instance"] = None
            if instance_id and layer.getInstance(instance_id):
                node["instance"] = instance_id

            type = light.get("type")
            if type:
                s_ref = light.get("s_ref")
                if not s_ref:
                    s_ref = -1
                node["s_ref"] = int(s_ref)
                a_ref = light.get("a_ref")
                if not a_ref:
                    a_ref = 0.0
                node["a_ref"] = float(a_ref)

                if type == "image":
                    image = light.get("image")
                    if not image:
                        print "Light has no image. Omitting..."
                        continue
                    node["type"] = "image"
                    image = reverse_root_subfile(self.source, image)
                    img = self.image_manager.create(image)
                    node["image"] = img
                elif type == "animation":
                    animation = light.get("animation")
                    if not animation:
                        print "Light has no animation. Omitting..."
                        continue
                    node["type"] = "animation"
                    animation = reverse_root_subfile(self.source, animation)
                    anim = loadXMLAnimation(self.engine, animation)
                    node["animation"] = anim
                elif type == "simple":
                    node["type"] = type
                    radius = light.get("radius")
                    if not radius:
                        radius = _LIGHT_DEFAULT_RADIUS
                    node["radius"] = float(radius)

                    subdivisions = light.get("subdivisions")
                    if not subdivisions:
                        subdivisions = _LIGHT_DEFAULT_SUBDIVISIONS
                    node["subdivisions"] = int(subdivisions)

                    intensity = light.get("intensity")
                    if not intensity:
                        intensity = _LIGHT_DEFAULT_INTENSITY
                    node["intensity"] = int(intensity)

                    xstretch = light.get("xstretch")
                    if not xstretch:
                        xstretch = 1.0
                    ystretch = light.get("ystretch")
                    if not ystretch:
                        ystretch = 1.0
                    node["stretch"] = float(xstretch), float(ystretch)

                    color = light.get("color")
                    if not color:
                        color = "%d,%d,%d" % (255, 255, 255)
                    node["color"] = [int(c) for c in color.split(",")]

            else:
                continue

            cam_id = light.get("camera_id")
            if not cam_id:
                cam_id = _LIGHT_DEFAULT_CAM_ID

            if not cam_id in self.light_data:
                self.light_data[cam_id] = {}
            if group not in self.light_data[cam_id]:
                self.light_data[cam_id][group] = []

            self.light_data[cam_id][group].append(node)

        for camera, groups in self.light_data.iteritems():
            print "Lights for camera %s" % camera
            for group, lights in groups.iteritems():
                print group, lights