def mapmonsterdb(): excel_file = 'MapDB.xls' client_template = 'mapmonsterdb.lua' client_output = 'mapmonsterdb.lua' client_output_dict = dict() client_output_dict['$MAPMONSTERDB$'] = converter_mapmonsterdb_data2(excel_file, 'mapmonster') gen_file(client_template, client_output, client_output_dict)
def equipdb(): excel_file = 'equipdb.xls' client_template = 'equipdb.lua' client_output = 'equipdb.lua' client_configs = { 'equip': { 'data_type': ['int', 'unicode', 'str'], 'data_template': '[%(s0)d]={"%(s1)s","%(s2)s"}', 'placeholder': '$EQUIPDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def itemdb(): excel_file = 'itemdb.xls' client_template = 'itemdb.lua' client_output = 'itemdb.lua' client_configs = { 'item': { 'data_type': ['int', 'unicode', 'str', 'int', 'int'], 'data_template': '[%(s0)d]={"%(s1)s","%(s2)s",%(s3)d,%(s4)d}', 'placeholder': '$ITEMDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def sampledb(): excel_file = 'MapDB.xls' client_template = 'MapDB.lua' client_output = 'MapDB.lua' client_configs = { 'MapDB':{ 'data_type':['int','str','str','str', 'str', 'str', 'str','int','int','int','int','int'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s","%(s3)s",{"%(s4)s"},{"%(s5)s"},%(s6)s,%(s7)d,%(s8)d,%(s9)d,%(s10)d,%(s11)d}', 'placeholder':'$MapDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def equipdb(): excel_file = 'equipdb.xls' client_template = 'equipdb.lua' client_output = 'equipdb.lua' client_configs = { 'equip':{ 'data_type':['int','unicode','str'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s"}', 'placeholder':'$EQUIPDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def stringdb(): excel_file = 'stringdb.xls' client_template = 'stringdb.lua' client_output = 'stringdb.lua' client_configs = { 'stringdb':{ 'data_type':['str','unicode'], 'data_template':'["%(s0)s"]="%(s1)s"', 'placeholder':'$STRINGDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def sampledb(): excel_file = 'sampledb.xls' client_template = 'sampledb.lua' client_output = 'sampledb.lua' client_configs = { 'sample':{ 'data_type':['int','unicode','unicode','int', 'int', 'int', 'int', 'int'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s",%(s3)d,%(s4)d,%(s5)d,%(s6)d,%(s7)d}', 'placeholder':'$SAMPLEDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def skilldb(): excel_file = 'skilldb.xls' client_template = 'skilldb.lua' client_output = 'skilldb.lua' client_configs = { 'skill':{ 'data_type':['int','unicode','unicode','unicode','int', 'str', 'int', 'int', 'int', 'str', 'int', 'int', 'str', 'str', 'str', 'int', 'int', 'str','str'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s", %(s4)d, {%(s5)s},%(s6)d, %(s7)d, %(s8)d, "%(s9)s", %(s10)d, %(s11)d, "%(s12)s", "%(s13)s", "%(s14)s", %(s15)d, %(s16)d,"%(s3)s","%(s17)s","%(s18)s"}', 'placeholder':'$SKILLDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def roledb(): excel_file = 'roledb.xls' client_template = 'roledb.lua' client_output = 'roledb.lua' client_configs = { 'role':{ 'data_type':['int','unicode','str','int', 'int', 'int', 'int', 'float', 'int','int', 'int', 'unicode','unicode', 'str','float','float','int','str'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s",%(s3)d,%(s4)d,%(s5)d,%(s6)d,%(s7).2f, %(s8)d,%(s9)d,%(s10)d,"%(s11)s","%(s12)s","%(s13)s",%(s14).2f,%(s15).2f,%(s16)d,{%(s17)s}}', 'placeholder':'$ROLEDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def stringres(argv_platform): """ """ excel_file = 'stringres.xlsx' server_template = 'stringres.php' # 后端配置文件模版 server_output = 'stringres.php' # 后端配置输出文件 server_configs = { 'stringres': { 'data_type': ['unicode', 'unicode', 'unicode'], 'data_template': '"%(s0)s"=>"%(s1)s"', 'placeholder': '$STRINGRES$' } } server_output_dict = converter_0(excel_file, server_configs, argv_platform) gen_file(server_template, server_output, server_output_dict, True)
def sampledb(): excel_file = 'sampledb.xls' client_template = 'sampledb.lua' client_output = 'sampledb.lua' client_configs = { 'sample': { 'data_type': ['int', 'unicode', 'unicode', 'int', 'int', 'int', 'int', 'int'], 'data_template': '[%(s0)d]={"%(s1)s","%(s2)s",%(s3)d,%(s4)d,%(s5)d,%(s6)d,%(s7)d}', 'placeholder': '$SAMPLEDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def roledb(): excel_file = 'roledb.xls' client_template = 'roledb.lua' client_output = 'roledb.lua' client_configs = { 'role': { 'data_type': [ 'int', 'unicode', 'str', 'int', 'int', 'int', 'int', 'float', 'int', 'int', 'int', 'unicode', 'unicode', 'str', 'float', 'float', 'int', 'str' ], 'data_template': '[%(s0)d]={"%(s1)s","%(s2)s",%(s3)d,%(s4)d,%(s5)d,%(s6)d,%(s7).2f, %(s8)d,%(s9)d,%(s10)d,"%(s11)s","%(s12)s","%(s13)s",%(s14).2f,%(s15).2f,%(s16)d,{%(s17)s}}', 'placeholder': '$ROLEDB$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def stringdb(): excel_file = 'stringdb.xls' client_template = 'stringdb.lua' client_output = 'stringdb.lua' client_configs = { 'stringdb': { 'data_type': ['str', 'unicode'], 'data_template': '["%(s0)s"]="%(s1)s"', 'placeholder': '$STRINGDB$' }, 'name': { 'data_type': ['int', 'unicode'], 'data_template': '[%(s0)d]="%(s1)s"', 'placeholder': '$NAMEDB$' }, 'prefix': { 'data_type': ['int', 'unicode'], 'data_template': '[%(s0)d]="%(s1)s"', 'placeholder': '$PREFIX$' } } client_output_dict = converter_0(excel_file, client_configs) gen_file(client_template, client_output, client_output_dict)
def convertImg(argv_type, argv_line, argv_platform, argv_lang, argv_start, argv_end): """ """ diff_flag = False if argv_start != -1 and argv_end != -1: diff_flag = True diff_list = list() if diff_flag: diff_list = getDiffList(argv_start, argv_end, argv_line) print diff_list excel_file = 'plist.xls' # excel配置文件,xls格式 client_template = 'resDB.lua' # 后端配置文件模版 client_output = 'resDB.lua' # 后端配置输出文件 plist_dict = converter_plist(excel_file, "plist", argv_type, argv_lang) #公共资源列表 book = xlrd.open_workbook('plist.xls') sheet = book.sheet_by_name('platform') print sheet.name publicres_dict = {} for i in xrange(1, sheet.nrows): # 循环sheet中的行 row_key = _utf8(sheet.cell_value(i, 0)) publicres_dict[row_key] = "" #多语言资源列表 book = xlrd.open_workbook('plist.xls') sheet = book.sheet_by_name('language') print sheet.name languageres_dict = {} for i in xrange(1, sheet.nrows): # 循环sheet中的行 row_key = _utf8(sheet.cell_value(i, 0)) languageres_dict[row_key] = "" #生成resDB row_texts = "" #win32不做plist need_raise = False if argv_type != 'win32': #判断平台不是为win32 for row_key, row_value in plist_dict.iteritems(): #处理图片 for j in xrange(0, len(row_value)): #拆分目录 img_flag = row_value[j][0] img_name = row_value[j][1] img_flag = getImageFlag(img_name) if img_flag == IMAGE_FLAG_JSON: continue #查找是否多平台文件 continue_flag, target_name = getPublicresFlag( img_name, publicres_dict, argv_platform) if continue_flag: continue else: img_name = target_name #查找是否多语言文件 continue_flag, target_name = getLanguageresFlag( img_name, languageres_dict, argv_lang) if continue_flag: continue else: img_name = target_name img_path = os.path.splitext(img_name)[0] #获得图片路径 if img_flag == 4: img_path = os.path.splitext(os.path.basename(img_name))[0] img_plist = row_key.replace('\\', '/') #选择代替的标识符 img_path = img_path.replace('\\', '#') #继续替换 type_format = row_value[j][2] #图片格式 #检查plist配置的图像转换是否正确 if argv_type.lower() in ['android', 'wp8']: if not os.path.exists(img_name): print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: img = Image.open(img_name) if img: if img.mode == 'RGBA': in_list = [ 'rgba8888', 'rgba4444', 'rgba5551', 'pvrtc4', 'dxt3', 'selflow', 'selfhigh', 'selfmiddle', 'none' ] elif img.mode == 'RGB': in_list = [ 'rgb888', 'rgb565', 'pvrtc4_noalpha', 'dxt1', 'none' ] else: in_list = ['none'] need_raise = True for data in in_list: if data in type_format: need_raise = False if need_raise: print img_name + " convert format error! need " + str( in_list) else: print img_name + '==open error!' raise if need_raise: raise if row_key.lower() != 'none': row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( img_path, img_plist + '.plist', 1, type_format) else: type_flag = 0 type_img_name = os.path.splitext( img_name.replace('\\', '/'))[0] type_img_ext = os.path.splitext(img_name.replace( '\\', '/'))[1] if type_img_ext.lower() != '.png': type_img_name = img_name.replace('\\', '/') else: if argv_type.lower() in ['ios', 'android', 'wp8']: if type_format == 'none': type_img_name = img_name.replace('\\', '/') type_flag = 0 else: type_img_name = type_img_name + '.plist' type_flag = 1 else: raise if img_name.find('\\ui\\') >= 0 or img_name.find( '\\audio\\') >= 0 or img_name.find( '\\json\\') >= 0 or img_name.find( '\\skilleffect\\') >= 0: if argv_type.lower() in ['ios', 'android', 'wp8']: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(img_name)[0].replace( '\\', '#'), type_img_name, type_flag, type_format) else: raise else: if argv_type.lower() in ['ios', 'android', 'wp8']: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(os.path.basename(img_name)) [0], type_img_name, type_flag, type_format) else: raise #遍历目录 path_dict = {} walkpath("res", path_dict) for row_key, row_value in path_dict.iteritems(): #处理图片 for j in xrange(0, len(row_value)): #拆分目录 img_path = row_key img_name = row_value[j] if img_name.find('.png') >= 0 or \ img_name.find('.mp3') >= 0 or \ img_name.find('.caf') >= 0 or \ img_name.find('.m4a') >= 0 or \ img_name.find('.ExportJson') >= 0 or \ img_name.find('.json') >= 0 or \ img_name.find('.csb') > 0 or \ img_name.find('.plist') > 0 or \ img_name.find('.fnt') > 0 or \ img_name.find('.ttf') > 0 or \ img_name.find('.ogg') >= 0 : pass else: continue img_flag = getImageFlag(img_name) #json文件夹只处理ExportJson文件 if img_flag == IMAGE_FLAG_JSON: if img_name.find('\\equip\\') >= 0: if img_name.find('.ExportJson') < 0 and img_name.find( '.plist') < 0: continue else: if img_name.find('.ExportJson') < 0: continue #查找是否已经被plist,win32不做plist continue_flag = getPlistedFlag(img_name, plist_dict, argv_type) if continue_flag: continue #查找是否有同名plist if img_flag == IMAGE_FLAG_NORMAL: found_flag = getPlistExistedFlag(img_name, path_dict, row_key) if found_flag: #row_texts = row_texts + '\t["%s"]={"%s",%d,""},\n'%(os.path.splitext(os.path.basename(img_name))[0],os.path.splitext(img_name.replace('\\','/'))[0],1) continue #查找是否多平台文件 continue_flag, target_name = getPublicresFlag( img_name, publicres_dict, argv_platform) if continue_flag: continue else: img_name = target_name #查找是否多语言文件 continue_flag, target_name = getLanguageresFlag( img_name, languageres_dict, argv_lang) if continue_flag: continue else: img_name = target_name #产生图像格式 type_format = getImageType(img_name, argv_type) type_flag = 0 type_img_name = os.path.splitext(img_name.replace('\\', '/'))[0] type_img_ext = os.path.splitext(img_name.replace('\\', '/'))[1] if type_img_ext.lower() != '.png': #音效文件特殊处理 if img_name.find('res\\audio\\') >= 0: if img_name.find('\\' + 'win32' + '\\') <= 0: continue else: img_name = img_name.replace('\\' + 'win32' + '\\', '\\') type_img_name = img_name.replace('\\', '/') if img_name.find('.plist') > 0: type_flag = 1 else: type_flag = 0 else: if argv_type.lower() == 'ios': type_img_name = type_img_name + '.plist' type_flag = 1 elif argv_type.lower() == 'android': if type_format == 'none': type_img_name = img_name.replace('\\', '/') type_flag = 0 else: type_img_name = type_img_name + '.plist' type_flag = 1 elif argv_type.lower() == 'wp8': if type_format == 'none': type_img_name = img_name.replace('\\', '/') type_flag = 0 else: type_img_name = type_img_name + '.plist' type_flag = 1 else: type_img_name = img_name.replace('\\', '/') if img_name.find('\\ui\\') >= 0 or img_name.find( '\\audio\\') >= 0 or img_name.find( '\\json\\') >= 0 or img_name.find( '\\skilleffect\\') >= 0: if argv_type.lower() in ['ios', 'android', 'wp8']: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(img_name)[0].replace( '\\', '#'), type_img_name, type_flag, type_format) else: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(img_name)[0].replace( '\\', '#'), type_img_name, type_flag, type_format) else: if argv_type.lower() in ['ios', 'android', 'wp8']: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(os.path.basename(img_name))[0], type_img_name, type_flag, type_format) else: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(os.path.basename(img_name))[0], type_img_name, type_flag, type_format) client_output_dict = {} client_output_dict["$RESPATH$"] = row_texts gen_file(client_template, client_output, client_output_dict, False) print 'plist ok! start convert!' #处理文件 if argv_type == 'win32': safeRmTree("..\\..\\client\\res") import time time.sleep(2) while os.path.exists("..\\..\\client\\res"): pass shutil.copytree('res', "..\\..\\client\\res", False, ignoreFile) if os.path.exists("..\\..\\client\\res\\audio"): shutil.rmtree("..\\..\\client\\res\\audio", True) os.makedirs("..\\..\\client\\res\\audio") #win32音效特殊处理 #for file_name in os.listdir("res\\audio\\win32\\"): # sub_path = os.path.join("res\\audio\\win32\\", file_name) # if os.path.isdir(sub_path): # continue # else: # safeCopy(sub_path,"..\\..\\client\\res\\audio") # copyFiles("res\\audio\\win32\\", "..\\..\\client\\res\\audio") #公共资源改名覆盖 for publicres_key in publicres_dict.iterkeys(): print 'win32 copy %s to %s' % ( "..\\..\\client\\" + publicres_key + "_" + argv_platform + ".png", "..\\..\\client\\" + publicres_key + ".png") shutil.copy( "..\\..\\client\\" + publicres_key + "_" + argv_platform + ".png", "..\\..\\client\\" + publicres_key + ".png") #多语言资源改名覆盖 if argv_lang != 'gbk' and argv_lang != 'multi': for languageres_key in languageres_dict.iterkeys(): print 'win32 copy %s to %s' % ( "..\\..\\client\\" + languageres_key + "_" + argv_lang + ".png", "..\\..\\client\\" + languageres_key + ".png") shutil.copy( "..\\..\\client\\" + languageres_key + "_" + argv_lang + ".png", "..\\..\\client\\" + languageres_key + ".png") return #处理配置的plist safeRmTree("temp\\") convert_flag = False for row_key, row_value in plist_dict.iteritems(): #处理图片 convert_flag = False for j in xrange(0, len(row_value)): #拆分目录 img_flag = row_value[j][0] img_name = row_value[j][1] img_format = row_value[j][2] img_path = os.path.dirname(img_name) + '\\' if img_flag == 4: img_path = "" img_flag = getImageFlag(img_name) copy_flag = 1 if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_FONT: copy_flag = 0 if row_key.lower() == 'none': if img_name.find('\\ui\\') >= 0 or img_name.find( '\\audio\\') >= 0 or img_name.find( '\\json\\') >= 0 or img_name.find( '\\skilleffect\\') >= 0: pass else: img_path = '' if not os.path.exists("temp\\" + img_path): os.makedirs("temp\\" + img_path) #查找是否多平台文件 continue_flag, target_name = getPublicresFlag( img_name, publicres_dict, argv_platform) if continue_flag: continue else: img_publicres_name = target_name #查找是否多语言文件 continue_flag, target_name = getLanguageresFlag( img_name, languageres_dict, argv_lang) if continue_flag: continue else: img_publicres_name = target_name if not os.path.exists(img_name): print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: safeCopy( img_name, "temp\\" + img_path + os.path.basename(img_publicres_name)) if img_name.replace('\\', '/') in diff_list: convert_flag = True if row_key.lower() == 'none': if (diff_flag and convert_flag) or not diff_flag: cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s" % ( '..\\..\\outputClient\\' + argv_type + '\\' + os.path.splitext(img_publicres_name)[0], getFormatFlag(argv_type, img_format), copy_flag, img_path) os.system(cmd_text) safeRmTree("temp\\") convert_flag = False else: safeRmTree("temp\\") convert_flag = False if row_key.lower() != 'none': if (diff_flag and convert_flag) or not diff_flag: cmd_text = "res\\xcopy.bat %s temp %s 1 %d" % ( '..\\..\\outputClient\\' + argv_type + '\\' + row_key, getFormatFlag(argv_type, img_format), copy_flag) os.system(cmd_text) #如果目标图没有生成,那么抛异常 if (not os.path.exists('..\\..\\outputClient\\' + argv_type + '\\' + row_key + '.png') ) and (not os.path.exists('..\\..\\outputClient\\' + argv_type + '\\' + row_key + '.pvr.ccz') ) and (not os.path.exists('..\\..\\outputClient\\' + argv_type + '\\' + row_key + '.dds')): raise safeRmTree("temp\\") else: safeRmTree("temp\\") #遍历处理其他文件 for row_key, row_value in path_dict.iteritems(): #处理图片 for j in xrange(0, len(row_value)): #拆分目录 img_path = row_key img_name = row_value[j] img_format = 'none' img_path = os.path.dirname(img_name) + '\\' if img_name.find('.png') >= 0 or \ img_name.find('.mp3') >= 0 or \ img_name.find('.caf') >= 0 or \ img_name.find('.m4a') >= 0 or \ img_name.find('.ExportJson') >= 0 or \ img_name.find('.csb') >= 0 or \ img_name.find('.json') >= 0 or \ img_name.find('.tmx') >= 0 or \ img_name.find('.plist') >= 0 or \ img_name.find('.fnt') >= 0 or \ img_name.find('.ttf') >= 0 or \ img_name.find('.ogg') >= 0 : pass else: continue img_flag = getImageFlag(img_name) copy_flag = 1 if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_FONT: copy_flag = 0 #查找是否已经被plist,win32不做plist continue_flag = getPlistedFlag(img_name, plist_dict, argv_type) if continue_flag: continue #查找是否有同名plist if img_flag == IMAGE_FLAG_NORMAL: found_flag = getPlistExistedFlag(img_name, path_dict, row_key) if found_flag: #复制过去 safeCopy( img_name, "..\\..\\outputClient\\" + argv_type + '\\' + img_path) img_plist = os.path.splitext(img_name)[0] + '.plist' safeCopy( img_plist, "..\\..\\outputClient\\" + argv_type + '\\' + img_path) continue #查找是否多平台文件 continue_flag, target_name = getPublicresFlag( img_name, publicres_dict, argv_platform) if continue_flag: continue else: img_publicres_name = target_name #查找是否多语言文件 continue_flag, target_name = getLanguageresFlag( img_name, languageres_dict, argv_lang) if continue_flag: continue else: img_publicres_name = target_name convert_flag = False if img_name.replace('\\', '/') in diff_list: convert_flag = True if (diff_flag and convert_flag) or not diff_flag: pass else: continue #产生图像格式 img_format = getImageType(img_name, argv_type) img_ext = os.path.splitext(img_name.replace('\\', '/'))[1] if img_ext.lower() != '.png': if img_flag == IMAGE_FLAG_NORMAL or img_flag == IMAGE_FLAG_FONT: #音效文件特殊处理 if img_path.find('res\\audio\\') >= 0: if img_path.find('\\' + 'win32' + '\\') <= 0: continue else: img_path = img_path.replace( '\\' + 'win32' + '\\', '\\') safeCopy( img_name, "..\\..\\outputClient\\" + argv_type + '\\' + img_path) elif img_flag == IMAGE_FLAG_JSON: safeCopy( img_name, "..\\..\\outputClient\\" + argv_type + '\\' + img_path) elif img_flag == IMAGE_FLAG_MAP: safeCopy( img_name, "..\\..\\outputClient\\" + argv_type + '\\' + img_path) elif img_flag == IMAGE_FLAG_CSB: safeCopy( img_name, "..\\..\\outputClient\\" + argv_type + '\\' + img_path) print 'copy ' + img_name else: if img_name.find('\\ui\\') >= 0 or img_name.find( '\\audio\\') >= 0 or img_name.find( '\\json\\') >= 0 or img_name.find( '\\skilleffect\\') >= 0: pass else: img_path = '' if not os.path.exists(img_name): print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: safeCopy( img_name, "temp\\" + img_path + os.path.basename(img_publicres_name)) cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s" % ( "..\\..\\outputClient\\" + argv_type + '\\' + os.path.splitext(img_publicres_name)[0], getFormatFlag(argv_type, img_format), copy_flag, img_path) os.system(cmd_text) safeRmTree("temp\\")
def convertImg(argv_type,argv_line,argv_platform,argv_lang,argv_start,argv_end): """ """ diff_flag = False if argv_start != -1 and argv_end != -1: diff_flag = True diff_list = list() if diff_flag: diff_list = getDiffList(argv_start,argv_end,argv_line) print diff_list excel_file = 'plist.xls' # excel配置文件,xls格式 client_template = 'resDB.lua' # 后端配置文件模版 client_output = 'resDB.lua' # 后端配置输出文件 plist_dict = converter_plist(excel_file,"plist",argv_type,argv_lang) #公共资源列表 book = xlrd.open_workbook('plist.xls') sheet = book.sheet_by_name('platform') print sheet.name publicres_dict = {} for i in xrange(1, sheet.nrows): # 循环sheet中的行 row_key = _utf8(sheet.cell_value(i, 0)) publicres_dict[row_key] = "" #多语言资源列表 book = xlrd.open_workbook('plist.xls') sheet = book.sheet_by_name('language') print sheet.name languageres_dict = {} for i in xrange(1, sheet.nrows): # 循环sheet中的行 row_key = _utf8(sheet.cell_value(i, 0)) languageres_dict[row_key] = "" #生成resDB row_texts = "" #win32不做plist need_raise = False if argv_type != 'win32':#判断平台不是为win32 for row_key,row_value in plist_dict.iteritems(): #处理图片 for j in xrange(0,len(row_value)): #拆分目录 img_flag = row_value[j][0] img_name = row_value[j][1] img_flag = getImageFlag(img_name) if img_flag == IMAGE_FLAG_JSON: continue #查找是否多平台文件 continue_flag,target_name = getPublicresFlag(img_name,publicres_dict,argv_platform) if continue_flag: continue else: img_name = target_name #查找是否多语言文件 continue_flag,target_name = getLanguageresFlag(img_name,languageres_dict,argv_lang) if continue_flag: continue else: img_name = target_name img_path = os.path.splitext(img_name)[0] #获得图片路径 if img_flag == 4: img_path = os.path.splitext(os.path.basename(img_name))[0] img_plist = row_key.replace('\\','/')#选择代替的标识符 img_path = img_path.replace('\\','#')#继续替换 type_format = row_value[j][2]#图片格式 #检查plist配置的图像转换是否正确 if argv_type.lower() in ['android','wp8']: if not os.path.exists(img_name): print img_name,"not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: img = Image.open(img_name) if img: if img.mode == 'RGBA': in_list = ['rgba8888','rgba4444','rgba5551','pvrtc4','dxt3','selflow','selfhigh','selfmiddle','none'] elif img.mode == 'RGB': in_list = ['rgb888','rgb565','pvrtc4_noalpha','dxt1','none'] else: in_list = ['none'] need_raise = True for data in in_list: if data in type_format: need_raise = False if need_raise: print img_name+" convert format error! need "+str(in_list) else: print img_name+'==open error!' raise if need_raise: raise if row_key.lower() != 'none': row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(img_path,img_plist+'.plist',1,type_format) else: type_flag = 0 type_img_name = os.path.splitext(img_name.replace('\\','/'))[0] type_img_ext = os.path.splitext(img_name.replace('\\','/'))[1] if type_img_ext.lower() != '.png': type_img_name = img_name.replace('\\','/') else: if argv_type.lower() in ['ios','android','wp8']: if type_format == 'none': type_img_name = img_name.replace('\\','/') type_flag = 0 else: type_img_name = type_img_name + '.plist' type_flag = 1 else: raise if img_name.find('\\ui\\') >= 0 or img_name.find('\\audio\\') >= 0 or img_name.find('\\json\\') >= 0 or img_name.find('\\skilleffect\\') >= 0: if argv_type.lower() in ['ios','android','wp8']: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(img_name)[0].replace('\\','#'),type_img_name,type_flag,type_format) else: raise else: if argv_type.lower() in ['ios','android','wp8']: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(os.path.basename(img_name))[0],type_img_name,type_flag,type_format) else: raise #遍历目录 path_dict = {} walkpath("res",path_dict) for row_key,row_value in path_dict.iteritems(): #处理图片 for j in xrange(0,len(row_value)): #拆分目录 img_path = row_key img_name = row_value[j] if img_name.find('.png') >= 0 or \ img_name.find('.mp3') >= 0 or \ img_name.find('.caf') >= 0 or \ img_name.find('.m4a') >= 0 or \ img_name.find('.ExportJson') >= 0 or \ img_name.find('.json') >= 0 or \ img_name.find('.csb') > 0 or \ img_name.find('.plist') > 0 or \ img_name.find('.fnt') > 0 or \ img_name.find('.ttf') > 0 or \ img_name.find('.ogg') >= 0 : pass else: continue img_flag = getImageFlag(img_name) #json文件夹只处理ExportJson文件 if img_flag == IMAGE_FLAG_JSON: if img_name.find('\\equip\\') >= 0: if img_name.find('.ExportJson') < 0 and img_name.find('.plist') < 0: continue else: if img_name.find('.ExportJson') < 0: continue #查找是否已经被plist,win32不做plist continue_flag = getPlistedFlag(img_name,plist_dict,argv_type) if continue_flag: continue #查找是否有同名plist if img_flag == IMAGE_FLAG_NORMAL: found_flag = getPlistExistedFlag(img_name,path_dict,row_key) if found_flag: #row_texts = row_texts + '\t["%s"]={"%s",%d,""},\n'%(os.path.splitext(os.path.basename(img_name))[0],os.path.splitext(img_name.replace('\\','/'))[0],1) continue #查找是否多平台文件 continue_flag,target_name = getPublicresFlag(img_name,publicres_dict,argv_platform) if continue_flag: continue else: img_name = target_name #查找是否多语言文件 continue_flag,target_name = getLanguageresFlag(img_name,languageres_dict,argv_lang) if continue_flag: continue else: img_name = target_name #产生图像格式 type_format = getImageType(img_name,argv_type) type_flag = 0 type_img_name = os.path.splitext(img_name.replace('\\','/'))[0] type_img_ext = os.path.splitext(img_name.replace('\\','/'))[1] if type_img_ext.lower() != '.png': #音效文件特殊处理 if img_name.find('res\\audio\\') >= 0: if img_name.find('\\'+'win32'+'\\') <= 0: continue else: img_name = img_name.replace('\\'+'win32'+'\\','\\') type_img_name = img_name.replace('\\','/') if img_name.find('.plist') > 0: type_flag = 1 else: type_flag = 0 else: if argv_type.lower() == 'ios': type_img_name = type_img_name + '.plist' type_flag = 1 elif argv_type.lower() == 'android': if type_format == 'none': type_img_name = img_name.replace('\\','/') type_flag = 0 else: type_img_name = type_img_name + '.plist' type_flag = 1 elif argv_type.lower() == 'wp8': if type_format == 'none': type_img_name = img_name.replace('\\','/') type_flag = 0 else: type_img_name = type_img_name + '.plist' type_flag = 1 else: type_img_name = img_name.replace('\\','/') if img_name.find('\\ui\\') >= 0 or img_name.find('\\audio\\') >= 0 or img_name.find('\\json\\') >= 0 or img_name.find('\\skilleffect\\') >= 0: if argv_type.lower() in ['ios','android','wp8']: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(img_name)[0].replace('\\','#'),type_img_name,type_flag,type_format) else: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(img_name)[0].replace('\\','#'),type_img_name,type_flag,type_format) else: if argv_type.lower() in ['ios','android','wp8']: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(os.path.basename(img_name))[0],type_img_name,type_flag,type_format) else: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n'%(os.path.splitext(os.path.basename(img_name))[0],type_img_name,type_flag,type_format) client_output_dict = {} client_output_dict["$RESPATH$"] = row_texts gen_file(client_template, client_output, client_output_dict, False) print 'plist ok! start convert!' #处理文件 if argv_type == 'win32': safeRmTree("..\\..\\client\\res") import time time.sleep(2) while os.path.exists("..\\..\\client\\res"): pass shutil.copytree('res', "..\\..\\client\\res",False,ignoreFile) if os.path.exists("..\\..\\client\\res\\audio"): shutil.rmtree("..\\..\\client\\res\\audio", True) os.makedirs("..\\..\\client\\res\\audio") #win32音效特殊处理 #for file_name in os.listdir("res\\audio\\win32\\"): # sub_path = os.path.join("res\\audio\\win32\\", file_name) # if os.path.isdir(sub_path): # continue # else: # safeCopy(sub_path,"..\\..\\client\\res\\audio") # copyFiles("res\\audio\\win32\\", "..\\..\\client\\res\\audio"); #公共资源改名覆盖 for publicres_key in publicres_dict.iterkeys(): print 'win32 copy %s to %s'%("..\\..\\client\\"+publicres_key+"_"+argv_platform+".png","..\\..\\client\\"+publicres_key+".png") shutil.copy("..\\..\\client\\"+publicres_key+"_"+argv_platform+".png","..\\..\\client\\"+publicres_key+".png") #多语言资源改名覆盖 if argv_lang != 'gbk' and argv_lang != 'multi': for languageres_key in languageres_dict.iterkeys(): print 'win32 copy %s to %s'%("..\\..\\client\\"+languageres_key+"_"+argv_lang+".png","..\\..\\client\\"+languageres_key+".png") shutil.copy("..\\..\\client\\"+languageres_key+"_"+argv_lang+".png","..\\..\\client\\"+languageres_key+".png") return #处理配置的plist safeRmTree("temp\\") convert_flag = False for row_key,row_value in plist_dict.iteritems(): #处理图片 convert_flag = False for j in xrange(0,len(row_value)): #拆分目录 img_flag = row_value[j][0] img_name = row_value[j][1] img_format = row_value[j][2] img_path = os.path.dirname(img_name) + '\\' if img_flag == 4: img_path = "" img_flag = getImageFlag(img_name) copy_flag = 1 if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_FONT: copy_flag = 0 if row_key.lower() == 'none': if img_name.find('\\ui\\') >= 0 or img_name.find('\\audio\\') >= 0 or img_name.find('\\json\\') >= 0 or img_name.find('\\skilleffect\\') >= 0: pass else: img_path = '' if not os.path.exists("temp\\"+img_path): os.makedirs("temp\\"+img_path) #查找是否多平台文件 continue_flag,target_name = getPublicresFlag(img_name,publicres_dict,argv_platform) if continue_flag: continue else: img_publicres_name = target_name #查找是否多语言文件 continue_flag,target_name = getLanguageresFlag(img_name,languageres_dict,argv_lang) if continue_flag: continue else: img_publicres_name = target_name if not os.path.exists(img_name): print img_name,"not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: safeCopy(img_name,"temp\\"+img_path+os.path.basename(img_publicres_name)) if img_name.replace('\\','/') in diff_list : convert_flag = True if row_key.lower() == 'none': if (diff_flag and convert_flag) or not diff_flag: cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s"%('..\\..\\outputClient\\'+argv_type+'\\'+os.path.splitext(img_publicres_name)[0],getFormatFlag(argv_type,img_format),copy_flag,img_path) os.system(cmd_text) safeRmTree("temp\\") convert_flag = False else: safeRmTree("temp\\") convert_flag = False if row_key.lower() != 'none': if (diff_flag and convert_flag) or not diff_flag: cmd_text = "res\\xcopy.bat %s temp %s 1 %d"%('..\\..\\outputClient\\'+argv_type+'\\'+row_key,getFormatFlag(argv_type,img_format),copy_flag) os.system(cmd_text) #如果目标图没有生成,那么抛异常 if (not os.path.exists('..\\..\\outputClient\\'+argv_type+'\\'+row_key+'.png')) and (not os.path.exists('..\\..\\outputClient\\'+argv_type+'\\'+row_key+'.pvr.ccz')) and (not os.path.exists('..\\..\\outputClient\\'+argv_type+'\\'+row_key+'.dds')): raise safeRmTree("temp\\") else: safeRmTree("temp\\") #遍历处理其他文件 for row_key,row_value in path_dict.iteritems(): #处理图片 for j in xrange(0,len(row_value)): #拆分目录 img_path = row_key img_name = row_value[j] img_format = 'none' img_path = os.path.dirname(img_name) + '\\' if img_name.find('.png') >= 0 or \ img_name.find('.mp3') >= 0 or \ img_name.find('.caf') >= 0 or \ img_name.find('.m4a') >= 0 or \ img_name.find('.ExportJson') >= 0 or \ img_name.find('.csb') >= 0 or \ img_name.find('.json') >= 0 or \ img_name.find('.tmx') >= 0 or \ img_name.find('.plist') >= 0 or \ img_name.find('.fnt') >= 0 or \ img_name.find('.ttf') >= 0 or \ img_name.find('.ogg') >= 0 : pass else: continue img_flag = getImageFlag(img_name) copy_flag = 1 if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_FONT: copy_flag = 0 #查找是否已经被plist,win32不做plist continue_flag = getPlistedFlag(img_name,plist_dict,argv_type) if continue_flag: continue #查找是否有同名plist if img_flag == IMAGE_FLAG_NORMAL: found_flag = getPlistExistedFlag(img_name,path_dict,row_key) if found_flag: #复制过去 safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path) img_plist = os.path.splitext(img_name)[0]+'.plist' safeCopy(img_plist,"..\\..\\outputClient\\"+argv_type+'\\'+img_path) continue #查找是否多平台文件 continue_flag,target_name = getPublicresFlag(img_name,publicres_dict,argv_platform) if continue_flag: continue else: img_publicres_name = target_name #查找是否多语言文件 continue_flag,target_name = getLanguageresFlag(img_name,languageres_dict,argv_lang) if continue_flag: continue else: img_publicres_name = target_name convert_flag = False if img_name.replace('\\','/') in diff_list : convert_flag = True if (diff_flag and convert_flag) or not diff_flag: pass else: continue #产生图像格式 img_format = getImageType(img_name,argv_type) img_ext = os.path.splitext(img_name.replace('\\','/'))[1] if img_ext.lower() != '.png': if img_flag == IMAGE_FLAG_NORMAL or img_flag == IMAGE_FLAG_FONT: #音效文件特殊处理 if img_path.find('res\\audio\\') >= 0: if img_path.find('\\'+'win32'+'\\') <= 0: continue else: img_path = img_path.replace('\\'+'win32'+'\\','\\') safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path) elif img_flag == IMAGE_FLAG_JSON: safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path) elif img_flag == IMAGE_FLAG_MAP: safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path) elif img_flag == IMAGE_FLAG_CSB: safeCopy(img_name,"..\\..\\outputClient\\"+argv_type+'\\'+img_path) print 'copy '+img_name else: if img_name.find('\\ui\\') >= 0 or img_name.find('\\audio\\') >= 0 or img_name.find('\\json\\') >= 0 or img_name.find('\\skilleffect\\') >= 0: pass else: img_path = '' if not os.path.exists(img_name): print img_name,"not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: safeCopy(img_name,"temp\\"+img_path+os.path.basename(img_publicres_name)) cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s"%("..\\..\\outputClient\\"+argv_type+'\\'+os.path.splitext(img_publicres_name)[0],getFormatFlag(argv_type,img_format),copy_flag,img_path) os.system(cmd_text) safeRmTree("temp\\")
def convertImg(argv_type, argv_line, argv_platform, argv_lang, argv_start, argv_end): """ """ diff_flag = False if argv_start != -1 and argv_end != -1: diff_flag = True diff_list = list() if diff_flag: diff_list = getDiffList(argv_start, argv_end, argv_line) print diff_list excel_file = "plist.xls" # excel配置文件,xls格式 client_template = "resDB.lua" # 后端配置文件模版 client_output = "resDB.lua" # 后端配置输出文件 plist_dict = converter_plist(excel_file, "plist", argv_type, argv_lang) # 公共资源列表 book = xlrd.open_workbook("plist.xls") sheet = book.sheet_by_name("platform") print sheet.name publicres_dict = {} for i in xrange(1, sheet.nrows): # 循环sheet中的行 row_key = _utf8(sheet.cell_value(i, 0)) publicres_dict[row_key] = "" # 多语言资源列表 book = xlrd.open_workbook("plist.xls") sheet = book.sheet_by_name("language") print sheet.name languageres_dict = {} for i in xrange(1, sheet.nrows): # 循环sheet中的行 row_key = _utf8(sheet.cell_value(i, 0)) languageres_dict[row_key] = "" # 生成resDB row_texts = "" # win32不做plist need_raise = False if argv_type != "win32": for row_key, row_value in plist_dict.iteritems(): # 处理图片 for j in xrange(0, len(row_value)): # 拆分目录 img_flag = row_value[j][0] img_name = row_value[j][1] img_flag = getImageFlag(img_name) if img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_JSON or img_flg == IMAGE_FLAG_CSB: continue # 查找是否多平台文件 continue_flag, target_name = getPublicresFlag(img_name, publicres_dict, argv_platform) if continue_flag: continue else: img_name = target_name # 查找是否多语言文件 continue_flag, target_name = getLanguageresFlag(img_name, languageres_dict, argv_lang) if continue_flag: continue else: img_name = target_name img_path = os.path.splitext(img_name)[0] if img_flag == 4: img_path = os.path.splitext(os.path.basename(img_name))[0] img_plist = row_key.replace("\\", "/") img_path = img_path.replace("\\", "#") type_format = row_value[j][2] # 检查plist配置的图像转换是否正确 if argv_type.lower() in ["android", "wp8"]: if not os.path.exists(img_name): print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: img = Image.open(img_name) if img: if img.mode == "RGBA": in_list = [ "rgba8888", "rgba4444", "rgba5551", "pvrtc4", "dxt3", "selflow", "selfhigh", "selfmiddle", ] elif img.mode == "RGB": in_list = ["rgb888", "rgb565", "pvrtc4_noalpha", "dxt1"] else: in_list = ["none"] need_raise = True for data in in_list: if data in type_format: need_raise = False if need_raise: print img_name + " convert format error! need " + str(in_list) else: print img_name + "==open error!" raise if need_raise: raise if row_key.lower() != "none": row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( img_path, img_plist + ".plist", 1, type_format, ) else: type_flag = 0 type_img_name = os.path.splitext(img_name.replace("\\", "/"))[0] type_img_ext = os.path.splitext(img_name.replace("\\", "/"))[1] if type_img_ext.lower() != ".png": type_img_name = img_name.replace("\\", "/") else: if argv_type.lower() in ["ios", "android", "wp8"]: if type_format == "none": type_img_name = img_name.replace("\\", "/") type_flag = 0 else: type_img_name = type_img_name + ".plist" type_flag = 1 else: raise if ( img_name.find("\\ui\\") >= 0 or img_name.find("\\audio\\") >= 0 or img_name.find("\\json\\") >= 0 or img_name.find("\\skilleffect\\") >= 0 ): if argv_type.lower() in ["ios", "android", "wp8"]: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(img_name)[0].replace("\\", "#"), type_img_name, type_flag, type_format, ) else: raise else: if argv_type.lower() in ["ios", "android", "wp8"]: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(os.path.basename(img_name))[0], type_img_name, type_flag, type_format, ) else: raise # 遍历目录 path_dict = {} walkpath("res", path_dict) for row_key, row_value in path_dict.iteritems(): # 处理图片 for j in xrange(0, len(row_value)): # 拆分目录 img_path = row_key img_name = row_value[j] if ( img_name.find(".png") >= 0 or img_name.find(".mp3") >= 0 or img_name.find(".caf") >= 0 or img_name.find(".m4a") >= 0 or img_name.find(".ExportJson") >= 0 or img_name.find(".json") >= 0 or img_name.find(".csb") > 0 or img_name.find(".plist") > 0 or img_name.find(".ogg") >= 0 ): pass else: continue img_flag = getImageFlag(img_name) # json文件夹只处理ExportJson文件 if img_flag == IMAGE_FLAG_JSON: if img_name.find("\\equip\\") >= 0: if img_name.find(".ExportJson") < 0 and img_name.find(".plist") < 0: continue else: if img_name.find(".ExportJson") < 0: continue # map文件夹只处理json文件 if img_flag == IMAGE_FLAG_MAP and img_name.find(".json") < 0: continue # csb文件夹只处理csb文件 if img_flag == IMAGE_FLAG_CSB and img_name.find(".csb") < 0: continue # 查找是否已经被plist,win32不做plist continue_flag = getPlistedFlag(img_name, plist_dict, argv_type) if continue_flag: continue # 查找是否有同名plist if img_flag == IMAGE_FLAG_NORMAL: found_flag = getPlistExistedFlag(img_name, path_dict, row_key) if found_flag: row_texts = row_texts + '\t["%s"]={"%s",%d,""},\n' % ( os.path.splitext(os.path.basename(img_name))[0], os.path.splitext(img_name.replace("\\", "/"))[0], 1, ) continue # 查找是否多平台文件 continue_flag, target_name = getPublicresFlag(img_name, publicres_dict, argv_platform) if continue_flag: continue else: img_name = target_name # 查找是否多语言文件 continue_flag, target_name = getLanguageresFlag(img_name, languageres_dict, argv_lang) if continue_flag: continue else: img_name = target_name # 产生图像格式 type_format = getImageType(img_name, argv_type) type_flag = 0 type_img_name = os.path.splitext(img_name.replace("\\", "/"))[0] type_img_ext = os.path.splitext(img_name.replace("\\", "/"))[1] if type_img_ext.lower() != ".png": # 音效文件特殊处理 if img_name.find("res\\audio\\") >= 0: if img_name.find("\\" + argv_type.lower() + "\\") <= 0: continue else: img_name = img_name.replace("\\" + argv_type.lower() + "\\", "\\") type_img_name = img_name.replace("\\", "/") if img_name.find(".plist") > 0: type_flag = 1 else: type_flag = 0 else: if argv_type.lower() == "ios": type_img_name = type_img_name + ".plist" type_flag = 1 elif argv_type.lower() == "android": if type_format == "none": type_img_name = img_name.replace("\\", "/") type_flag = 0 else: type_img_name = type_img_name + ".plist" type_flag = 1 elif argv_type.lower() == "wp8": if type_format == "none": type_img_name = img_name.replace("\\", "/") type_flag = 0 else: type_img_name = type_img_name + ".plist" type_flag = 1 else: type_img_name = img_name.replace("\\", "/") if ( img_name.find("\\ui\\") >= 0 or img_name.find("\\audio\\") >= 0 or img_name.find("\\json\\") >= 0 or img_name.find("\\skilleffect\\") >= 0 ): if argv_type.lower() in ["ios", "android", "wp8"]: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(img_name)[0].replace("\\", "#"), type_img_name, type_flag, type_format, ) else: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(img_name)[0].replace("\\", "#"), type_img_name, type_flag, type_format, ) else: if argv_type.lower() in ["ios", "android", "wp8"]: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(os.path.basename(img_name))[0], type_img_name, type_flag, type_format, ) else: row_texts = row_texts + '\t["%s"]={"%s",%d,"%s"},\n' % ( os.path.splitext(os.path.basename(img_name))[0], type_img_name, type_flag, type_format, ) client_output_dict = {} client_output_dict["$RESPATH$"] = row_texts gen_file(client_template, client_output, client_output_dict, False) print "plist ok! start convert!" # 处理文件 if argv_type == "win32": safeRmTree("..\\..\\client\\res") import time time.sleep(2) while os.path.exists("..\\..\\client\\res"): pass shutil.copytree("res", "..\\..\\client\\res", False, ignoreFile) if os.path.exists("..\\..\\client\\res\\audio"): shutil.rmtree("..\\..\\client\\res\\audio", True) os.makedirs("..\\..\\client\\res\\audio") # win32音效特殊处理 for file_name in os.listdir("res\\audio\\win32\\"): sub_path = os.path.join("res\\audio\\win32\\", file_name) if os.path.isdir(sub_path): continue else: safeCopy(sub_path, "..\\..\\client\\res\\audio") # 公共资源改名覆盖 for publicres_key in publicres_dict.iterkeys(): print "win32 copy %s to %s" % ( "..\\..\\client\\" + publicres_key + "_" + argv_platform + ".png", "..\\..\\client\\" + publicres_key + ".png", ) shutil.copy( "..\\..\\client\\" + publicres_key + "_" + argv_platform + ".png", "..\\..\\client\\" + publicres_key + ".png", ) # 多语言资源改名覆盖 if argv_lang != "gbk" and argv_lang != "multi": for languageres_key in languageres_dict.iterkeys(): print "win32 copy %s to %s" % ( "..\\..\\client\\" + languageres_key + "_" + argv_lang + ".png", "..\\..\\client\\" + languageres_key + ".png", ) shutil.copy( "..\\..\\client\\" + languageres_key + "_" + argv_lang + ".png", "..\\..\\client\\" + languageres_key + ".png", ) return # 处理配置的plist safeRmTree("temp\\") convert_flag = False for row_key, row_value in plist_dict.iteritems(): # 处理图片 convert_flag = False for j in xrange(0, len(row_value)): # 拆分目录 img_flag = row_value[j][0] img_name = row_value[j][1] img_format = row_value[j][2] img_path = os.path.dirname(img_name) + "\\" if img_flag == 4: img_path = "" img_flag = getImageFlag(img_name) copy_flag = 1 if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_CSB: copy_flag = 0 if row_key.lower() == "none": if ( img_name.find("\\ui\\") >= 0 or img_name.find("\\audio\\") >= 0 or img_name.find("\\json\\") >= 0 or img_name.find("\\skilleffect\\") >= 0 ): pass else: img_path = "" if not os.path.exists("temp\\" + img_path): os.makedirs("temp\\" + img_path) # 查找是否多平台文件 continue_flag, target_name = getPublicresFlag(img_name, publicres_dict, argv_platform) if continue_flag: continue else: img_publicres_name = target_name # 查找是否多语言文件 continue_flag, target_name = getLanguageresFlag(img_name, languageres_dict, argv_lang) if continue_flag: continue else: img_publicres_name = target_name if not os.path.exists(img_name): print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: safeCopy(img_name, "temp\\" + img_path + os.path.basename(img_publicres_name)) if img_name.replace("\\", "/") in diff_list: convert_flag = True if row_key.lower() == "none": if (diff_flag and convert_flag) or not diff_flag: cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s" % ( "..\\..\\outputClient\\" + argv_type + "\\" + os.path.splitext(img_publicres_name)[0], getFormatFlag(argv_type, img_format), copy_flag, img_path, ) os.system(cmd_text) safeRmTree("temp\\") convert_flag = False else: safeRmTree("temp\\") convert_flag = False if row_key.lower() != "none": if (diff_flag and convert_flag) or not diff_flag: cmd_text = "res\\xcopy.bat %s temp %s 1 %d" % ( "..\\..\\outputClient\\" + argv_type + "\\" + row_key, getFormatFlag(argv_type, img_format), copy_flag, ) os.system(cmd_text) # 如果目标图没有生成,那么抛异常 if ( (not os.path.exists("..\\..\\outputClient\\" + argv_type + "\\" + row_key + ".png")) and (not os.path.exists("..\\..\\outputClient\\" + argv_type + "\\" + row_key + ".pvr.ccz")) and (not os.path.exists("..\\..\\outputClient\\" + argv_type + "\\" + row_key + ".dds")) ): raise safeRmTree("temp\\") else: safeRmTree("temp\\") # 遍历处理其他文件 for row_key, row_value in path_dict.iteritems(): # 处理图片 for j in xrange(0, len(row_value)): # 拆分目录 img_path = row_key img_name = row_value[j] img_format = "none" img_path = os.path.dirname(img_name) + "\\" if ( img_name.find(".png") >= 0 or img_name.find(".mp3") >= 0 or img_name.find(".caf") >= 0 or img_name.find(".m4a") >= 0 or img_name.find(".ExportJson") >= 0 or img_name.find(".json") >= 0 or img_name.find(".tmx") >= 0 or img_name.find(".plist") >= 0 or img_name.find(".ogg") >= 0 ): pass else: continue img_flag = getImageFlag(img_name) copy_flag = 1 if img_flag == IMAGE_FLAG_JSON or img_flag == IMAGE_FLAG_MAP or img_flag == IMAGE_FLAG_CSB: copy_flag = 0 # 查找是否已经被plist,win32不做plist continue_flag = getPlistedFlag(img_name, plist_dict, argv_type) if continue_flag: continue # 查找是否有同名plist if img_flag == IMAGE_FLAG_NORMAL: found_flag = getPlistExistedFlag(img_name, path_dict, row_key) if found_flag: # 复制过去 safeCopy(img_name, "..\\..\\outputClient\\" + argv_type + "\\" + img_path) img_plist = os.path.splitext(img_name)[0] + ".plist" safeCopy(img_plist, "..\\..\\outputClient\\" + argv_type + "\\" + img_path) continue # 查找是否多平台文件 continue_flag, target_name = getPublicresFlag(img_name, publicres_dict, argv_platform) if continue_flag: continue else: img_publicres_name = target_name # 查找是否多语言文件 continue_flag, target_name = getLanguageresFlag(img_name, languageres_dict, argv_lang) if continue_flag: continue else: img_publicres_name = target_name convert_flag = False if img_name.replace("\\", "/") in diff_list: convert_flag = True if (diff_flag and convert_flag) or not diff_flag: pass else: continue # 产生图像格式 img_format = getImageType(img_name, argv_type) img_ext = os.path.splitext(img_name.replace("\\", "/"))[1] if img_ext.lower() != ".png": if img_flag == IMAGE_FLAG_NORMAL: # 音效文件特殊处理 if img_path.find("res\\audio\\") >= 0: if img_path.find("\\" + argv_type.lower() + "\\") <= 0: continue else: img_path = img_path.replace("\\" + argv_type.lower() + "\\", "\\") safeCopy(img_name, "..\\..\\outputClient\\" + argv_type + "\\" + img_path) elif img_flag == IMAGE_FLAG_MAP: if img_name.find(".tmx") >= 0 or img_name.find(".json") >= 0: with open(img_name, "r") as fr: content = fr.read() content = content.replace(".png", ".pvr.ccz") safeWrite( "..\\..\\outputClient\\" + argv_type + "\\" + img_path + os.path.basename(img_name), content ) else: safeCopy(img_name, "..\\..\\outputClient\\" + argv_type + "\\" + img_path) elif img_flag == IMAGE_FLAG_JSON: safeCopy(img_name, "..\\..\\outputClient\\" + argv_type + "\\" + img_path) print "copy " + img_name else: if ( img_name.find("\\ui\\") >= 0 or img_name.find("\\audio\\") >= 0 or img_name.find("\\json\\") >= 0 or img_name.find("\\skilleffect\\") >= 0 ): pass else: img_path = "" if not os.path.exists(img_name): print img_name, "not exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else: safeCopy(img_name, "temp\\" + img_path + os.path.basename(img_publicres_name)) cmd_text = "res\\xcopy.bat %s temp %s 0 %d %s" % ( "..\\..\\outputClient\\" + argv_type + "\\" + os.path.splitext(img_publicres_name)[0], getFormatFlag(argv_type, img_format), copy_flag, img_path, ) os.system(cmd_text) safeRmTree("temp\\")
def skilldetaildb(): excel_file = 'skilldb.xls' client_template = 'skilldetaildb.lua' client_output = 'skilldetaildb.lua' client_configs1 = { '1':{ 'data_type':['int','str','str','str','int','str', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'float', 'unicode',"str"], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s","%(s3)s",%(s4)d,"%(s5)s",%(s6)d, %(s7)d, %(s8)d, %(s9)d, %(s10)d, %(s11)d, %(s12)d, %(s13).2f,{%(s15)s}}', 'placeholder':'$SKILLDETAIL1$' } } client_configs2 = { '2':{ 'data_type':['int','str','str','str', 'int', 'int','int','int','float','float', 'int', 'float', 'int', 'int', 'unicode','str', 'int', 'int', 'int'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s","%(s3)s", %(s4)d, %(s5)d,%(s6)d,%(s7)d,%(s8).2f,%(s9).2f,%(s10)d,%(s11).2f, %(s12)d, %(s13)d ,"%(s15)s", %(s16)d, %(s17)d, %(s18)d}', 'placeholder':'$SKILLDETAIL2$' } } client_configs3 = { '3':{ 'data_type':['int','str','str','str','str', 'int', 'int', 'int', 'float', 'int'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s",{%(s3)s},"%(s4)s",%(s5)d, %(s6)d,%(s7)d, %(s8).2f,%(s9)d}', 'placeholder':'$SKILLDETAIL3$' } } client_configs4 = { '4':{ 'data_type':['int','int', 'unicode', 'str', 'str'], 'data_template':'[%(s0)d]={%(s1)d, "%(s2)s", "%(s3)s"}', 'placeholder':'$SKILLDETAIL4$' } } client_configs5 = { '5':{ 'data_type':['int','str','str','str','str','int', 'int', 'int','int','int','int','int','float','str', 'str'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s","%(s3)s","%(s4)s",%(s5)d, %(s6)d,%(s7)d,%(s8)d,%(s9)d,%(s10)d,%(s11)d,%(s12).2f,{%(s13)s},"%(s14)s"}', 'placeholder':'$SKILLDETAIL5$' } } client_configs6 = { '6':{ 'data_type':['int','str','str','int', 'int', 'float', 'str'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s",%(s3)d,%(s4)d, %(s5).2f,"%(s6)s"}', 'placeholder':'$SKILLDETAIL6$' } } client_configs7 = { '7':{ 'data_type':['int','int','int','int', 'unicode'], 'data_template':'[%(s0)d]={%(s1)d,%(s2)d, %(s3)d}', 'placeholder':'$SKILLDETAIL7$' } } client_configs8 = { '8':{ 'data_type':['int','str','str','str', 'str', 'str', 'int', 'int', 'int', 'int', 'int', 'int', 'float', 'int'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s","%(s3)s", "%(s4)s",{%(s5)s}, %(s6)d, %(s7)d, %(s8)d, %(s9)d, %(s10)d, %(s11)d, %(s12).2f, %(s13)d}', 'placeholder':'$SKILLDETAIL8$' } } client_configs9 = { '9':{ 'data_type':['int', 'str', 'str', 'str', 'int', 'int', 'int', 'int', 'float', 'unicode','str'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s","%(s3)s", %(s4)d, %(s5)d, %(s6)d, %(s7)d, %(s8).2f,{%(s9)s}}', 'placeholder':'$SKILLDETAIL9$' } } client_configs10 = { '10':{ 'data_type':['int','str','str','str', 'int', 'int', 'int', 'int', 'float', 'str', 'unicode','int','int','int'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s","%(s3)s",%(s4)d, %(s5)d, %(s6)d, %(s7)d, %(s8).2f, {%(s9)s},"%(s10)s",%(s11)d,%(s12)d,%(s13)d}', 'placeholder':'$SKILLDETAIL10$' } } client_configs11 = { '11':{ 'data_type':['int','str','str','str', 'str', 'str', 'int', 'int', 'int', 'int', 'float'], 'data_template':'[%(s0)d]={"%(s1)s","%(s2)s","%(s3)s","%(s4)s", {%(s5)s}, %(s6)d, %(s7)d, %(s8)d, %(s9)d ,%(s10).2f}', 'placeholder':'$SKILLDETAIL11$' } } client_configs12 = { '12':{ 'data_type':['int','int','int','float', 'int', 'int', 'float', 'int', 'int', 'str','str','str','str'], 'data_template':'[%(s0)d]={%(s1)d, %(s2)d, %(s3).2f, %(s4)d, %(s5)d, %(s6).1f, %(s7)d, %(s8)d, {%(s9)s},"%(s10)s","%(s11)s",{%(s12)s}}', 'placeholder':'$SKILLDETAIL11$' } } client_output_dict = {} client_output_dict['$SKILLDETAIL1$'] = converter_3(excel_file, client_configs1) client_output_dict['$SKILLDETAIL2$'] = converter_3(excel_file, client_configs2) client_output_dict['$SKILLDETAIL3$'] = converter_3(excel_file, client_configs3) client_output_dict['$SKILLDETAIL4$'] = converter_3(excel_file, client_configs4) client_output_dict['$SKILLDETAIL5$'] = converter_3(excel_file, client_configs5) client_output_dict['$SKILLDETAIL6$'] = converter_3(excel_file, client_configs6) client_output_dict['$SKILLDETAIL7$'] = converter_3(excel_file, client_configs7) client_output_dict['$SKILLDETAIL8$'] = converter_3(excel_file, client_configs8) client_output_dict['$SKILLDETAIL9$'] = converter_3(excel_file, client_configs9) client_output_dict['$SKILLDETAIL10$'] = converter_3(excel_file, client_configs10) client_output_dict['$SKILLDETAIL11$'] = converter_3(excel_file, client_configs11) client_output_dict['$SKILLDETAIL12$'] = converter_3(excel_file, client_configs12) gen_file(client_template, client_output, client_output_dict)