jsonmaker.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import os
  2. import shutil
  3. currdir = os.getcwd()
  4. prefixlist = ["inhand-left-","inhand-right-","equipped-INNERCLOTHING-","equipped-FEET-","equipped-BACKPACK-","equipped-BELT-","equipped-EYES-","equipped-HAND-","equipped-HELMET-","equipped-MASK-","equipped-NECK-","equipped-OUTERCLOTHING-"]
  5. if (__name__ == "__main__"):
  6. print("Checking JSON...")
  7. for root, dirs, files in os.walk(currdir+"\\exported"): # checks all files and folders in the base folder
  8. for file in files:
  9. filesp = file.replace("\n","") # removes the paragraph at the end of the string
  10. if(file.endswith(".png")):
  11. if not os.path.isfile(root+"\\meta.json"):
  12. print(" Not found at {}, creating!".format(root))
  13. with open(root+"\\meta.json", "w") as newmeta:
  14. newmeta.write('''{\"version\": 1,\"copyright\": \"Taken from civ13 at commit https://github.com/Civ13/Civ13/commit/c07b37fbca55b690d80cc2ec0c2c61839cbecf5c\",\"size\": {\"x\": 32,\"y\": 32},
  15. \"states\": [''')
  16. newmeta.close()
  17. dirs = ''
  18. for prefix in prefixlist:
  19. if file.find(prefix):
  20. dirs = ',\"directions\": 4'
  21. jsonstr = '{"name": "'+file.replace(".png","")+'"'+dirs+'},'
  22. print(" Adding".format(jsonstr))
  23. with open(root+"\\meta.json", "a") as text_file:
  24. text_file.write(jsonstr)
  25. text_file.close()
  26. for root, dirs, files in os.walk(currdir+"\\exported"): # checks all files and folders in the base folder
  27. for file in files:
  28. filesp = file.replace("\n","") # removes the paragraph at the end of the string
  29. if(file.endswith(".json")):
  30. print("finalising " + root + "/"+file)
  31. with open(root+"\\meta.json", "a") as final_file:
  32. final_file.write("]}")