less copy protection, more size visualization
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

102 wiersze
4.2 KiB

  1. import sys
  2. import re
  3. import json
  4. import glob
  5. import os
  6. import subprocess
  7. import pathlib
  8. # an affront to god
  9. def combine(base_path, highlight_path, vivid_path, output_path):
  10. base = open(base_path, "r", encoding="utf-8").read()
  11. highlight = open(highlight_path, "r", encoding="utf-8").read()
  12. vivid = open(vivid_path, "r", encoding="utf-8").read()
  13. base_data = re.search("<g.*", base, flags=re.DOTALL)[0][:-7]
  14. highlight_data = re.search("<g.*", highlight, flags=re.DOTALL)[0][:-7]
  15. vivid_data = vivid.replace("</metadata>", "</metadata>" + base_data + "\n" + highlight_data)
  16. with open(output_path, "w", encoding="utf-8") as f:
  17. f.write(vivid_data)
  18. subprocess.run([INKSCAPE, "--without-gui", "--export-plain-svg=" + output_path.resolve().__str__(), "--export-area-drawing", output_path], shell=False)
  19. configdir = pathlib.Path(__file__).parent
  20. configpath = configdir.joinpath("config.json")
  21. config = json.load(open(configpath, encoding="utf-8"))
  22. workdir = pathlib.Path(config["work-directory"])
  23. sourcedir = workdir.joinpath(sys.argv[1])
  24. macrodir = pathlib.Path(config["macrovision-directory"])
  25. print(sourcedir, macrodir)
  26. side_strings = []
  27. POTRACE = config["potrace"]
  28. INKSCAPE = config["inkscape"]
  29. output = {}
  30. with open(sourcedir.joinpath("data.json"), "r", encoding="utf-8") as file:
  31. all_data = json.load(file)
  32. group_name = all_data["name"]
  33. category = all_data["kind"]
  34. outputdir = macrodir.joinpath("media").joinpath(category).joinpath(group_name)
  35. os.makedirs(outputdir, exist_ok=True)
  36. base_lut = configdir.joinpath("luts").joinpath("base-lut.png").__str__()
  37. highlight_lut = configdir.joinpath("luts").joinpath("highlight-lut.png").__str__()
  38. vivid_lut = configdir.joinpath("luts").joinpath("vivid-lut.png").__str__()
  39. for data in all_data["forms"]:
  40. name = data["name"]
  41. for view in data["views"]:
  42. view_name = view["name"]
  43. input = sourcedir.joinpath(name + "-" + view_name + ".png")
  44. result = outputdir.joinpath(name + "-" + view_name + ".svg")
  45. print(result)
  46. if os.path.exists(result) and os.path.getmtime(input) < os.path.getmtime(result):
  47. print("Skipping ", input)
  48. continue
  49. input_base = sourcedir.joinpath(name + "-" + view_name + "-base.bmp")
  50. input_highlight = sourcedir.joinpath(name + "-" + view_name + "-highlight.bmp")
  51. input_vivid = sourcedir.joinpath(name + "-" + view_name + "-vivid.bmp")
  52. subprocess.run(["magick", "convert", input, base_lut, "-channel", "RGB", "-clut", "-background", "#FFFFFF", "-flatten", input_base], shell=False)
  53. subprocess.run(["magick", "convert", input, highlight_lut, "-channel", "RGB", "-clut", "-background", "#FFFFFF", "-flatten", input_highlight], shell=False)
  54. subprocess.run(["magick", "convert", input, vivid_lut, "-channel", "RGB", "-clut", "-background", "#FFFFFF", "-flatten", input_vivid], shell=False)
  55. output_base = sourcedir.joinpath(name + "-" + view_name + "-base.svg")
  56. output_highlight = sourcedir.joinpath(name + "-" + view_name + "-highlight.svg")
  57. output_vivid = sourcedir.joinpath(name + "-" + view_name + "-vivid.svg")
  58. subprocess.run([POTRACE, input_base, "-b", "svg", "-o", output_base], shell=False)
  59. subprocess.run([POTRACE, input_highlight, "-b", "svg", "-C", "#1a1a1a", "-o", output_highlight], shell=False)
  60. subprocess.run([POTRACE, input_vivid, "-b", "svg", "-C", "#333333", "-o", output_vivid], shell=False)
  61. combine(output_base, output_highlight, output_vivid, result)
  62. # os.unlink(input_base)
  63. # os.unlink(input_highlight)
  64. # now we add the data
  65. file_path = macrodir.joinpath("presets").joinpath(category + ".js")
  66. with open(file_path, "r", encoding="utf-8") as file:
  67. lines = file.readlines()
  68. found = False
  69. with open(file_path, "w", encoding="utf-8") as file:
  70. for line in lines:
  71. if f"/* ***{group_name}*** */" in line:
  72. found = True
  73. file.write(f" /* ***{group_name}*** */ results.push(makeModel({json.dumps(all_data)}));\n")
  74. elif "/* ***INSERT HERE*** */" in line and not found:
  75. file.write(f" /* ***{group_name}*** */ results.push(makeModel({json.dumps(all_data)}));\n")
  76. file.write(line)
  77. else:
  78. file.write(line)