cleaned up root folder, organized files into docs/scripts/tools dirs
This commit is contained in:
100
scripts/build_dev.bat
Normal file
100
scripts/build_dev.bat
Normal file
@@ -0,0 +1,100 @@
|
||||
@echo off
|
||||
REM ReiLua Development Build Script
|
||||
REM Run this from w64devkit shell or CMD with MinGW in PATH
|
||||
|
||||
echo ================================
|
||||
echo ReiLua - Development Build
|
||||
echo ================================
|
||||
echo.
|
||||
|
||||
REM Navigate to build directory
|
||||
cd build
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Cannot access build directory
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Clean old embedded files (important for dev builds!)
|
||||
echo Cleaning old embedded files...
|
||||
del /Q embedded_main.h embedded_assets.h 2>nul
|
||||
|
||||
REM Warn about Lua files in build directory
|
||||
dir /b *.lua >nul 2>&1
|
||||
if not errorlevel 1 (
|
||||
echo.
|
||||
echo WARNING: Found Lua files in build directory!
|
||||
echo Development builds should load from file system, not embed.
|
||||
echo.
|
||||
dir /b *.lua
|
||||
echo.
|
||||
set /p REMOVE="Remove these files from build directory? (Y/n): "
|
||||
if /i not "%REMOVE%"=="n" (
|
||||
del /Q *.lua
|
||||
echo Lua files removed.
|
||||
)
|
||||
echo.
|
||||
)
|
||||
|
||||
REM Warn about assets folder in build directory
|
||||
if exist "assets" (
|
||||
echo.
|
||||
echo WARNING: Found assets folder in build directory!
|
||||
echo Development builds should load from file system, not embed.
|
||||
echo.
|
||||
set /p REMOVE="Remove assets folder from build directory? (Y/n): "
|
||||
if /i not "%REMOVE%"=="n" (
|
||||
rmdir /S /Q assets
|
||||
echo Assets folder removed.
|
||||
)
|
||||
echo.
|
||||
)
|
||||
|
||||
REM Clean old configuration if requested
|
||||
if "%1"=="clean" (
|
||||
echo Cleaning build directory...
|
||||
del /Q CMakeCache.txt *.o *.a 2>nul
|
||||
rmdir /S /Q CMakeFiles 2>nul
|
||||
echo Clean complete!
|
||||
echo.
|
||||
)
|
||||
|
||||
REM Configure with MinGW
|
||||
echo Configuring CMake for development...
|
||||
cmake -G "MinGW Makefiles" ..
|
||||
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: CMake configuration failed!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Building ReiLua...
|
||||
mingw32-make
|
||||
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: Build failed!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ================================
|
||||
echo Build Complete!
|
||||
echo ================================
|
||||
echo.
|
||||
echo Development build created successfully!
|
||||
echo.
|
||||
echo To run your game:
|
||||
echo cd \path\to\your\game
|
||||
echo \path\to\ReiLua\build\ReiLua.exe
|
||||
echo.
|
||||
echo To run with console logging:
|
||||
echo \path\to\ReiLua\build\ReiLua.exe --log
|
||||
echo.
|
||||
echo Features:
|
||||
echo - Lua files load from file system
|
||||
echo - Assets load from file system
|
||||
echo - Fast iteration - edit and reload
|
||||
echo.
|
||||
pause
|
||||
96
scripts/build_dev.sh
Normal file
96
scripts/build_dev.sh
Normal file
@@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
# ReiLua Development Build Script
|
||||
# Run this from w64devkit shell
|
||||
|
||||
echo "================================"
|
||||
echo "ReiLua - Development Build"
|
||||
echo "================================"
|
||||
echo ""
|
||||
|
||||
# Navigate to build directory
|
||||
cd build || exit 1
|
||||
|
||||
# Clean old embedded files (important for dev builds!)
|
||||
echo "Cleaning old embedded files..."
|
||||
rm -f embedded_main.h embedded_assets.h
|
||||
|
||||
# Warn about Lua files in build directory
|
||||
LUA_COUNT=$(ls *.lua 2>/dev/null | wc -l)
|
||||
if [ "$LUA_COUNT" -gt 0 ]; then
|
||||
echo ""
|
||||
echo "WARNING: Found Lua files in build directory!"
|
||||
echo "Development builds should load from file system, not embed."
|
||||
echo ""
|
||||
ls -1 *.lua
|
||||
echo ""
|
||||
read -p "Remove these files from build directory? (Y/n): " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
|
||||
rm -f *.lua
|
||||
echo "Lua files removed."
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Warn about assets folder in build directory
|
||||
if [ -d "assets" ]; then
|
||||
echo ""
|
||||
echo "WARNING: Found assets folder in build directory!"
|
||||
echo "Development builds should load from file system, not embed."
|
||||
echo ""
|
||||
read -p "Remove assets folder from build directory? (Y/n): " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
|
||||
rm -rf assets
|
||||
echo "Assets folder removed."
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Clean old configuration if requested
|
||||
if [ "$1" == "clean" ]; then
|
||||
echo "Cleaning build directory..."
|
||||
rm -rf CMakeCache.txt CMakeFiles/ *.o *.a
|
||||
echo "Clean complete!"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Configure with MinGW
|
||||
echo "Configuring CMake for development..."
|
||||
cmake -G "MinGW Makefiles" ..
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ""
|
||||
echo "ERROR: CMake configuration failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Building ReiLua..."
|
||||
make
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ""
|
||||
echo "ERROR: Build failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================"
|
||||
echo "Build Complete!"
|
||||
echo "================================"
|
||||
echo ""
|
||||
echo "Development build created successfully!"
|
||||
echo ""
|
||||
echo "To run your game:"
|
||||
echo " cd /path/to/your/game"
|
||||
echo " /path/to/ReiLua/build/ReiLua.exe"
|
||||
echo ""
|
||||
echo "To run with console logging:"
|
||||
echo " /path/to/ReiLua/build/ReiLua.exe --log"
|
||||
echo ""
|
||||
echo "Features:"
|
||||
echo " - Lua files load from file system"
|
||||
echo " - Assets load from file system"
|
||||
echo " - Fast iteration - edit and reload"
|
||||
echo ""
|
||||
144
scripts/build_release.bat
Normal file
144
scripts/build_release.bat
Normal file
@@ -0,0 +1,144 @@
|
||||
@echo off
|
||||
REM ReiLua Release Build Script
|
||||
REM Run this from w64devkit shell or CMD with MinGW in PATH
|
||||
|
||||
echo ================================
|
||||
echo ReiLua - Release Build
|
||||
echo ================================
|
||||
echo.
|
||||
|
||||
REM Check if we're in the right directory
|
||||
if not exist "CMakeLists.txt" (
|
||||
echo ERROR: Please run this script from the ReiLua root directory
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Navigate to build directory
|
||||
cd build
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Cannot access build directory
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Clean old embedded files
|
||||
echo Cleaning old embedded files...
|
||||
del /Q embedded_main.h embedded_assets.h 2>nul
|
||||
|
||||
REM Check for Lua files
|
||||
echo.
|
||||
echo Checking for Lua files...
|
||||
dir /b *.lua >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo WARNING: No Lua files found in build directory!
|
||||
echo.
|
||||
echo Please copy your Lua files:
|
||||
echo cd build
|
||||
echo copy ..\your_game\*.lua .
|
||||
echo.
|
||||
set /p CONTINUE="Do you want to continue anyway? (y/N): "
|
||||
if /i not "%CONTINUE%"=="y" exit /b 1
|
||||
) else (
|
||||
echo Found Lua files:
|
||||
dir /b *.lua
|
||||
)
|
||||
|
||||
REM Check for assets folder
|
||||
echo.
|
||||
echo Checking for assets...
|
||||
if not exist "assets" (
|
||||
echo.
|
||||
echo WARNING: No assets folder found!
|
||||
echo.
|
||||
echo To embed assets, create the folder and copy files:
|
||||
echo cd build
|
||||
echo mkdir assets
|
||||
echo copy ..\your_game\assets\* assets\
|
||||
echo.
|
||||
set /p CONTINUE="Do you want to continue without assets? (y/N): "
|
||||
if /i not "%CONTINUE%"=="y" exit /b 1
|
||||
set EMBED_ASSETS=OFF
|
||||
) else (
|
||||
echo Found assets folder
|
||||
set EMBED_ASSETS=ON
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ================================
|
||||
echo Build Configuration
|
||||
echo ================================
|
||||
echo Lua Embedding: ON
|
||||
echo Asset Embedding: %EMBED_ASSETS%
|
||||
echo Build Type: Release
|
||||
echo ================================
|
||||
echo.
|
||||
pause
|
||||
|
||||
REM Clean CMake cache
|
||||
echo.
|
||||
echo Cleaning CMake cache...
|
||||
del /Q CMakeCache.txt 2>nul
|
||||
rmdir /S /Q CMakeFiles 2>nul
|
||||
|
||||
REM Configure with embedding enabled
|
||||
echo.
|
||||
echo Configuring CMake for release...
|
||||
cmake -G "MinGW Makefiles" .. -DEMBED_MAIN=ON -DEMBED_ASSETS=%EMBED_ASSETS% -DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: CMake configuration failed!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Build
|
||||
echo.
|
||||
echo Building ReiLua Release...
|
||||
mingw32-make
|
||||
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: Build failed!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Show summary
|
||||
echo.
|
||||
echo ================================
|
||||
echo Embedded Files Summary
|
||||
echo ================================
|
||||
|
||||
if exist "embedded_main.h" (
|
||||
echo.
|
||||
echo Embedded Lua files:
|
||||
findstr /C:"Embedded file:" embedded_main.h
|
||||
)
|
||||
|
||||
if exist "embedded_assets.h" (
|
||||
echo.
|
||||
echo Embedded assets:
|
||||
findstr /C:"Embedded asset:" embedded_assets.h
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ================================
|
||||
echo Build Complete!
|
||||
echo ================================
|
||||
echo.
|
||||
echo Executable: ReiLua.exe
|
||||
echo Location: %CD%\ReiLua.exe
|
||||
echo.
|
||||
echo Your game is ready for distribution!
|
||||
echo.
|
||||
echo To test the release build:
|
||||
echo ReiLua.exe --log (with console)
|
||||
echo ReiLua.exe (production mode)
|
||||
echo.
|
||||
echo To distribute:
|
||||
echo - Copy ReiLua.exe to your distribution folder
|
||||
echo - Rename it to your game name (optional)
|
||||
echo - That's it! Single file distribution!
|
||||
echo.
|
||||
pause
|
||||
150
scripts/build_release.sh
Normal file
150
scripts/build_release.sh
Normal file
@@ -0,0 +1,150 @@
|
||||
#!/bin/bash
|
||||
# ReiLua Release Build Script
|
||||
# Run this from w64devkit shell
|
||||
|
||||
echo "================================"
|
||||
echo "ReiLua - Release Build"
|
||||
echo "================================"
|
||||
echo ""
|
||||
|
||||
# Check if we're in the right directory
|
||||
if [ ! -f "CMakeLists.txt" ]; then
|
||||
echo "ERROR: Please run this script from the ReiLua root directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Navigate to build directory
|
||||
cd build || exit 1
|
||||
|
||||
# Clean old embedded files
|
||||
echo "Cleaning old embedded files..."
|
||||
rm -f embedded_main.h embedded_assets.h
|
||||
|
||||
# Check for Lua files
|
||||
echo ""
|
||||
echo "Checking for Lua files..."
|
||||
LUA_FILES=$(ls *.lua 2>/dev/null | wc -l)
|
||||
|
||||
if [ "$LUA_FILES" -eq 0 ]; then
|
||||
echo ""
|
||||
echo "WARNING: No Lua files found in build directory!"
|
||||
echo ""
|
||||
echo "Please copy your Lua files:"
|
||||
echo " cd build"
|
||||
echo " cp ../your_game/*.lua ."
|
||||
echo ""
|
||||
read -p "Do you want to continue anyway? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Found $LUA_FILES Lua file(s):"
|
||||
ls -1 *.lua
|
||||
fi
|
||||
|
||||
# Check for assets folder
|
||||
echo ""
|
||||
echo "Checking for assets..."
|
||||
if [ ! -d "assets" ]; then
|
||||
echo ""
|
||||
echo "WARNING: No assets folder found!"
|
||||
echo ""
|
||||
echo "To embed assets, create the folder and copy files:"
|
||||
echo " cd build"
|
||||
echo " mkdir assets"
|
||||
echo " cp ../your_game/assets/* assets/"
|
||||
echo ""
|
||||
read -p "Do you want to continue without assets? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
EMBED_ASSETS="OFF"
|
||||
else
|
||||
ASSET_FILES=$(find assets -type f 2>/dev/null | wc -l)
|
||||
echo "Found $ASSET_FILES asset file(s) in assets folder"
|
||||
EMBED_ASSETS="ON"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================"
|
||||
echo "Build Configuration"
|
||||
echo "================================"
|
||||
echo "Lua Embedding: ON"
|
||||
echo "Asset Embedding: $EMBED_ASSETS"
|
||||
echo "Build Type: Release"
|
||||
echo "================================"
|
||||
echo ""
|
||||
read -p "Press Enter to continue or Ctrl+C to cancel..."
|
||||
|
||||
# Clean CMake cache to ensure fresh configuration
|
||||
echo ""
|
||||
echo "Cleaning CMake cache..."
|
||||
rm -rf CMakeCache.txt CMakeFiles/
|
||||
|
||||
# Configure with embedding enabled
|
||||
echo ""
|
||||
echo "Configuring CMake for release..."
|
||||
cmake -G "MinGW Makefiles" .. -DEMBED_MAIN=ON -DEMBED_ASSETS=$EMBED_ASSETS -DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ""
|
||||
echo "ERROR: CMake configuration failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build
|
||||
echo ""
|
||||
echo "Building ReiLua Release..."
|
||||
make
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ""
|
||||
echo "ERROR: Build failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Show embedded file info
|
||||
echo ""
|
||||
echo "================================"
|
||||
echo "Embedded Files Summary"
|
||||
echo "================================"
|
||||
|
||||
if [ -f "embedded_main.h" ]; then
|
||||
echo ""
|
||||
echo "Embedded Lua files:"
|
||||
grep 'Embedded file:' embedded_main.h | sed 's/.*Embedded file: / - /'
|
||||
else
|
||||
echo "No Lua files embedded"
|
||||
fi
|
||||
|
||||
if [ -f "embedded_assets.h" ]; then
|
||||
echo ""
|
||||
echo "Embedded assets:"
|
||||
grep 'Embedded asset:' embedded_assets.h | sed 's/.*Embedded asset: / - /' | sed 's/ (.*//'
|
||||
else
|
||||
echo "No assets embedded"
|
||||
fi
|
||||
|
||||
# Get executable size
|
||||
echo ""
|
||||
echo "================================"
|
||||
echo "Build Complete!"
|
||||
echo "================================"
|
||||
EXESIZE=$(du -h ReiLua.exe | cut -f1)
|
||||
echo ""
|
||||
echo "Executable: ReiLua.exe ($EXESIZE)"
|
||||
echo "Location: $(pwd)/ReiLua.exe"
|
||||
echo ""
|
||||
echo "Your game is ready for distribution!"
|
||||
echo ""
|
||||
echo "To test the release build:"
|
||||
echo " ./ReiLua.exe --log (with console)"
|
||||
echo " ./ReiLua.exe (production mode)"
|
||||
echo ""
|
||||
echo "To distribute:"
|
||||
echo " - Copy ReiLua.exe to your distribution folder"
|
||||
echo " - Rename it to your game name (optional)"
|
||||
echo " - That's it! Single file distribution!"
|
||||
echo ""
|
||||
116
scripts/embed_assets.py
Normal file
116
scripts/embed_assets.py
Normal file
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Embed asset files (images, sounds, fonts, etc.) into a C header file.
|
||||
Usage: python embed_assets.py <output.h> <file1.png> [file2.wav] [file3.ttf] ...
|
||||
|
||||
Embeds all specified asset files into a C header for inclusion in the executable.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def sanitize_name(filename):
|
||||
"""Convert filename to valid C identifier"""
|
||||
name = os.path.basename(filename)
|
||||
# Remove or replace all non-alphanumeric characters (except underscore)
|
||||
valid_chars = []
|
||||
for char in name:
|
||||
if char.isalnum() or char == '_':
|
||||
valid_chars.append(char)
|
||||
else:
|
||||
valid_chars.append('_')
|
||||
name = ''.join(valid_chars)
|
||||
# Ensure it doesn't start with a digit
|
||||
if name and name[0].isdigit():
|
||||
name = '_' + name
|
||||
return name
|
||||
|
||||
def get_file_extension(filename):
|
||||
"""Get the file extension"""
|
||||
return os.path.splitext(filename)[1].lower()
|
||||
|
||||
def embed_files(output_file, input_files):
|
||||
with open(output_file, 'w') as f:
|
||||
f.write('#ifndef EMBEDDED_ASSETS_H\n')
|
||||
f.write('#define EMBEDDED_ASSETS_H\n\n')
|
||||
f.write('/* Auto-generated file - do not edit manually */\n\n')
|
||||
|
||||
# Embed each file as a separate array
|
||||
for idx, input_file in enumerate(input_files):
|
||||
with open(input_file, 'rb') as inf:
|
||||
data = inf.read()
|
||||
|
||||
var_name = sanitize_name(input_file)
|
||||
# Extract relative path from 'assets/' onwards if present
|
||||
if 'assets' in input_file.replace('\\', '/'):
|
||||
parts = input_file.replace('\\', '/').split('assets/')
|
||||
if len(parts) > 1:
|
||||
relative_name = 'assets/' + parts[-1]
|
||||
else:
|
||||
relative_name = os.path.basename(input_file)
|
||||
else:
|
||||
relative_name = os.path.basename(input_file)
|
||||
|
||||
f.write(f'/* Embedded asset: {input_file} ({len(data)} bytes) */\n')
|
||||
f.write(f'static const unsigned char embedded_asset_{idx}_{var_name}[] = {{\n')
|
||||
|
||||
for i, byte in enumerate(data):
|
||||
if i % 12 == 0:
|
||||
f.write(' ')
|
||||
f.write(f'0x{byte:02x}')
|
||||
if i < len(data) - 1:
|
||||
f.write(',')
|
||||
if (i + 1) % 12 == 0:
|
||||
f.write('\n')
|
||||
else:
|
||||
f.write(' ')
|
||||
|
||||
f.write('\n};\n')
|
||||
f.write(f'static const unsigned int embedded_asset_{idx}_{var_name}_len = {len(data)};\n\n')
|
||||
|
||||
# Create the asset table
|
||||
f.write('/* Asset table for virtual filesystem */\n')
|
||||
f.write('typedef struct {\n')
|
||||
f.write(' const char* name;\n')
|
||||
f.write(' const unsigned char* data;\n')
|
||||
f.write(' unsigned int size;\n')
|
||||
f.write('} EmbeddedAsset;\n\n')
|
||||
|
||||
f.write('static const EmbeddedAsset embedded_assets[] = {\n')
|
||||
for idx, input_file in enumerate(input_files):
|
||||
var_name = sanitize_name(input_file)
|
||||
# Extract relative path from 'assets/' onwards if present
|
||||
if 'assets' in input_file.replace('\\', '/'):
|
||||
parts = input_file.replace('\\', '/').split('assets/')
|
||||
if len(parts) > 1:
|
||||
relative_name = 'assets/' + parts[-1]
|
||||
else:
|
||||
relative_name = os.path.basename(input_file)
|
||||
else:
|
||||
relative_name = os.path.basename(input_file)
|
||||
f.write(f' {{ "{relative_name}", embedded_asset_{idx}_{var_name}, embedded_asset_{idx}_{var_name}_len }},\n')
|
||||
f.write('};\n\n')
|
||||
|
||||
f.write(f'static const int embedded_asset_count = {len(input_files)};\n\n')
|
||||
f.write('#endif /* EMBEDDED_ASSETS_H */\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 3:
|
||||
print('Usage: python embed_assets.py <output.h> <asset1> [asset2] ...')
|
||||
print(' Embeds images, sounds, fonts, and other asset files into a C header.')
|
||||
print(' Supported: .png, .jpg, .wav, .ogg, .mp3, .ttf, .otf, etc.')
|
||||
sys.exit(1)
|
||||
|
||||
output_file = sys.argv[1]
|
||||
input_files = sys.argv[2:]
|
||||
|
||||
# Check all input files exist
|
||||
for f in input_files:
|
||||
if not os.path.exists(f):
|
||||
print(f'Error: File not found: {f}')
|
||||
sys.exit(1)
|
||||
|
||||
embed_files(output_file, input_files)
|
||||
print(f'Embedded {len(input_files)} asset file(s) into {output_file}')
|
||||
for f in input_files:
|
||||
size = os.path.getsize(f)
|
||||
print(f' - {f} ({size} bytes)')
|
||||
57
scripts/embed_font.py
Normal file
57
scripts/embed_font.py
Normal file
@@ -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()
|
||||
64
scripts/embed_logo.py
Normal file
64
scripts/embed_logo.py
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Embed logo image files into C header for splash screens.
|
||||
Usage: python embed_logo.py <output.h> <raylib_logo.png> <reilua_logo.png>
|
||||
"""
|
||||
|
||||
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) != 4:
|
||||
print("Usage: python embed_logo.py <output.h> <raylib_logo.png> <reilua_logo.png>")
|
||||
sys.exit(1)
|
||||
|
||||
output_file = sys.argv[1]
|
||||
raylib_logo = sys.argv[2]
|
||||
reilua_logo = sys.argv[3]
|
||||
|
||||
# Check if files exist
|
||||
if not os.path.exists(raylib_logo):
|
||||
print(f"Error: {raylib_logo} not found!")
|
||||
sys.exit(1)
|
||||
|
||||
if not os.path.exists(reilua_logo):
|
||||
print(f"Error: {reilua_logo} not found!")
|
||||
sys.exit(1)
|
||||
|
||||
# Generate header content
|
||||
header_content = "/* Auto-generated embedded logo files */\n"
|
||||
header_content += "#pragma once\n\n"
|
||||
|
||||
# Embed both logo files
|
||||
header_content += embed_file(raylib_logo, "embedded_raylib_logo")
|
||||
header_content += embed_file(reilua_logo, "embedded_reilua_logo")
|
||||
|
||||
# Write to output file
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(header_content)
|
||||
|
||||
print(f"Generated {output_file}")
|
||||
print(f" - Embedded {raylib_logo} ({os.path.getsize(raylib_logo)} bytes)")
|
||||
print(f" - Embedded {reilua_logo} ({os.path.getsize(reilua_logo)} bytes)")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
92
scripts/embed_lua.py
Normal file
92
scripts/embed_lua.py
Normal file
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Embed multiple Lua files into a C header file for inclusion in the executable.
|
||||
Usage: python embed_lua.py <output.h> <file1.lua> [file2.lua] [file3.lua] ...
|
||||
|
||||
Embeds all specified Lua files into a C header with a virtual filesystem.
|
||||
The first file is treated as main.lua (entry point).
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def sanitize_name(filename):
|
||||
"""Convert filename to valid C identifier"""
|
||||
name = os.path.basename(filename)
|
||||
name = name.replace('.', '_').replace('-', '_').replace('/', '_').replace('\\', '_')
|
||||
return name
|
||||
|
||||
def embed_files(output_file, input_files):
|
||||
with open(output_file, 'w') as f:
|
||||
f.write('#ifndef EMBEDDED_MAIN_H\n')
|
||||
f.write('#define EMBEDDED_MAIN_H\n\n')
|
||||
f.write('/* Auto-generated file - do not edit manually */\n\n')
|
||||
|
||||
# Embed each file as a separate array
|
||||
for idx, input_file in enumerate(input_files):
|
||||
with open(input_file, 'rb') as inf:
|
||||
data = inf.read()
|
||||
|
||||
var_name = sanitize_name(input_file)
|
||||
f.write(f'/* Embedded file: {input_file} */\n')
|
||||
f.write(f'static const unsigned char embedded_lua_{idx}_{var_name}[] = {{\n')
|
||||
|
||||
for i, byte in enumerate(data):
|
||||
if i % 12 == 0:
|
||||
f.write(' ')
|
||||
f.write(f'0x{byte:02x}')
|
||||
if i < len(data) - 1:
|
||||
f.write(',')
|
||||
if (i + 1) % 12 == 0:
|
||||
f.write('\n')
|
||||
else:
|
||||
f.write(' ')
|
||||
|
||||
f.write('\n};\n')
|
||||
f.write(f'static const unsigned int embedded_lua_{idx}_{var_name}_len = {len(data)};\n\n')
|
||||
|
||||
# Create the file table
|
||||
f.write('/* File table for virtual filesystem */\n')
|
||||
f.write('typedef struct {\n')
|
||||
f.write(' const char* name;\n')
|
||||
f.write(' const unsigned char* data;\n')
|
||||
f.write(' unsigned int size;\n')
|
||||
f.write('} EmbeddedLuaFile;\n\n')
|
||||
|
||||
f.write('static const EmbeddedLuaFile embedded_lua_files[] = {\n')
|
||||
for idx, input_file in enumerate(input_files):
|
||||
var_name = sanitize_name(input_file)
|
||||
# Store both original filename and basename for require compatibility
|
||||
basename = os.path.basename(input_file)
|
||||
f.write(f' {{ "{basename}", embedded_lua_{idx}_{var_name}, embedded_lua_{idx}_{var_name}_len }},\n')
|
||||
f.write('};\n\n')
|
||||
|
||||
f.write(f'static const int embedded_lua_file_count = {len(input_files)};\n\n')
|
||||
|
||||
# Main entry point (first file)
|
||||
var_name = sanitize_name(input_files[0])
|
||||
f.write('/* Main entry point */\n')
|
||||
f.write(f'#define embedded_main_lua embedded_lua_0_{var_name}\n')
|
||||
f.write(f'#define embedded_main_lua_len embedded_lua_0_{var_name}_len\n\n')
|
||||
|
||||
f.write('#endif /* EMBEDDED_MAIN_H */\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 3:
|
||||
print('Usage: python embed_lua.py <output.h> <file1.lua> [file2.lua] ...')
|
||||
print(' The first Lua file is treated as the main entry point.')
|
||||
sys.exit(1)
|
||||
|
||||
output_file = sys.argv[1]
|
||||
input_files = sys.argv[2:]
|
||||
|
||||
# Check all input files exist
|
||||
for f in input_files:
|
||||
if not os.path.exists(f):
|
||||
print(f'Error: File not found: {f}')
|
||||
sys.exit(1)
|
||||
|
||||
embed_files(output_file, input_files)
|
||||
print(f'Embedded {len(input_files)} file(s) into {output_file}')
|
||||
for f in input_files:
|
||||
print(f' - {f}')
|
||||
|
||||
Reference in New Issue
Block a user