【HTML5】Egret笔记(五):打包资源配置表(续)
2020-10-11
之前用shell打包,资源分组在单独表中,不易管理,另外纹理集[subkeys]键值也未解析出来,本次用python重新实现了一遍。
功能:default.res.json 中[groups]分组通过Egret Wing来可视化编辑。生成[resources]部分时,工具会先保存groups分组,然后遍历资源目录,根据资源名来得到egret格式的配置。
Github:
https://github.com/pury/SPTools/tree/master/egret/res_config
#!/usr/bin/env python
import os
import json
#指定资源目录
os.chdir("resource")
def main():
res = json.load(open('default.res.json', 'r'))
resources = {}
resourcesList = []
getRes("assets",resourcesList)
getRes("config", resourcesList)
resources["resources"] = resourcesList
res.update(resources)
json.dump(res, open("default.res.json","w"), False, True, True, True, None, 4)
def getRes(dir,resourcesList):
for dirpath,dirnames,filenames in os.walk(dir):
for file in filenames:
if (0 == file.find(".")):
continue
resource = {}
fileType = getType(file)
resource["url"] = dirpath.replace("\\","/") +"/"+ file
resource["type"] = fileType
resource["name"] = file.replace(".","_")
if (fileType == "sheet"):
resource["subkeys"] = getSubkeys(dirpath + "/" + file)
resourcesList.append(resource)
def getType(file):
if (-1 != file.find("sheet") and -1 != file.find("json")):
return "sheet"
if( -1 != file.find("json")):
return "json"
if (-1 != file.find("png") or -1 != file.find("jpg")):
return "image"
if (-1 != file.find("xml")):
return "xml"
if (-1 != file.find("mp3")):
return "sound"
def getSubkeys(file):
sheet = json.load(open(file,"r"))
subkeys = "";
for key in sheet["frames"]:
subkeys += key + ","
subkeys = subkeys.rstrip(",")
return subkeys
if __name__ == '__main__':
main()
(友情提醒:所有非项目发布时用到的文件建议全部移出Egret根目录。)