def convert(raw_path):
    src = os.path.join(config.RAW_RESOURCE_PATH, config.TARGET, raw_path)
    print "parse xml %s"%src
    xmldoc = xml.dom.minidom.parse(src)
    srcKey = util.get_path_key(raw_path)
    root = xmldoc.documentElement
    dest = os.path.join(config.BIN_RESOURCE_PATH, config.TARGET, str(srcKey))
    sprite_name = raw_path[7:-4].replace("\\", "_")
    out = open(dest, "wb")
    
    #for test
    #out.write(struct.pack("h", -10));
    #image
    imagesNode = root.getElementsByTagName("images")[0]
    sprite.convert_images(imagesNode, out)
    
    #modules
    modulesNode = root.getElementsByTagName("modules")[0]
    sprite.convert_modules(modulesNode, out)
    
    #patch
    patchesNode = root.getElementsByTagName("magicbgs")[0]
    convert_patches(patchesNode, out)
    logging.info("convert patch_sprite %s"%dest)
    out.close()
    gen.add_item("patch_sprite", (sprite_name, srcKey))
Example #2
0
def convert(raw_path):
    """
    raw_path 相对路径,去掉taget之后的路径
    """
    src = os.path.join(config.RAW_RESOURCE_PATH, config.TARGET, raw_path)
    print "parse xml %s" % src
    xmldoc = xml.dom.minidom.parse(src)
    srcKey = util.get_path_key(raw_path)
    root = xmldoc.documentElement
    dest = os.path.join(config.BIN_RESOURCE_PATH, config.TARGET, str(srcKey))
    sprite_name = raw_path[7:-4].replace("\\", "_")
    out = open(dest, "wb")

    # for test
    # out.write(struct.pack("h", -10));
    # image
    imagesNode = root.getElementsByTagName("images")[0]
    convert_images(imagesNode, out)

    # modules
    modulesNode = root.getElementsByTagName("modules")[0]
    convert_modules(modulesNode, out)

    # frames
    framesNode = root.getElementsByTagName("frames")[0]
    convert_frames(framesNode, out)

    # actions
    actionsNodes = root.getElementsByTagName("actions")
    if actionsNodes:
        convert_actions(actionsNodes[0], out)

    out.close()
    gen.add_item("sprite", (sprite_name, srcKey))
def convert(src, dest):
    xmldoc = xml.dom.minidom.parse(src)
    stringDict = {}
    root = xmldoc.documentElement
    out = open(dest, "wb")
    stringNodes = root.getElementsByTagName("string")
    stringCount = len(stringNodes)
    out.write(struct.pack("H", stringCount))
    index = 0
    for stringNode in stringNodes:
        key = stringNode.getAttribute("name")
        value = stringNode.childNodes[0].nodeValue
        print key,value
        if key in stringDict:
            print "Error, dump key key %s"%key
            return 
        else:
            stringDict[key] = value
        utf8Value = value.encode("utf-8")
        # 网络字节序写入长度
        out.write(struct.pack("!h", len(utf8Value)))
        out.write(utf8Value)   
        gen.add_item("string", (key, index))
        index += 1
    out.close()
Example #4
0
def convert(scene_path):
    src = os.path.join(config.RAW_RESOURCE_PATH, config.TARGET, scene_path)
    xmldoc = xml.dom.minidom.parse(src)
    root = xmldoc.documentElement
    key = util.get_path_key(scene_path)
    dest = os.path.join(config.BIN_RESOURCE_PATH, config.TARGET, str(key))
    out = open(dest, "wb")
    #parser_node(root, out, controlItems, 0, "")
    out.close()
    scenename = os.path.split(scene_path)[1][0:-4]
    gen.add_item("scene", (scenename, key))
Example #5
0
def convert(src):
    xmldoc = xml.dom.minidom.parse(src)
    keyDict = {}
    root = xmldoc.documentElement
    colorNodes = root.getElementsByTagName("color")
    for colorNode in colorNodes:
        key = colorNode.getAttribute("name")
        value = colorNode.childNodes[0].nodeValue
        print key,value
        if key in keyDict:
            print "Error, dump key key %s"%key
            return 
        else:
            keyDict[key] = value
        gen.add_item("color", (key, int(value, 16)))