123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- # -*- coding: utf-8 -*-
- import sys
- import json
- import os
- import libs.file_utils as file_utils
- import libs.biplist as biplist
- #修改ccb文件,重定位所有引用文件的路径
- #例如修改了ccbproject工程目录结构,ccb中的文件图片等重新指定位置
- #修改指定ccb节点下所有SpriteFrame(递归)
- def redirectAll(ccbNode, fileName2asset):
- properties = ccbNode['properties']
- #查找节点中的为SpriteFrame
- for curPorperty in properties:
- properType = curPorperty['type']
- if 'SpriteFrame' == properType:
- if 'value' in curPorperty:
- values = curPorperty['value']
- value0 = values[1]
- _, fileName = os.path.split(value0)
- if fileName in fileName2asset:
- values[0] = ''
- values[1] = fileName2asset[fileName]
- #print(fileName)
- if 'baseValue' in curPorperty:
- baseValues = curPorperty['baseValue']
- baseValue0 = baseValues[0]
- _, fileName = os.path.split(baseValue0)
- if fileName in fileName2asset:
- baseValues[0] = fileName2asset[fileName]
- #print(fileName)
- elif 'Texture' == properType:
- value = curPorperty['value']
- _, fileName = os.path.split(value)
- if fileName in fileName2asset:
- curPorperty['value'] = fileName2asset[fileName]
- #print(fileName)
- elif 'FntFile' == properType:
- value = curPorperty['value']
- _, fileName = os.path.split(value)
- if fileName in fileName2asset:
- curPorperty['value'] = fileName2asset[fileName]
- #print(fileName)
- elif 'CCBFile' == properType:
- value = curPorperty['value']
- _, fileName = os.path.split(value)
- if fileName in fileName2asset:
- curPorperty['value'] = fileName2asset[fileName]
- elif 'REDFile' == properType:
- value = curPorperty['value']
- _, fileName = os.path.split(value)
- if fileName in fileName2asset:
- curPorperty['value'] = fileName2asset[fileName]
- elif 'SpineSkel' == properType:
- value = curPorperty['value']
- _, fileName = os.path.split(value)
- if fileName in fileName2asset:
- curPorperty['value'] = fileName2asset[fileName]
- #print(fileName)
- #查找动时间线中使用SpriteFrame的
- if('animatedProperties' in ccbNode):
- animationProperties = ccbNode['animatedProperties']
- for nodeName in animationProperties:
- animProperty = animationProperties[nodeName]
- if('displayFrame' not in animProperty):
- continue
- displayFrame = animProperty['displayFrame']
- if('keyframes' not in displayFrame):
- continue
- keyframes = displayFrame['keyframes']
- for key in keyframes:
- values = key['value']
- val0 = values[0]
- val1 = values[1]
- _, fileName = os.path.split(val0)
- if fileName in fileName2asset:
- values[0] = fileName2asset[fileName]
- #print(val0)
- #递归子节点
- children = ccbNode['children']
- if(len(children) > 0):
- for child in children:
- redirectAll(child, fileName2asset)
- def excute(ccbProjFile):
- ccbProjFile = os.path.abspath(ccbProjFile)
- ccbProjRoot, _ = os.path.split(ccbProjFile)
- #读取ccb工程中设置的资源文件路径
- ccbProj = biplist.readPlist(ccbProjFile)
- resPaths = ccbProj['resourcePaths']
- ccbResDirs = []
- for tempItem in resPaths:
- curPath = tempItem['path']
- if '' != curPath:
- curPath = os.path.join(ccbProjRoot, curPath)
- curPath = os.path.abspath(curPath)
- ccbResDirs.append(curPath)
- #搜索所有ccb工程中的文件
- name2path = {}
- name2asset = {}
- for curDir in ccbResDirs:
- curDir = os.path.abspath(curDir)
- fileList = file_utils.findFiles(curDir, True, ['.png', '.jpg', '.fnt', '.red', '.skel', '.atlas'])
- for file in fileList:
- _, fileName = os.path.split(file)
- name2path[fileName] = file
- name2asset[fileName] = file[len(curDir) + 1:]
- for fileName in name2path:
- ccbFile = name2path[fileName]
- if(not ccbFile.endswith('.red')):
- continue
- print(ccbFile)
- plist = biplist.readPlist(ccbFile)
- nodeGraph = plist['nodeGraph']
- redirectAll(nodeGraph, name2asset)
- biplist.writePlist(plist, ccbFile, False)
- projFile = input("指定RED工程文件:").strip()
- projFile = os.path.abspath(projFile)
- excute(projFile)
|