-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,63 @@ | ||
import zipfile | ||
import sys | ||
import json | ||
import argparse | ||
import os | ||
|
||
def build_pack(type='normal'): | ||
def main(): | ||
parser = argparse.ArgumentParser(description="Automatically build resourcepacks") | ||
parser.add_argument('type', default='normal',help="Build type. This should be 'all', 'normal' or 'compat'.", choices=['all', 'normal', 'compat']) | ||
parser.add_argument('-n', '--without-figure', action='store_true', help="Do not add figures when building resource packs. If build type is 'all', this argument will be ignored.") | ||
args = vars(parser.parse_args()) | ||
if args['type'] == 'all': | ||
build_all() | ||
else: | ||
build(args) | ||
print("Build succeeded!") | ||
|
||
def build(args): | ||
with open("assets/minecraft/lang/zh_meme.json", 'r', encoding='utf8') as f: | ||
lang_data = json.load(f) | ||
if type == 'normal': | ||
# Normal build | ||
zipped_pack = zipfile.ZipFile("mcwzh-meme.zip", 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=5) | ||
zipped_pack.writestr("assets/minecraft/lang/zh_meme.json", json.dumps(lang_data, indent=4, ensure_ascii=True)) | ||
zipped_pack.write("pack.mcmeta") | ||
zipped_pack.write("assets/minecraft/models/item/totem_of_undying.json") | ||
zipped_pack.write("assets/minecraft/models/item/dianliang.json") | ||
zipped_pack.write("assets/minecraft/models/item/lxazl5770.json") | ||
zipped_pack.write("assets/minecraft/models/item/lake.json") | ||
zipped_pack.write("assets/minecraft/models/item/mysticnebula70.json") | ||
zipped_pack.write("assets/minecraft/textures/entity/lxazl5770.png") | ||
zipped_pack.write("assets/minecraft/textures/entity/dianliang.png") | ||
zipped_pack.write("assets/minecraft/textures/entity/lakejason.png") | ||
zipped_pack.write("assets/minecraft/textures/entity/mysticnebula70.png") | ||
elif type == 'compat': | ||
# Compatible build | ||
zipped_pack = zipfile.ZipFile("mcwzh-meme_compatible.zip", 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=5) | ||
zipped_pack.writestr("assets/minecraft/lang/zh_cn.json", json.dumps(lang_data, indent=4, ensure_ascii=True)) | ||
pack_name = get_packname(args) | ||
# all builds have these files | ||
pack = zipfile.ZipFile(pack_name, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=5) | ||
pack.write("pack.png") | ||
pack.write("LICENSE") | ||
# build with figures | ||
if not args['without_figure']: | ||
for file in os.listdir("assets/minecraft/models/item"): | ||
pack.write("assets/minecraft/models/item/" + file) | ||
for file in os.listdir("assets/minecraft/textures/entity"): | ||
pack.write("assets/minecraft/textures/entity/" + file) | ||
if args['type'] == 'normal': | ||
# normal build | ||
pack.writestr("assets/minecraft/lang/zh_meme.json", json.dumps(lang_data, indent=4, ensure_ascii=True)) | ||
pack.write("pack.mcmeta") | ||
elif args['type'] == 'compat': | ||
# compatible build | ||
pack.writestr("assets/minecraft/lang/zh_cn.json", json.dumps(lang_data, indent=4, ensure_ascii=True)) | ||
# Processing mcmeta | ||
with open("pack.mcmeta", 'r', encoding='utf8') as meta: | ||
metadata = json.load(meta) | ||
del metadata['language'] | ||
zipped_pack.writestr("pack.mcmeta", json.dumps(metadata, indent=4, ensure_ascii=False)) | ||
zipped_pack.write("assets/minecraft/models/item/totem_of_undying.json") | ||
zipped_pack.write("assets/minecraft/models/item/dianliang.json") | ||
zipped_pack.write("assets/minecraft/models/item/lxazl5770.json") | ||
zipped_pack.write("assets/minecraft/models/item/lake.json") | ||
zipped_pack.write("assets/minecraft/models/item/mysticnebula70.json") | ||
zipped_pack.write("assets/minecraft/textures/entity/lxazl5770.png") | ||
zipped_pack.write("assets/minecraft/textures/entity/dianliang.png") | ||
zipped_pack.write("assets/minecraft/textures/entity/lakejason.png") | ||
zipped_pack.write("assets/minecraft/textures/entity/mysticnebula70.png") | ||
elif type == 'no_figure': | ||
# Normal build, without figure | ||
zipped_pack = zipfile.ZipFile("mcwzh-meme_no_figure.zip", 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=5) | ||
zipped_pack.writestr("assets/minecraft/lang/zh_meme.json", json.dumps(lang_data, indent=4, ensure_ascii=True)) | ||
zipped_pack.write("pack.mcmeta") | ||
elif type == 'compat_no_figure': | ||
# Compatible build, without figure | ||
zipped_pack = zipfile.ZipFile("mcwzh-meme_compatible_no_figure.zip", 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=5) | ||
zipped_pack.writestr("assets/minecraft/lang/zh_cn.json", json.dumps(lang_data, indent=4, ensure_ascii=True)) | ||
# Processing mcmeta | ||
with open("pack.mcmeta", 'r', encoding='utf8') as meta: | ||
metadata = json.load(meta) | ||
del metadata['language'] | ||
zipped_pack.writestr("pack.mcmeta", json.dumps(metadata, indent=4, ensure_ascii=False)) | ||
zipped_pack.write("LICENSE") | ||
zipped_pack.write("pack.png") | ||
zipped_pack.close() | ||
pack.writestr("pack.mcmeta", json.dumps(metadata, indent=4, ensure_ascii=False)) | ||
pack.close() | ||
|
||
def build_all(): | ||
build({'type': 'normal', 'without_figure': False}) | ||
build({'type': 'normal', 'without_figure': True}) | ||
build({'type': 'compat', 'without_figure': False}) | ||
build({'type': 'compat', 'without_figure': True}) | ||
|
||
def get_packname(args): | ||
base_name = "mcwzh-meme" | ||
if args['type'] == 'normal': | ||
if args['without_figure']: | ||
base_name = base_name + "_nofigure" | ||
elif args['type'] == 'compat': | ||
base_name = base_name + "_compatible" | ||
if args['without_figure']: | ||
base_name = base_name + "_nofigure" | ||
return base_name + ".zip" | ||
|
||
if len(sys.argv) > 1: | ||
if sys.argv[1] == "compat": | ||
build_pack("compat") | ||
build_pack("compat_no_figure") | ||
elif sys.argv[1] == "all": | ||
build_pack() | ||
build_pack("compat") | ||
build_pack("no_figure") | ||
build_pack("compat_no_figure") | ||
elif sys.argv[1] == "normal": | ||
build_pack() | ||
build_pack("no_figure") | ||
else: | ||
print("Needs 1 argument") | ||
exit(code=-1) | ||
print("Build succeeded!") | ||
exit(code=0) | ||
if __name__ == '__main__': | ||
main() |