This repository has been archived by the owner on Jun 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
84 lines (67 loc) · 2.5 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
Place this script in the root of KSAM assets and then run it to build.
Usage: python3 build.py [dest location]
"""
import sys
import os
import shutil
import json
import util.mtxtool as mtx
import configparser as cp
config = cp.ConfigParser()
def main(dest):
# Load config
config.read("build.ini")
pngfiles = config["Textures"]["files"].split(" ")
cwd = os.getcwd()
# Create folders for the entire APK structure
print(" → Creating folders for build...")
permmode = 0o755
os.mkdir("build", mode=permmode)
os.mkdir("build/assets", mode=permmode)
os.mkdir("build/assets/about", mode=permmode)
os.mkdir("build/assets/effects", mode=permmode)
os.mkdir("build/assets/fonts", mode=permmode)
os.mkdir("build/assets/gfx", mode=permmode)
os.mkdir("build/assets/hud", mode=permmode)
os.mkdir("build/assets/levels", mode=permmode)
os.mkdir("build/assets/menu", mode=permmode)
os.mkdir("build/assets/meshes", mode=permmode)
os.mkdir("build/assets/music", mode=permmode)
os.mkdir("build/assets/obstacles", mode=permmode)
os.mkdir("build/assets/rooms", mode=permmode)
os.mkdir("build/assets/segments", mode=permmode)
os.mkdir("build/assets/shaders", mode=permmode)
os.mkdir("build/assets/snd", mode=permmode)
# Generate baked images
if (config["Textures"].getboolean("enable")):
# TODO: This needs to be redone!
print(" → Generating textures and images...")
for i in pngfiles:
filein = "textures/" + i + ".png"
fileout = "build/assets/" + i + ".png.mtx.mp3"
print(" → Baking", filein, "to", fileout, "...")
mtx.bakeMtxFromPng(filein, fileout)
# Install packages
packages = config["General"]["packages"].split(" ")
print(" → Installing", len(packages), "package(s)...")
for p in packages:
f = open(p + "/package.json", "r")
package_info = json.load(f)
f.close();
print(" → Installing package", package_info["packageName"], "version", package_info["packageVersion"], "...")
shutil.copytree(cwd + "/" + p + "/assets", cwd + "/build/assets", dirs_exist_ok = True)
# Overlay the files of the APK
print(" → Copying new files to APK...")
shutil.copytree(cwd + "/build/assets", dest + "/assets", dirs_exist_ok = True)
# Cleanup
if (not config["General"].getboolean("keepAssets")):
print(" → Removing temporary build tree...")
shutil.rmtree(cwd + "/build")
print(" → Build completed successfully!")
return 0
if (__name__ == "__main__"):
if (len(sys.argv) >= 2):
sys.exit(main(sys.argv[1]))
else:
print("Usage: python3 ./build.py (location to apk root)")