Beispiel #1
0
    def unload(self, label):
        updateInfos(self.defaultValues, label)

        if len(self.defaultValues.keys()) == 0:
            return

        defaultLabel = LabelParser().unparse(self.defaultValues)
        node = self.svg.getAndCreateMetadataNode()
        node.set(addNS('default_xmoto_label', 'xmoto'), defaultLabel)
Beispiel #2
0
    def addPath(self, path):
        # put None if a value is different in at least two path
        label = path.get(addNS('xmoto_label', 'xmoto'), '')
        label = LabelParser().parse(label)

        self.defVals.addElementLabel(label)

        elementId = path.get('id', '')
        for name, value in label.iteritems():
            if type(value) == dict:
                namespace    = name
                namespaceDic = value

                # save original xmotoLabel to put back parameters not
                # modified by this extension
                if (self.namespacesInCommon is not None
                    and namespace not in self.namespacesInCommon):
                    createIfAbsent(self.originalValues, elementId)
                    createIfAbsent(self.originalValues[elementId], namespace)
                    for var, value in namespaceDic.iteritems():
                        self.originalValues[elementId][namespace][var] = value
                    continue

                createIfAbsent(self.comVals, namespace)

                for (name, value) in namespaceDic.iteritems():
                    if name in self.comVals[namespace]:
                        if self.comVals[namespace][name] != value:
                            self.comVals[namespace][name] = None
                    else:
                        self.comVals[namespace][name] = value
            else:
                if name in self.comVals:
                    if self.comVals[name] != value:
                        self.comVals[name] = None
                else:
                    self.comVals[name] = value
Beispiel #3
0
class XmExtGtkLevel(XmExtGtk):
    """ update level's properties
    """
    def load(self):
        (self.node, metadata) = self.svg.getMetaData()
        self.label = LabelParser().parse(metadata)

    def store(self, widget):
        try:
            self.fillResults(self.label)
            self.updateLabelData()
        except Exception, e:
            logging.error(str(e))
            xmGuiGtk.errorMessageBox(str(e))
            return

        metadata = LabelParser().unparse(self.label)

        if self.node is not None:
            self.node.text = metadata
        else:
            self.svg.createMetadata(metadata)

        xmGuiGtk.quit()
Beispiel #4
0
    def updateNodeSvgAttributes(self, node, label, style):
        node = convertToXmNode(node, self.svg)
        labelValue = LabelParser().unparse(label)
        styleValue = StyleParser().unparse(style)

        # if the user select the an element in the sublayer using the
        # 'circle tool' for example, the selected node will be that
        # element, not the sublayer (the sublayer is selected when you
        # use the 'selection tool').
        # in this case, use the sublayer instead of the selected child
        if node.belongsToSubLayer() == True:
            node = convertToXmNode(node.getparent())

        # update node shape
        # ugly and clumsy but will be refactored with xmObjects later
        if 'typeid' in label:
            # entity or zone
            typeid = label['typeid']

            if typeid in [
                    'PlayerStart', 'EndOfLevel', 'Strawberry', 'Wrecker',
                    'Checkpoint'
            ]:
                if typeid == 'EndOfLevel':
                    typeid = 'Flower'

                metadata = self.svg.getMetaDataValue()
                metadata = LabelParser().parse(metadata)

                if typeid == 'Checkpoint':
                    # the checkpoint sprite is called with _1
                    createIfAbsent(metadata, 'remplacement')
                    metadata['remplacement']['Checkpoint'] = 'Checkpoint_1'

                texName = getValue(metadata,
                                   'remplacement',
                                   typeid,
                                   default=typeid)
                scale = float(
                    getValue(metadata, 'remplacement', typeid + 'Scale', 1.0))
                _reversed = getBoolValue(label, 'position', 'reversed')
                rotation = float(getValue(label, 'position', 'angle', 0.0))
                radius = ENTITY_RADIUS[typeid] / SVG2LVL_RATIO

                node.setNodeAsBitmap(self.svg, texName, radius, SPRITES,
                                     labelValue, styleValue, scale, _reversed,
                                     rotation)

            elif typeid == 'ParticleSource':
                texName = getValue(label, 'param', 'type', '')
                radius = ENTITY_RADIUS[typeid] / SVG2LVL_RATIO

                node.setNodeAsBitmap(self.svg, texName, radius,
                                     PARTICLESOURCES, labelValue, styleValue)

            elif typeid == 'Sprite':
                texName = getValue(label, 'param', 'name', '')
                scale = float(getValue(label, 'size', 'scale', 1.0))
                _reversed = getBoolValue(label, 'position', 'reversed')
                rotation = float(getValue(label, 'position', 'angle', 0.0))
                radius = ENTITY_RADIUS['Sprite'] / SVG2LVL_RATIO

                node.setNodeAsBitmap(self.svg, texName, radius, SPRITES,
                                     labelValue, styleValue, scale, _reversed,
                                     rotation)

            elif typeid == 'Zone':
                (node, aabb) = node.subLayerElementToSingleNode()
                node.setNodeAsRectangle(aabb)
                # we may have set the label and still to a child of
                # 'g', and now node is the 'g', so we have to set it
                # to it too.
                node.setStyleLabel(labelValue, styleValue)

            elif typeid == 'Joint':
                # the addJoint extension already create the joints
                # with the right shape
                pass

            else:
                raise Exception("typeid=%s not handled by \
updateNodeSvgAttributes" % typeid)

        else:
            # block
            if node.isSubLayer(type=XmNode.BITMAP) == True:
                log.outMsg("Can't convert an entity to a block")
                return
#            elif (getValue(label, 'usetexture', 'color_r', 255) != 255
#                or getValue(label, 'usetexture', 'color_g', 255) != 255
#                or getValue(label, 'usetexture', 'color_b', 255) != 255):
#                # a color is not 255, we have to set two blocks, one
#                # textured and one colored
#                coloredStyle = self.generateStyle(label, coloredBlock=True)
#                coloredStyleValue = StyleParser().unparse(coloredStyle)
#
#                g = node.getSubLayerNode()
#                g.addColoredChildren(node, labelValue, styleValue, coloredStyleValue)
            else:
                if node.isSubLayer(type=XmNode.BLOCK) == True:
                    # remove sublayer and colored block
                    node.removeColoredChildren(labelValue, styleValue)
                else:
                    # nothing to do
                    pass

        node.setStyleLabel(labelValue, styleValue)
Beispiel #5
0
 def load(self, svg):
     self.svg = svg
     node = self.svg.getMetaDataNode()
     if node is not None:
         label = node.get(addNS('default_xmoto_label', 'xmoto'), '')
         self.defaultValues = LabelParser().parse(label)
Beispiel #6
0
class DefaultValues:
    def __init__(self):
        self.defaultValues = {}
        self.svg = None
        self.useDefault = True

    def addElementLabel(self, label):
        """ load default values only for new elements with no xmoto_label
        """
        if len(label.keys()) != 0:
            self.useDefault = False

    def load(self, svg):
        self.svg = svg
        node = self.svg.getMetaDataNode()
        if node is not None:
            label = node.get(addNS('default_xmoto_label', 'xmoto'), '')
            self.defaultValues = LabelParser().parse(label)

    def unload(self, label):
        updateInfos(self.defaultValues, label)

        if len(self.defaultValues.keys()) == 0:
            return

        defaultLabel = LabelParser().unparse(self.defaultValues)
        node = self.svg.getAndCreateMetadataNode()
        node.set(addNS('default_xmoto_label', 'xmoto'), defaultLabel)

    def get(self, dictValues, namespace, name=None, default=None):
        value = getValue(dictValues, namespace, name, None)
        if value is None:
            if self.useDefault == True:
                value = getValue(self.defaultValues, namespace, name, None)
                if value is None:
                    return default
                else:
                    return value
            else:
                return default
        else:
            return value

    def delWoExcept(self, _dict, key, namespace=None):
        delWoExcept(_dict, key, namespace)
        delWoExcept(self.defaultValues, key, namespace)

    def setOrDelBool(self, _dict, namespace, key, value):
        if setOrDelBool(_dict[namespace], key, value) == False:
            delWoExcept(self.defaultValues, key, namespace)

    def setOrDelBitmap(self, _dict, namespace, key, bitmapName):
        if setOrDelBitmap(_dict[namespace], key, bitmapName) == False:
            delWoExcept(self.defaultValues, key, namespace)

    def setOrDelColor(self, _dict, namespace, prefix, color):
        if setOrDelColor(_dict[namespace], prefix, color) == False:
            delWoExcept(self.defaultValues, prefix + '_r', namespace)
            delWoExcept(self.defaultValues, prefix + '_g', namespace)
            delWoExcept(self.defaultValues, prefix + '_b', namespace)
            delWoExcept(self.defaultValues, prefix + '_a', namespace)

    def setOrDelValue(self, _dict, namespace, key, value, default=None):
        if setOrDelValue(_dict[namespace], key, value, default) == False:
            delWoExcept(self.defaultValues, key, namespace)
Beispiel #7
0
 def load(self):
     (self.node, metadata) = self.svg.getMetaData()
     self.label = LabelParser().parse(metadata)