2016. 4. 8. 10:27

PNG 파일을 ATF 로 일괄 변환시키는 스트립트(Ver. 1.0.0)

Adobe Air 로 게임을 만들면 이미지 리소스를 png 파일을 써도 되지만 메모리의 사용량이나 처리속도면에서 ATF 파일로 변환해서 쓰는게 훨씬 이득이다. 다만 ATF 파일로 변환하면 전용뷰어 외에는 확인이 안되서 디버깅시는 PNG 파일을 릴리즈시에는 플랫폼별(PC/ANDROID/IOS)들로 각각의 파일들을 만들어서 처리되게 한다.


## atf 관련 실행파일 및 뷰어는 AIR SDK 에 atftool 디렉토리에 존재함.



import os import hashlib import subprocess CONST_WIN = 0 CONST_IOS = 1 CONST_AND = 2 png2atf = "D:\\SDK\\AIR_SDK\\AIRSDK_21\\atftools\\png2atf.exe" assetDir = "D:\\work\\workspace_flex\\holdem\\assets_d\\mobile_ko\\assets" hashFile = assetDir + "\\.AssetsHash" def md5(fname): hash_md5 = hashlib.md5() with open(fname, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): hash_md5.update(chunk) return hash_md5.hexdigest() def conver_asset(create, gtype, fname): xname = assetDir + "\\" + fname + ".xml" sname = assetDir + "\\" + fname + ".png" if gtype == CONST_IOS: name_xml = fname + "_ios.xml" name_xml_full = assetDir + "\\" + name_xml name_atf = fname + "_ios.atf" name_atf_full = assetDir + '\\' + name_atf elif gtype == CONST_AND: name_xml = fname + "_and.xml" name_xml_full = assetDir + "\\" + name_xml name_atf = fname + "_and.atf" name_atf_full = assetDir + '\\' + name_atf else: name_xml = fname + "_win.xml" name_xml_full = assetDir + "\\" + name_xml name_atf = fname + "_win.atf" name_atf_full = assetDir + '\\' + name_atf if not create and os.path.exists(name_xml_full) and os.path.exists(name_atf_full): return if os.path.exists(name_xml_full): os.remove(name_xml_full) with open(xname, "r") as fp: xml = fp.read(os.path.getsize(xname)) xml = xml.replace(fname + ".png", name_atf, 1) with open(name_xml_full, "w") as fp: fp.write(xml) if os.path.exists(name_atf_full): os.remove(name_atf_full) if gtype == CONST_IOS: print fname + " >> " + name_atf subprocess.call(png2atf + " -c p -q -n 0,0 -i " + sname + " -o " + name_atf_full) elif gtype == CONST_AND: print fname + " >> " + name_atf subprocess.call(png2atf + " -c e -q -n 0,0 -i " + sname + " -o " + name_atf_full) else: print fname + " >> " + name_atf subprocess.call(png2atf + " -c d -q -n 0,0 -i " + sname + " -o " + name_atf_full) def main(): hash_pool = {} hash_pool_save = {} if os.path.exists(hashFile): with open(hashFile, 'r') as fp: while True: line = fp.readline() if not line: break key, value = line.rstrip('\n').split('|') hash_pool[key] = value for root, dirs, files in os.walk(assetDir): for f in files: filename, ext = os.path.splitext(f) if ext == '.png': md5hash = md5(assetDir + '\\' + f) create = False if (f in hash_pool) == False or hash_pool[f] != md5hash: create = True conver_asset(create, CONST_IOS, filename) conver_asset(create, CONST_AND, filename) conver_asset(create, CONST_WIN, filename) hash_pool_save[f] = md5hash with open(hashFile, 'w') as fp: for key in hash_pool_save: line = key + "|" + hash_pool_save[key] fp.write(line + '\n') if __name__ == "__main__": main()