publish.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/python
  2. #
  3. # This program assembles the distribution file Gameduino.zip
  4. # from the source .ino files, and the asset files in
  5. # converted-assets.
  6. #
  7. inventory = {
  8. '1.Basics' : "sprites256 palettes rotate collision scroll",
  9. '2.Audio' : "toccata player sample instruments2",
  10. '3.Advanced' : "interrupt splitscreen jkcollision bitmap wireframe snow assets",
  11. '4.Demo' : "ball chessboard dna spectrum cp437",
  12. '5.Games' : "asteroids frogger chopper",
  13. '6.Tools' : "selftest screenshot memloader joytest",
  14. }
  15. import zipfile
  16. def clean(src):
  17. vis = 1
  18. dst = []
  19. for l in src:
  20. assert not chr(9) in l, "Tab found in source"
  21. if "//'" in l:
  22. l = l[:l.index("//'")]
  23. if vis and not "JCB" in l:
  24. dst.append(l.rstrip() + "\n")
  25. else:
  26. if "JCB{" in l:
  27. vis = 0
  28. if "}JCB" in l:
  29. vis = 1
  30. return "".join(dst)
  31. z = zipfile.ZipFile("Gameduino.zip", "w", zipfile.ZIP_DEFLATED)
  32. for f in "GD.cpp GD.h".split():
  33. z.write(f, "Gameduino/%s" % f)
  34. legit = []
  35. testset = open("testset", "w")
  36. for d,projs in inventory.items():
  37. dir = "Gameduino" + "/" + d
  38. for p in projs.split():
  39. pd = dir + "/" + p
  40. z.writestr("%s/%s.ino" % (pd, p), clean(open("%s.ino" % p)))
  41. for l in open("%s.ino" % p):
  42. if '#include "' in l:
  43. hdr = l[10:l.rindex('"')]
  44. z.write("converted-assets/%s" % hdr, "%s/%s" % (pd, hdr))
  45. legit.append("converted-assets/%s" % hdr)
  46. testset.write(p + " ")
  47. legit.append(p + ".ino")
  48. testset.close()
  49. z.close()
  50. # print ["./mkino %s" % s for s in " ".join(inventory.values()).split()]
  51. print " ".join(legit)