def save_images(self, images, object): """ save image definitions @type images: list @param images: list of <image> elements @type object: fife.Object @param object: the object which should be saved """ visual = object.get2dGfxVisual() angles = visual.getStaticImageAngles() if self.debug: print("\t\tobject angles: ", angles) for element in images: angle = int(element.get("direction")) if angle not in angles: continue index = visual.getStaticImageIndexByAngle(angle) image = self.img_manager.get(index) x_offset = image.getXShift() y_offset = image.getYShift() if 'x_offset' not in element.attrib or int(element.attrib['x_offset']) != x_offset: self.change = True if 'y_offset' not in element.attrib or int(element.attrib['y_offset']) != y_offset: self.change = True element.attrib['x_offset'] = str(x_offset) element.attrib['y_offset'] = str(y_offset) if self.debug and self.change: print("\tSet new data in xml tree: (<image>) ") print("\t\tx offset: ", element.attrib['x_offset']) print("\t\ty offset: ", element.attrib['y_offset'])
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())
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())
def save_images(self, images, object): """ save image definitions @type images: list @param images: list of <image> elements @type object: fife.Object @param object: the object which should be saved """ visual = object.get2dGfxVisual() angles = visual.getStaticImageAngles() if self.debug: print("\t\tobject angles: ", angles) for element in images: angle = int(element.get("direction")) if angle not in angles: continue index = visual.getStaticImageIndexByAngle(angle) image = self.img_manager.get(index) x_offset = image.getXShift() y_offset = image.getYShift() if 'x_offset' not in element.attrib or int( element.attrib['x_offset']) != x_offset: self.change = True if 'y_offset' not in element.attrib or int( element.attrib['y_offset']) != y_offset: self.change = True element.attrib['x_offset'] = str(x_offset) element.attrib['y_offset'] = str(y_offset) if self.debug and self.change: print("\tSet new data in xml tree: (<image>) ") print("\t\tx offset: ", element.attrib['x_offset']) print("\t\ty offset: ", element.attrib['y_offset'])
def parse_instances(self, layerelt, layer): """ create all layers and their instances @type layerelt: object @param layerelt: ElementTree layer branch @type layer: object @param layer: FIFE layer object """ instelt = layerelt.find('instances') instances = [] for attr in ('i', 'inst', 'instance'): instances.extend(instelt.findall(attr)) for instance in instances: _id = instance.get('id') if not _id: _id = '' objectID = '' for attr in ('o', 'object', 'obj'): objectID = instance.get(attr) if objectID: break if not objectID: self._err('<instance> %s does not specify an object attribute.' % str(objectID)) objectID = str(objectID) nspace = '' for attr in ('namespace', 'ns'): nspace = instance.get(attr) if nspace: break # try to reuse the previous namespace if not nspace and self.nspace: nspace = self.nspace if not nspace and not self.nspace: self._err('<instance> %s does not specify an object namespace, and no default is available.' % str(objectID)) nspace = str(nspace) self.nspace = nspace # check if there is an object for this instance available, if not -> skip this one object = self.model.getObject(objectID, nspace) if not object: print("Object with id=%s, ns=%s could not be found. Omitting..." % (objectID, nspace)) continue x = instance.get('x') if x: self.x = x = float(x) else: x = self.x y = instance.get('y') if y: self.y = y = float(y) else: y = self.y z = instance.get('z') if z: z = float(z) else: z = 0.0 inst = layer.createInstance(object, fife.ExactModelCoordinate(x,y,z), _id) rotation = 0 for attr in ('r', 'rotation'): rotation = instance.get(attr) if rotation: break if not rotation: angles = object.get2dGfxVisual().getStaticImageAngles() if angles: rotation = angles[0] else: rotation = 0 else: rotation = int(rotation) inst.setRotation(rotation) over_block = instance.get('override_blocking') if over_block is not None: inst.setOverrideBlocking(bool(over_block)) blocking = instance.get('blocking') if blocking is not None: inst.setBlocking(bool(int(blocking))) fife.InstanceVisual.create(inst) stackpos = instance.get('stackpos') if stackpos: inst.get2dGfxVisual().setStackPosition(int(stackpos)) if (object.getAction('default')): target = fife.Location(layer) inst.actRepeat('default', target)
def parse_instances(self, layerelt, layer): """ create all layers and their instances @type layerelt: object @param layerelt: ElementTree layer branch @type layer: object @param layer: FIFE layer object """ instelt = layerelt.find('instances') instances = [] for attr in ('i', 'inst', 'instance'): instances.extend(instelt.findall(attr)) for instance in instances: _id = instance.get('id') if not _id: _id = '' objectID = '' for attr in ('o', 'object', 'obj'): objectID = instance.get(attr) if objectID: break if not objectID: self._err( '<instance> %s does not specify an object attribute.' % str(objectID)) objectID = str(objectID) nspace = '' for attr in ('namespace', 'ns'): nspace = instance.get(attr) if nspace: break # try to reuse the previous namespace if not nspace and self.nspace: nspace = self.nspace if not nspace and not self.nspace: self._err( '<instance> %s does not specify an object namespace, and no default is available.' % str(objectID)) nspace = str(nspace) self.nspace = nspace # check if there is an object for this instance available, if not -> skip this one object = self.model.getObject(objectID, nspace) if not object: print( "Object with id=%s, ns=%s could not be found. Omitting..." % (objectID, nspace)) continue x = instance.get('x') if x: self.x = x = float(x) else: x = self.x y = instance.get('y') if y: self.y = y = float(y) else: y = self.y z = instance.get('z') if z: z = float(z) else: z = 0.0 inst = layer.createInstance(object, fife.ExactModelCoordinate(x, y, z), _id) rotation = 0 for attr in ('r', 'rotation'): rotation = instance.get(attr) if rotation: break if not rotation: angles = object.get2dGfxVisual().getStaticImageAngles() if angles: rotation = angles[0] else: rotation = 0 else: rotation = int(rotation) inst.setRotation(rotation) over_block = instance.get('override_blocking') if over_block is not None: inst.setOverrideBlocking(bool(over_block)) blocking = instance.get('blocking') if blocking is not None: inst.setBlocking(bool(int(blocking))) fife.InstanceVisual.create(inst) stackpos = instance.get('stackpos') if stackpos: inst.get2dGfxVisual().setStackPosition(int(stackpos)) if (object.getAction('default')): target = fife.Location(layer) inst.actRepeat('default', target)