mirror of
https://github.com/TeamMidnightDust/RoundTreesPack.git
synced 2025-12-15 09:45:09 +01:00
Add option to minify json files
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/src/__pycache__
|
||||||
|
Round-Trees-*.zip
|
||||||
Binary file not shown.
13
gen_pack.py
13
gen_pack.py
@@ -11,6 +11,9 @@ import shutil
|
|||||||
import time
|
import time
|
||||||
from distutils.dir_util import copy_tree
|
from distutils.dir_util import copy_tree
|
||||||
|
|
||||||
|
import src.json_utils
|
||||||
|
from src.json_utils import dumpJson, minifyJsonFiles, minify
|
||||||
|
|
||||||
# Utility functions
|
# Utility functions
|
||||||
def printGreen(out): print("\033[92m{}\033[00m".format(out))
|
def printGreen(out): print("\033[92m{}\033[00m".format(out))
|
||||||
def printCyan(out): print("\033[96m{}\033[00m" .format(out))
|
def printCyan(out): print("\033[96m{}\033[00m" .format(out))
|
||||||
@@ -20,6 +23,8 @@ def autoGen(jsonData, args):
|
|||||||
print("Generating assets...")
|
print("Generating assets...")
|
||||||
if (os.path.exists("./assets")): shutil.rmtree("./assets")
|
if (os.path.exists("./assets")): shutil.rmtree("./assets")
|
||||||
copy_tree("./base/assets/", "./assets/")
|
copy_tree("./base/assets/", "./assets/")
|
||||||
|
if minify: minifyJsonFiles()
|
||||||
|
|
||||||
filecount = 0
|
filecount = 0
|
||||||
unpackMods()
|
unpackMods()
|
||||||
scanModsForLogs()
|
scanModsForLogs()
|
||||||
@@ -103,7 +108,7 @@ def generateBlockstateAndModel(mod_namespace, block_name, texture_end, texture_s
|
|||||||
|
|
||||||
# Write blockstate file
|
# Write blockstate file
|
||||||
with open(block_state_file, "w") as f:
|
with open(block_state_file, "w") as f:
|
||||||
json.dump(block_state_data, f, indent=4)
|
dumpJson(block_state_data, f)
|
||||||
|
|
||||||
|
|
||||||
# Create models folder if it doesn't exist already
|
# Create models folder if it doesn't exist already
|
||||||
@@ -131,7 +136,7 @@ def generateBlockstateAndModel(mod_namespace, block_name, texture_end, texture_s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
with open(block_model_file, "w") as f:
|
with open(block_model_file, "w") as f:
|
||||||
json.dump(block_model_data, f, indent=4)
|
dumpJson(block_model_data, f)
|
||||||
|
|
||||||
def generateItemModel(mod_namespace, block_name):
|
def generateItemModel(mod_namespace, block_name):
|
||||||
# Create models folder if it doesn't exist already
|
# Create models folder if it doesn't exist already
|
||||||
@@ -143,7 +148,7 @@ def generateItemModel(mod_namespace, block_name):
|
|||||||
"parent": f"{mod_namespace}:block/{block_name}1"
|
"parent": f"{mod_namespace}:block/{block_name}1"
|
||||||
}
|
}
|
||||||
with open(item_model_file, "w") as f:
|
with open(item_model_file, "w") as f:
|
||||||
json.dump(item_model_data, f, indent=4)
|
dumpJson(item_model_data, f)
|
||||||
|
|
||||||
def writeMetadata(args):
|
def writeMetadata(args):
|
||||||
edition = args.edition
|
edition = args.edition
|
||||||
@@ -181,10 +186,12 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
parser.add_argument('version', type=str)
|
parser.add_argument('version', type=str)
|
||||||
parser.add_argument('edition', nargs="*", type=str, default="§cCustom Edition", help="Define your edition name")
|
parser.add_argument('edition', nargs="*", type=str, default="§cCustom Edition", help="Define your edition name")
|
||||||
|
parser.add_argument('--minify', '-m', action='store_true', help="Minify all JSON output files")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print(args)
|
print(args)
|
||||||
print()
|
print()
|
||||||
|
if args.minify: src.json_utils.minify = True
|
||||||
|
|
||||||
# Loads overrides from the json file
|
# Loads overrides from the json file
|
||||||
f = open('./input/overrides.json')
|
f = open('./input/overrides.json')
|
||||||
|
|||||||
18
src/json_utils.py
Normal file
18
src/json_utils.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
minify = False
|
||||||
|
|
||||||
|
def minifyJsonFiles(rootDir="./assets"):
|
||||||
|
for root, dirs, files in os.walk(rootDir):
|
||||||
|
for infile in files:
|
||||||
|
if infile.endswith(".json"):
|
||||||
|
minifyExistingJson(root, infile)
|
||||||
|
def minifyExistingJson(root, infile):
|
||||||
|
with open(os.path.join(root, infile), "r") as rf:
|
||||||
|
data = json.load(rf)
|
||||||
|
with open(os.path.join(root, infile), "w") as wf:
|
||||||
|
json.dump(data, wf, separators=(',', ':'))
|
||||||
|
|
||||||
|
def dumpJson(data, f):
|
||||||
|
json.dump(data, f, separators=(',', ':')) if minify else json.dump(data, f, indent=4)
|
||||||
Reference in New Issue
Block a user