Organize resources into folders, update packer accordingly
This commit is contained in:
parent
9a9f74cb52
commit
bd62eb8ed7
11 changed files with 48 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
||||||
import os
|
import os, shutil
|
||||||
|
|
||||||
RES_DIR = "../res/"
|
RES_DIR = "../res/"
|
||||||
PACKED_DIR = "../include/packed/"
|
PACKED_DIR = "../include/packed/"
|
||||||
|
@ -7,32 +7,43 @@ resources = os.fsencode(RES_DIR)
|
||||||
os.makedirs(PACKED_DIR, exist_ok=True)
|
os.makedirs(PACKED_DIR, exist_ok=True)
|
||||||
packed_dir = os.fsencode(PACKED_DIR)
|
packed_dir = os.fsencode(PACKED_DIR)
|
||||||
|
|
||||||
for file in os.listdir(packed_dir):
|
for filename in os.listdir(packed_dir):
|
||||||
if os.path.splitext(file)[1] == b".hpp":
|
file_path = os.path.join(packed_dir, filename)
|
||||||
os.unlink(os.path.join(packed_dir, file))
|
if os.path.isfile(file_path) or os.path.islink(file_path):
|
||||||
|
os.unlink(file_path)
|
||||||
|
elif os.path.isdir(file_path):
|
||||||
|
shutil.rmtree(file_path)
|
||||||
|
|
||||||
for resource in os.listdir(resources):
|
for folder in os.listdir(resources):
|
||||||
res = ""
|
folder_path = os.path.join(resources, folder)
|
||||||
|
if os.path.isfile(folder_path):
|
||||||
|
continue
|
||||||
|
packed_path = os.path.join(packed_dir, folder)
|
||||||
|
os.makedirs(packed_path, exist_ok=True)
|
||||||
|
for resource in os.listdir(folder_path):
|
||||||
|
resource_path = os.path.join(folder_path, resource)
|
||||||
|
|
||||||
splitext = os.path.splitext(resource)
|
res = ""
|
||||||
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()}[] = {'{'}"
|
splitext = os.path.splitext(resource)
|
||||||
file = open(os.path.join(resources, resource), "rb") # read binary
|
name = splitext[0].decode()
|
||||||
bytes_processed = 0
|
ext = splitext[1].decode()
|
||||||
for byte in file.read():
|
|
||||||
if bytes_processed % 16 == 0:
|
if ext == ".png":
|
||||||
encoded += "\n\t"
|
name += "_texture"
|
||||||
encoded += f"0x{byte.to_bytes(1, byteorder='little').hex()}, "
|
elif ext == ".wav":
|
||||||
bytes_processed += 1
|
name += "_audio"
|
||||||
encoded = encoded[:-2] + "\n};"
|
name += "_data"
|
||||||
res += encoded + "\n"
|
|
||||||
with open(os.path.join(PACKED_DIR, f"{name}.hpp"), "w") as f:
|
encoded = f"const unsigned char {name.upper()}[] = {'{'}"
|
||||||
f.write(res)
|
file = open(resource_path, "rb") # read binary
|
||||||
|
bytes_processed = 0
|
||||||
|
for byte in file.read():
|
||||||
|
if bytes_processed % 16 == 0:
|
||||||
|
encoded += "\n\t"
|
||||||
|
encoded += f"0x{byte.to_bytes(1, byteorder='little').hex()}, "
|
||||||
|
bytes_processed += 1
|
||||||
|
encoded = encoded[:-2] + "\n};"
|
||||||
|
res += encoded + "\n"
|
||||||
|
with open(os.path.join(packed_path.decode(), f"{name}.hpp"), "w") as f:
|
||||||
|
f.write(res)
|
Before ![]() (image error) Size: 3.5 KiB After ![]() (image error) Size: 3.5 KiB ![]() ![]() |
Before ![]() (image error) Size: 8.8 KiB After ![]() (image error) Size: 8.8 KiB ![]() ![]() |
Before ![]() (image error) Size: 308 B After ![]() (image error) Size: 308 B ![]() ![]() |
19
src/Main.cpp
19
src/Main.cpp
|
@ -28,15 +28,16 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
#include <packed/background_texture_data.hpp>
|
#include <packed/audio/game_over_audio_data.hpp>
|
||||||
#include <packed/blocks_texture_data.hpp>
|
#include <packed/audio/level_up_audio_data.hpp>
|
||||||
#include <packed/game_over_audio_data.hpp>
|
#include <packed/audio/new_highscore_audio_data.hpp>
|
||||||
#include <packed/level_up_audio_data.hpp>
|
#include <packed/audio/rotate_audio_data.hpp>
|
||||||
#include <packed/new_highscore_audio_data.hpp>
|
#include <packed/audio/row_clear_audio_data.hpp>
|
||||||
#include <packed/numerals_texture_data.hpp>
|
#include <packed/audio/snap_audio_data.hpp>
|
||||||
#include <packed/rotate_audio_data.hpp>
|
|
||||||
#include <packed/row_clear_audio_data.hpp>
|
#include <packed/textures/background_texture_data.hpp>
|
||||||
#include <packed/snap_audio_data.hpp>
|
#include <packed/textures/blocks_texture_data.hpp>
|
||||||
|
#include <packed/textures/numerals_texture_data.hpp>
|
||||||
|
|
||||||
#define TILE_SIZE 20
|
#define TILE_SIZE 20
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue