Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
AlPha5130 committed Feb 18, 2020
1 parent a37991c commit 0bf195b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/automatic_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ jobs:
files: |
mcwzh-meme.zip
mcwzh-meme_compatible.zip
mcwzh-meme_no_figure.zip
mcwzh-meme_compatible_no_figure.zip
mcwzh-meme_nofigure.zip
mcwzh-meme_compatible_nofigure.zip
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cd mcwzh-meme-resourcepack
``` bash
python build.py all
```
在文件夹中会出现`mcwzh-meme.zip``mcwzh-meme_compatible.zip``mcwzh-meme_no_figure.zip``mcwzh-meme_compatible_no_figure.zip`四个资源包,名称和作用如上所述。
在文件夹中会出现`mcwzh-meme.zip``mcwzh-meme_compatible.zip``mcwzh-meme_nofigure.zip``mcwzh-meme_compatible_nofigure.zip`四个资源包,名称和作用如上所述。

如果只需要常规的资源包,运行:
``` bash
Expand All @@ -44,6 +44,12 @@ python build.py normal
``` bash
python build.py compat
```
如果不需要自定义模型,添加`-n`选项。

更详细的用法请运行以下命令来获取:
``` bash
python build.py -h
```
### 自助跟进游戏版本
此资源包的语言文件顺序与原版的英文顺序并不一致(本资源包是将key按照字母顺序排序)。如果原版的英文译名跟进了,请先将解包的英文语言文件按照前文所述排序,可以参考[这个网站](https://tool.funsmall.cn/jsonsort/)。推荐使用[Visual Studio Code](https://github.com/microsoft/vscode)的比较功能。
## 贡献
Expand Down
117 changes: 53 additions & 64 deletions build.py
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()

0 comments on commit 0bf195b

Please sign in to comment.