diff --git a/build/packer.py b/build/packer.py index 729b29e..4f413ef 100644 --- a/build/packer.py +++ b/build/packer.py @@ -1,4 +1,4 @@ -import os +import os, shutil RES_DIR = "../res/" PACKED_DIR = "../include/packed/" @@ -7,32 +7,43 @@ resources = os.fsencode(RES_DIR) 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 filename in os.listdir(packed_dir): + file_path = os.path.join(packed_dir, filename) + 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): - res = "" +for folder in os.listdir(resources): + 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) - name = splitext[0].decode() - ext = splitext[1].decode() - - if ext == ".png": - name += "_texture" - elif ext == ".wav": - name += "_audio" - name += "_data" + res = "" - 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: - 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_DIR, f"{name}.hpp"), "w") as f: - f.write(res) \ No newline at end of file + 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(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) \ No newline at end of file diff --git a/res/game_over.wav b/res/audio/game_over.wav similarity index 100% rename from res/game_over.wav rename to res/audio/game_over.wav diff --git a/res/level_up.wav b/res/audio/level_up.wav similarity index 100% rename from res/level_up.wav rename to res/audio/level_up.wav diff --git a/res/new_highscore.wav b/res/audio/new_highscore.wav similarity index 100% rename from res/new_highscore.wav rename to res/audio/new_highscore.wav diff --git a/res/rotate.wav b/res/audio/rotate.wav similarity index 100% rename from res/rotate.wav rename to res/audio/rotate.wav diff --git a/res/row_clear.wav b/res/audio/row_clear.wav similarity index 100% rename from res/row_clear.wav rename to res/audio/row_clear.wav diff --git a/res/snap.wav b/res/audio/snap.wav similarity index 100% rename from res/snap.wav rename to res/audio/snap.wav diff --git a/res/background.png b/res/textures/background.png similarity index 100% rename from res/background.png rename to res/textures/background.png diff --git a/res/blocks.png b/res/textures/blocks.png similarity index 100% rename from res/blocks.png rename to res/textures/blocks.png diff --git a/res/numerals.png b/res/textures/numerals.png similarity index 100% rename from res/numerals.png rename to res/textures/numerals.png diff --git a/src/Main.cpp b/src/Main.cpp index a753d63..5c16c31 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -28,15 +28,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include #define TILE_SIZE 20