def writeBlockHead(self): def writeMaterial(side, texture, material): content = "\t\t\t<material name=\"%s\" edge=\"%s\" color_r=\"%d\" \ color_g=\"%d\" color_b=\"%d\" color_a=\"%d\"" % ( side, texture, material[0][0], material[0][1], material[0][2], material[0][3]) if material[1] is not None: content += " scale=\"%f\"" % material[1] if material[2] is not None: content += " depth=\"%f\"" % material[2] content += " />" self.content.append(content) self.content.append("\t<block id=\"%s\">" % self.curBlock) if self.u_material is not None or self.d_material is not None: delWoExcept(self.infos, 'edges') if self.edgeAngle != 270.0: self.content.append("\t\t<edges angle=\"%f\">" % self.edgeAngle) else: self.content.append("\t\t<edges>") if self.u_material is not None: writeMaterial('u', self.edgeTexture, self.u_material) if self.d_material is not None: writeMaterial('d', self.downEdgeTexture, self.d_material) self.content.append("\t\t</edges>") self.addElementParams()
def writeContent(self, options, level): """ - block: * background * dynamic * usetexture=texture_name """ def removeNonNormal(posParams, keys): """ only static blocks in layers other than main """ for key in keys: if key in posParams: del posParams[key] def removeNonMain(posParams): removeNonNormal(posParams, ['background', 'physics']) def removeForLayer(posParams): removeNonNormal(posParams, ['background', 'dynamic', 'physics']) def getEdgeColorAndScale(prefix): r = int(getValue(self.infos, 'edge', '%s_r' % prefix, default=255)) g = int(getValue(self.infos, 'edge', '%s_g' % prefix, default=255)) b = int(getValue(self.infos, 'edge', '%s_b' % prefix, default=255)) a = int(getValue(self.infos, 'edge', '%s_a' % prefix, default=255)) scale = getValue(self.infos, 'edge', '%s_scale' % prefix) if scale is not None: scale = float(scale) depth = getValue(self.infos, 'edge', '%s_depth' % prefix) if depth is not None: depth = float(depth) # ugly hack because xmoto 0.5.2 non set value for depth is -1.0f if depth == -1.0: depth += 0.0001 return ((r, g, b, a), scale, depth) self.curBlockCounter = 0 self.curBlock = self._id self.ratio = options['ratio'] self.newWidth = options['width'] self.newHeight = options['height'] self.smooth = options['smooth'] useSmooth = getBoolValue(self.infos, 'position', '_usesmooth') if useSmooth == True: (present, smooth) = getIfPresent(self.infos, 'position', '_smooth') if present == True: self.smooth = 90.0 + float(smooth) createIfAbsent(self.infos, 'position') if ('x' not in self.infos['position'] or 'y' not in self.infos['position']): self.infos['position']['x'] = '%f' % (-self.newWidth / 2.0) self.infos['position']['y'] = '%f' % (self.newHeight / 2.0) layerNumber = self.infos['layerid'] del self.infos['layerid'] layerLevel = level.getLayersType()[layerNumber] if layerLevel == 'static': pass elif layerLevel == '2ndStatic': self.infos['position']['islayer'] = "true" removeNonMain(self.infos['position']) else: self.infos['position']['islayer'] = "true" lid = str(level.getLayerBlock2Level()[layerNumber]) self.infos['position']['layerid'] = lid removeForLayer(self.infos['position']) if 'usetexture' not in self.infos: self.infos['usetexture'] = {'id': 'default'} self.edgeTexture = getValue(self.infos, 'edge', 'texture', '') self.downEdgeTexture = getValue(self.infos, 'edge', 'downtexture', '') for prefix in ['u', 'd']: ((r, g, b, a), scale, depth) = getEdgeColorAndScale(prefix) if (r != 255 or g != 255 or b != 255 or scale is not None or depth is not None): setattr(self, '%s_material' % prefix, ((r, g, b, a), scale, depth)) else: setattr(self, '%s_material' % prefix, None) self.edgeAngle = float(getValue(self.infos, 'edges', 'angle', 270.0)) delWoExcept(self.infos, 'edge') if 'physics' in self.infos: if 'infinitemass' in self.infos['physics']: if self.infos['physics']['infinitemass'] == 'true': self.infos['physics']['mass'] = 'INFINITY' del self.infos['physics']['infinitemass'] self.preProcessVertex() for vertex in self.blocks: self.writeBlockHead() self.writeBlockVertex(vertex) self.content.append("\t</block>") self.curBlockCounter += 1 self.curBlock = self._id + str(self.curBlockCounter) return self.content
def setOrDelValue(self, _dict, namespace, key, value, default=None): if setOrDelValue(_dict[namespace], key, value, default) == False: delWoExcept(self.defaultValues, key, namespace)
def writeLevelHead(self): head = [] _id = getValue(self.options, 'level', 'id', default='defaultId') rversion = self.options['lvl']['rversion'] name = getValue(self.options, 'level', 'name', default='defaultName') desc = getValue(self.options, 'level', 'desc', default='') author = getValue(self.options, 'level', 'author', default='') today = str(date.today()) if _id == '': _id = 'defaultId' if name == '': name = 'defaultName' head.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>") head.append("<level id=\"%s\" rversion=\"%s\">" % (_id, rversion)) head.append("\t<info>") head.append("\t\t<name>%s</name>" % name) head.append("\t\t<description>%s</description>" % desc) head.append("\t\t<author>%s</author>" % author) head.append("\t\t<date>%s</date>" % today) # sky sky = "\t\t<sky" if 'sky' in self.options: # drifted is useless when it's put to false drifted = getValue(self.options, 'sky', 'drifted', default='false') if drifted == 'false': delWoExcept(self.options['sky'], 'drifted') tex = getValue(self.options, 'sky', 'tex') if tex in NOTSET_BITMAP: tex = '' delWoExcept(self.options['sky'], 'tex') for skyParam, value in self.options['sky'].iteritems(): if not skyParam.startswith('_') and value != '': sky += ' %s="%s"' % (skyParam, value) sky += ">%s</sky>" % tex head.append(sky) else: sky += ">%s</sky>" % 'sky1' head.append(sky) # border border = getValue(self.options, 'level', 'tex') if border not in NOTSET_BITMAP: head.append("\t\t<border texture=\"%s\"/>" % border) # music music = getValue(self.options, 'level', 'music') if music not in NOTSET: head.append("\t\t<music name=\"%s\" />" % music) head.append("\t</info>") # remplacement if 'remplacement' in self.options: # we want to add to the level the <theme_replacements> # tags only if there's some theme replacements. first = True line = "\t\t<sprite_replacement old_name=\"%s\" new_name=\"%s\"/>" for key, value in self.options['remplacement'].iteritems(): if (value not in NOTSET and key.find('Scale') == -1 and key != value): if first == True: head.append("\t<theme_replacements>") first = False head.append(line % (key, value)) if first == False: head.append("\t</theme_replacements>") # layer if 'layer' in self.options: # only add the <layeroffsets> tag if there's really some layers first = True line = "\t\t<layeroffset x=\"%s\" y=\"%s\" frontlayer=\"%s\"/>" layerInfos = self.options['layer'] for _id in self.layersType: if _id in ['static', '2ndStatic', 'unused']: continue if first == True: head.append("\t<layeroffsets>") first = False head.append(line % (layerInfos['layer_%d_x' % _id], layerInfos['layer_%d_y' % _id], layerInfos['layer_%d_isfront' % _id])) if first == False: head.append("\t</layeroffsets>") # limits head.append("\t<limits left=\"%f\" right=\"%f\" \ top=\"%f\" bottom=\"%f\"/>" % (self.limits['left'], self.limits['right'], self.limits['top'], self.limits['bottom'])) self.content.extend(head)
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 setOrDelBitmap(self, _dict, namespace, key, bitmapName): if setOrDelBitmap(_dict[namespace], key, bitmapName) == False: 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 delWoExcept(self, _dict, key, namespace=None): delWoExcept(_dict, key, namespace) delWoExcept(self.defaultValues, key, namespace)
def fillResultsPreHook(self): if self.namespacesToDelete == 'all': self.comVals.clear() else: for ns in self.namespacesToDelete: delWoExcept(self.comVals, ns)