Improve packing
This commit is contained in:
parent
874d9b3819
commit
9a9f74cb52
4 changed files with 45 additions and 21 deletions
|
@ -1,14 +1,31 @@
|
|||
import os
|
||||
|
||||
RES_DIR = "../res/"
|
||||
RES_FILE = "../include/res.hpp"
|
||||
PACKED_DIR = "../include/packed/"
|
||||
|
||||
resources = os.fsencode(RES_DIR)
|
||||
res = ""
|
||||
os.makedirs(PACKED_DIR, exist_ok=True)
|
||||
packed_dir = os.fsencode(PACKED_DIR)
|
||||
|
||||
for file in os.listdir(packed_dir):
|
||||
if os.path.splitext(file)[1] == b".hpp":
|
||||
os.unlink(os.path.join(packed_dir, file))
|
||||
|
||||
for resource in os.listdir(resources):
|
||||
encoded = f"const unsigned char {os.path.splitext(resource)[0].decode().upper()}[] = {'{'}"
|
||||
file = open(RES_DIR + resource.decode(), "rb") # read binary
|
||||
res = ""
|
||||
|
||||
splitext = os.path.splitext(resource)
|
||||
name = splitext[0].decode()
|
||||
ext = splitext[1].decode()
|
||||
|
||||
if ext == ".png":
|
||||
name += "_texture"
|
||||
elif ext == ".wav":
|
||||
name += "_audio"
|
||||
name += "_data"
|
||||
|
||||
encoded = f"const unsigned char {name.upper()}[] = {'{'}"
|
||||
file = open(os.path.join(resources, resource), "rb") # read binary
|
||||
bytes_processed = 0
|
||||
for byte in file.read():
|
||||
if bytes_processed % 16 == 0:
|
||||
|
@ -17,7 +34,5 @@ for resource in os.listdir(resources):
|
|||
bytes_processed += 1
|
||||
encoded = encoded[:-2] + "\n};"
|
||||
res += encoded + "\n"
|
||||
|
||||
res_file = open(RES_FILE, "w")
|
||||
res_file.write(res)
|
||||
res_file.close()
|
||||
with open(os.path.join(PACKED_DIR, f"{name}.hpp"), "w") as f:
|
||||
f.write(res)
|
Loading…
Add table
Add a link
Reference in a new issue