build.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import os
  2. import shutil
  3. import zipfile
  4. shutil.rmtree("data", True)
  5. shutil.copytree("original", "data")
  6. os.system("..\\..\\tools\\oxyresbuild.py -x system\\res.xml --src_data data --dest_data data\\system --nopng")
  7. shutil.rmtree("data/system/anims/")
  8. def recursive_zip(zipf, directory, folder = ""):
  9. for item in os.listdir(directory):
  10. if os.path.isfile(os.path.join(directory, item)):
  11. zipf.write(os.path.join(directory, item), folder + os.sep + item)
  12. elif os.path.isdir(os.path.join(directory, item)):
  13. recursive_zip(zipf, os.path.join(directory, item), folder + os.sep + item)
  14. import cStringIO
  15. data = cStringIO.StringIO()
  16. with zipfile.ZipFile(data, "w", zipfile.ZIP_DEFLATED) as zp:
  17. recursive_zip(zp, "data")
  18. fmtH = """
  19. #pragma once
  20. #ifndef %(MODULE)s_DATA
  21. #define %(MODULE)s_DATA
  22. extern unsigned int %(module)s_size;
  23. extern const unsigned char %(module)s_data[];
  24. #endif
  25. """
  26. fmtCPP = """
  27. #include "%(HEADER)s"
  28. unsigned int %(module)s_size = %(SIZE)d;
  29. const unsigned char %(module)s_data[] = {%(DATA)s};
  30. """
  31. def gen(module, data):
  32. st = ",".join("0x{:02x}".format(ord(c)) for c in data)
  33. MODULE = module.upper()
  34. SIZE = len(data)
  35. DATA = st
  36. args = {"MODULE":MODULE, "SIZE":SIZE, "DATA":DATA, "module":module, "HEADER":module + "_data.h"}
  37. return (fmtH % args, fmtCPP % args, )
  38. rs = gen("system", data.getvalue())
  39. with open("../../oxygine/src/core/system_data.h", "w") as fh:
  40. fh.write(rs[0])
  41. with open("../../oxygine/src/core/system_data.cpp", "w") as fh:
  42. fh.write(rs[1])
  43. with open("system.zip", "wb") as zp:
  44. zp.write(data.getvalue())