diff options
| author | Indrajith K L | 2025-11-03 17:48:56 +0530 |
|---|---|---|
| committer | Indrajith K L | 2025-11-03 17:48:56 +0530 |
| commit | 737214b71be8fe5fdf51155ad50bb064b3156bd3 (patch) | |
| tree | 21a2713d03830b21ee2b3ffd919708b054728e40 /embed_font.py | |
| parent | 3afcbd32001fc2ab2dcee1553268dbb39dabf070 (diff) | |
| download | reilua-enhanced-737214b71be8fe5fdf51155ad50bb064b3156bd3.tar.gz reilua-enhanced-737214b71be8fe5fdf51155ad50bb064b3156bd3.tar.bz2 reilua-enhanced-737214b71be8fe5fdf51155ad50bb064b3156bd3.zip | |
Add embedded assets, splash screens, and asset loading support
Features added:
- Embedded main.lua and Lua files support (EMBED_MAIN option)
- Embedded assets support (EMBED_ASSETS option)
- Splash screens with dual logo display (always embedded)
- Asset loading progress tracking API (BeginAssetLoading, UpdateAssetLoading, EndAssetLoading)
- Custom font embedding for splash/loading screens
- --log flag for Windows console control
- --no-logo flag to skip splash screens in development
- Python scripts for embedding (embed_lua.py, embed_assets.py, embed_logo.py, embed_font.py)
- Documentation (EMBEDDING.md, ASSET_LOADING.md, SPLASH_SCREENS.md)
This allows building single-executable releases with all Lua code and assets embedded.
Diffstat (limited to 'embed_font.py')
| -rw-r--r-- | embed_font.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/embed_font.py b/embed_font.py new file mode 100644 index 0000000..8144718 --- /dev/null +++ b/embed_font.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +""" +Embed font file into C header. +Usage: python embed_font.py <output.h> <font.ttf> +""" + +import sys +import os + +def embed_file(file_path, var_name): + """Convert a file to a C byte array""" + with open(file_path, 'rb') as f: + data = f.read() + + output = f"/* {os.path.basename(file_path)} */\n" + output += f"static const unsigned char {var_name}[] = {{\n" + + # Write bytes in rows of 16 + for i in range(0, len(data), 16): + chunk = data[i:i+16] + hex_values = ', '.join(f'0x{b:02x}' for b in chunk) + output += f" {hex_values},\n" + + output += "};\n" + output += f"static const unsigned int {var_name}_size = {len(data)};\n\n" + + return output + +def main(): + if len(sys.argv) != 3: + print("Usage: python embed_font.py <output.h> <font.ttf>") + sys.exit(1) + + output_file = sys.argv[1] + font_file = sys.argv[2] + + # Check if file exists + if not os.path.exists(font_file): + print(f"Error: {font_file} not found!") + sys.exit(1) + + # Generate header content + header_content = "/* Auto-generated embedded font file */\n" + header_content += "#pragma once\n\n" + + # Embed font file + header_content += embed_file(font_file, "embedded_font_data") + + # Write to output file + with open(output_file, 'w') as f: + f.write(header_content) + + print(f"Generated {output_file}") + print(f" - Embedded {font_file} ({os.path.getsize(font_file)} bytes)") + +if __name__ == "__main__": + main() |
