diff options
| -rw-r--r-- | .DS_Store | bin | 18436 -> 18436 bytes | |||
| -rw-r--r-- | .gitignore | 6 | ||||
| -rw-r--r-- | CMakeLists.txt | 21 | ||||
| -rw-r--r-- | include/state.h | 2 | ||||
| -rw-r--r-- | projects/.DS_Store | bin | 8196 -> 6148 bytes | |||
| -rw-r--r-- | projects/README.md | 26 | ||||
| -rw-r--r-- | scripts/.DS_Store | bin | 8196 -> 10244 bytes | |||
| -rwxr-xr-x | scripts/build_release.sh | 93 | ||||
| -rwxr-xr-x | scripts/create_project.sh | 344 | ||||
| -rw-r--r-- | src/main.c | 42 | ||||
| -rw-r--r-- | src/state.c | 16 |
11 files changed, 446 insertions, 104 deletions
| Binary files differ @@ -1,2 +1,6 @@ .vscode -build/
\ No newline at end of file +build/ + +# Projects - ignore all folders inside projects/ except the projects folder itself +projects/*/ +!projects/README.md
\ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index f0b57da..aef831d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,20 @@ include( CMakeDependentOption ) include( EnumOption ) cmake_minimum_required( VERSION 3.9 ) -project( ReiLua ) + +# Try to read custom project name from project.info +set( PROJECT_NAME_VAR "ReiLua" ) +if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/project.info" ) + file( STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/project.info" PROJECT_INFO_LINES ) + foreach( LINE ${PROJECT_INFO_LINES} ) + if( LINE MATCHES "^EXECUTABLE_NAME=(.+)$" ) + set( PROJECT_NAME_VAR "${CMAKE_MATCH_1}" ) + message( STATUS "Using custom executable name: ${PROJECT_NAME_VAR}" ) + endif() + endforeach() +endif() + +project( ${PROJECT_NAME_VAR} ) # Find Python interpreter (python3 or python) find_package(Python3 COMPONENTS Interpreter) @@ -36,6 +49,12 @@ if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) endif() +# Set compiler flags for Release builds +if( CMAKE_BUILD_TYPE STREQUAL "Release" ) + add_definitions( -DNDEBUG ) + message( STATUS "Release build - logging disabled by default" ) +endif() + file( GLOB SOURCES src/*.c ) # Always embed logo files for splash screens diff --git a/include/state.h b/include/state.h index 3e7836d..5a04af4 100644 --- a/include/state.h +++ b/include/state.h @@ -50,7 +50,7 @@ typedef struct { extern State* state; -bool stateInit( int argn, const char** argc, const char* basePath ); +bool stateInit( int argn, const char** argc, const char* basePath, bool enable_logging ); void stateContextInit(); void stateInitInterpret( int argn, const char** argc ); void stateFree(); diff --git a/projects/.DS_Store b/projects/.DS_Store Binary files differindex e952635..1cd0ded 100644 --- a/projects/.DS_Store +++ b/projects/.DS_Store diff --git a/projects/README.md b/projects/README.md index 4ee9b0b..21b09f4 100644 --- a/projects/README.md +++ b/projects/README.md @@ -1,4 +1,24 @@ -# All projects go in this folder -# Projects created by create_project.sh +# Projects -Each project is a complete ReiLua-Enhanced setup ready to build. +This folder contains your game projects created with `scripts/create_project.sh`. + +Each project is self-contained with: +- **game/** - Your game code and assets +- **build/** - Compiled executable +- **scripts/** - Build and run scripts +- All necessary ReiLua source files + +## Create a New Project + +```bash +cd /path/to/ReiLua-Enhanced +./scripts/create_project.sh +``` + +The script will guide you through setting up: +- Project name +- Executable name +- Author information +- Version and metadata + +Your projects are automatically gitignored in the main repository. diff --git a/scripts/.DS_Store b/scripts/.DS_Store Binary files differindex a08bf15..12fb8bb 100644 --- a/scripts/.DS_Store +++ b/scripts/.DS_Store diff --git a/scripts/build_release.sh b/scripts/build_release.sh index 41a050c..5c0e6ab 100755 --- a/scripts/build_release.sh +++ b/scripts/build_release.sh @@ -72,8 +72,38 @@ cd build || exit 1 echo "Cleaning old embedded files..." rm -f embedded_main.h embedded_assets.h -# Check for Lua files +# Auto-copy from game folder if it exists echo "" +if [ -d "../game" ]; then + echo "Found game/ folder - auto-copying contents to build..." + + # Copy all Lua files from game folder EXCEPT ReiLua_API.lua + if ls ../game/*.lua 1> /dev/null 2>&1; then + for lua_file in ../game/*.lua; do + filename=$(basename "$lua_file") + if [ "$filename" != "ReiLua_API.lua" ]; then + cp "$lua_file" . + fi + done + LUA_COUNT=$(ls *.lua 2>/dev/null | wc -l) + echo " ✓ Copied $LUA_COUNT Lua file(s)" + else + echo " ⚠ No Lua files found in game/" + fi + + # Copy assets folder if it exists + if [ -d "../game/assets" ]; then + rm -rf assets + cp -r ../game/assets . + ASSET_COUNT=$(find assets -type f 2>/dev/null | wc -l) + echo " ✓ Copied assets/ ($ASSET_COUNT files)" + else + echo " ℹ No assets folder in game/" + fi + echo "" +fi + +# Check for Lua files echo "Checking for Lua files..." LUA_FILES=$(ls *.lua 2>/dev/null | wc -l) @@ -81,9 +111,15 @@ 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 ." + if [ -d "../game" ]; then + echo "No Lua files found in game/ folder either." + echo "Add your main.lua to game/ folder and try again." + else + echo "Tip: Create a game/ folder in project root and add main.lua there." + echo "Or manually copy files:" + echo " cd build" + echo " cp ../your_game/*.lua ." + fi echo "" read -p "Do you want to continue anyway? (y/N): " -n 1 -r echo "" @@ -102,10 +138,16 @@ 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/" + if [ -d "../game" ]; then + echo "No assets found in game/assets/ folder." + echo "Add assets to game/assets/ if you need them embedded." + else + echo "Tip: Create game/assets/ in project root for auto-copy." + echo "Or manually:" + echo " cd build" + echo " mkdir assets" + echo " cp ../your_game/assets/* assets/" + fi echo "" read -p "Do you want to continue without assets? (y/N): " -n 1 -r echo "" @@ -200,26 +242,41 @@ echo "================================" echo "Build Complete!" echo "================================" -# Detect executable name based on platform +# Read executable name from project.info +EXE_NAME="ReiLua" +if [ -f "../project.info" ]; then + EXE_NAME=$(grep "^EXECUTABLE_NAME=" ../project.info | cut -d'=' -f2) +fi + +# Detect executable extension based on platform if [[ "$OSTYPE" == "darwin"* ]]; then - EXE_NAME="ReiLua" + EXE_FILE="$EXE_NAME" else - EXE_NAME="ReiLua.exe" + EXE_FILE="${EXE_NAME}.exe" +fi + +if [ ! -f "$EXE_FILE" ]; then + echo "Warning: Expected executable not found: $EXE_FILE" + echo "Falling back to ReiLua..." + if [[ "$OSTYPE" == "darwin"* ]]; then + EXE_FILE="ReiLua" + else + EXE_FILE="ReiLua.exe" + fi fi -EXESIZE=$(du -h "$EXE_NAME" | cut -f1) +EXESIZE=$(du -h "$EXE_FILE" | cut -f1) echo "" -echo "Executable: $EXE_NAME ($EXESIZE)" -echo "Location: $(pwd)/$EXE_NAME" +echo "Executable: $EXE_FILE ($EXESIZE)" +echo "Location: $(pwd)/$EXE_FILE" echo "" echo "Your game is ready for distribution!" echo "" echo "To test the release build:" -echo " ./$EXE_NAME --log (with console)" -echo " ./$EXE_NAME (production mode)" +echo " ./$EXE_FILE --log (with console)" +echo " ./$EXE_FILE (production mode)" echo "" echo "To distribute:" -echo " - Copy $EXE_NAME to your distribution folder" -echo " - Rename it to your game name (optional)" +echo " - Copy $EXE_FILE to your distribution folder" echo " - That's it! Single file distribution!" echo "" diff --git a/scripts/create_project.sh b/scripts/create_project.sh index e6a2173..9e71f8a 100755 --- a/scripts/create_project.sh +++ b/scripts/create_project.sh @@ -119,7 +119,7 @@ mkdir -p "$PROJECT_DIR" echo "Copying ReiLua-Enhanced files..." # Create directory structure first -mkdir -p "$PROJECT_DIR"/{src,include,lib,scripts/macos,fonts,logo,cmake} +mkdir -p "$PROJECT_DIR"/{src,include,lib,scripts/macos,fonts,logo,cmake,game} # Copy files using find to preserve structure, excluding unnecessary files (cd "$SCRIPT_DIR/.." && \ @@ -140,7 +140,7 @@ mkdir -p "$PROJECT_DIR"/{src,include,lib,scripts/macos,fonts,logo,cmake} ! -name '*.md' \ ! -name 'changelog' \ ! -name 'devnotes' \ - ! -name '*.png' \ + ! -name 'logo.png' \ ! -name 'LICENSE' \ ! -name 'zed.sample.settings.json' \ ! -name 'create_project.sh' \ @@ -361,21 +361,24 @@ EOFBUNDLE # Replace placeholders in create_app_bundle.sh if [ -f "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" ]; then - # Cross-platform sed: detect OS and use appropriate syntax + # Use direct sed replacement for macOS (creates backup with different approach) if [[ "$OSTYPE" == "darwin"* ]]; then - # macOS requires empty string after -i - SED_INPLACE="sed -i ''" + # macOS sed + sed -i '' "s/__PROJECT_NAME__/$PROJECT_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i '' "s/__EXECUTABLE_NAME__/$EXECUTABLE_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i '' "s/__BUNDLE_ID__/$BUNDLE_ID/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i '' "s/__VERSION__/$VERSION/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i '' "s/__AUTHOR_NAME__/$AUTHOR_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i '' "s/__DESCRIPTION__/$DESCRIPTION/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" else # Linux/Windows Git Bash - SED_INPLACE="sed -i" + sed -i "s/__PROJECT_NAME__/$PROJECT_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i "s/__EXECUTABLE_NAME__/$EXECUTABLE_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i "s/__BUNDLE_ID__/$BUNDLE_ID/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i "s/__VERSION__/$VERSION/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i "s/__AUTHOR_NAME__/$AUTHOR_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" + sed -i "s/__DESCRIPTION__/$DESCRIPTION/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" fi - - $SED_INPLACE "s/__PROJECT_NAME__/$PROJECT_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" - $SED_INPLACE "s/__EXECUTABLE_NAME__/$EXECUTABLE_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" - $SED_INPLACE "s/__BUNDLE_ID__/$BUNDLE_ID/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" - $SED_INPLACE "s/__VERSION__/$VERSION/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" - $SED_INPLACE "s/__AUTHOR_NAME__/$AUTHOR_NAME/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" - $SED_INPLACE "s/__DESCRIPTION__/$DESCRIPTION/g" "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" chmod +x "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" fi @@ -406,62 +409,91 @@ $DESCRIPTION - **Created:** $(date +%Y-%m-%d) - **Built with:** ReiLua-Enhanced -## Building +## Project Structure -### Development Build -\`\`\`bash -./scripts/build_dev.sh +\`\`\` +$PROJECT_NAME/ +├── game/ # Your game files (edit here!) +│ ├── main.lua # Game entry point +│ └── assets/ # Game assets +├── build/ # Build output (auto-generated) +├── scripts/ # Build scripts +├── src/ # ReiLua C source +├── include/ # Headers +└── lib/ # Static libraries \`\`\` -### Release Build -\`\`\`bash -# Copy your Lua files and assets -mkdir -p build -cp *.lua build/ -cp -r assets build/ +**Important:** All your game development happens in the \`game/\` folder! -# Build -./scripts/build_release.sh +## Development Workflow + +### 1. Edit Your Game + +All your game files go in the \`game/\` folder: + +\`\`\` +game/ +├── main.lua # Your game code +├── player.lua # Game modules +├── enemy.lua +└── assets/ + ├── sprites/ + │ ├── player.png + │ └── enemy.png + └── sounds/ + └── music.wav \`\`\` -### macOS App Bundle +### 2. Build for Development + \`\`\`bash -./scripts/macos/create_app_bundle.sh +./scripts/build_dev.sh \`\`\` -## Project Structure +### 3. Run Your Game +From project root, ReiLua will automatically load from \`game/\` folder: + +\`\`\`bash +./build/ReiLua --no-logo --log \`\`\` -$PROJECT_NAME/ -├── main.lua # Your game entry point -├── assets/ # Game assets (images, sounds, etc.) -├── build/ # Build output directory -├── scripts/ # Build scripts -│ ├── build_dev.sh -│ ├── build_release.sh -│ └── macos/ -│ ├── build_static_libs.sh -│ └── create_app_bundle.sh -├── src/ # ReiLua C source -├── include/ # Headers -└── lib/ # Static libraries + +The engine checks paths in this order: +1. \`game/main.lua\` (if game folder exists) +2. \`main.lua\` (current directory) +3. Embedded files (release builds) + +### 4. Release Build + +Release build automatically copies from \`game/\` folder: + +\`\`\`bash +./scripts/build_release.sh \`\`\` +This will: +- Copy all \`.lua\` files from \`game/\` to \`build/\` +- Copy \`game/assets/\` to \`build/assets/\` +- Embed everything into the executable + ## Game Development -Edit \`main.lua\` and add your game code: +Edit \`game/main.lua\`: \`\`\`lua -function init() - -- Initialize your game +function RL.init() + -- Load your assets + player = RL.LoadTexture("assets/sprites/player.png") end -function update(dt) +function RL.update(delta) -- Update game logic end -function draw() +function RL.draw() -- Draw your game + RL.ClearBackground(RL.RAYWHITE) + RL.DrawTexture(player, 100, 100, RL.WHITE) end \`\`\` @@ -490,6 +522,24 @@ hdiutil create -volname '$PROJECT_NAME' \\ # The executable is: build/ReiLua (rename to ${EXECUTABLE_NAME}) \`\`\` +## Why the game/ Folder? + +The \`game/\` folder keeps your work organized and safe: + +- **Separation:** Your game files stay separate from build artifacts +- **Safety:** Rebuilding won't delete your game files +- **Clarity:** Anyone can see where the game code lives +- **Automation:** Release builds auto-copy from game/ folder + +## Editor Setup + +This project includes configurations for: +- **Lua Language Server** (\`.luarc.json\`) - Autocomplete and type checking +- **Zed Editor** (\`.zed/settings.json\`) - LSP configuration +- **Zed Tasks** (\`.zed/tasks.json\`) - Build and run commands + +Open the project in Zed and use \`Cmd+Shift+P\` → "Run Task" to build and run. + ## License Add your license information here. @@ -500,40 +550,41 @@ Built with [ReiLua-Enhanced](https://github.com/nullstare/ReiLua) EOFREADME # Create example main.lua -cat > "$PROJECT_DIR/main.lua" << EOFLUA +cat > "$PROJECT_DIR/game/main.lua" << EOFLUA -- $PROJECT_NAME -- $DESCRIPTION -- Author: $AUTHOR_NAME -function init() +function RL.init() + RL.SetWindowTitle( "$PROJECT_NAME" ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + print("$PROJECT_NAME initialized!") print("Version: $VERSION") print("Author: $AUTHOR_NAME") - - -- Initialize your game here end -function update(dt) - -- Update game logic here - -- dt = delta time in seconds +function RL.update( delta ) + -- Game logic goes here + -- delta is time since last frame in seconds + + if RL.IsKeyPressed( RL.KEY_ESCAPE ) then + RL.CloseWindow() + end end -function draw() - -- Draw your game here - RL.clearBackground(RL.RAYWHITE) - - RL.drawText("$PROJECT_NAME", 10, 10, 40, RL.BLACK) - RL.drawText("Press ESC to exit", 10, 60, 20, RL.DARKGRAY) +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) - if RL.isKeyPressed(RL.KEY_ESCAPE) then - RL.closeWindow() - end + RL.DrawText( "$PROJECT_NAME", { 10, 10 }, 40, RL.BLACK ) + RL.DrawText( "Press ESC to exit", { 10, 60 }, 20, RL.DARKGRAY ) end EOFLUA -# Create assets directory -mkdir -p "$PROJECT_DIR/assets" -cat > "$PROJECT_DIR/assets/.gitkeep" << EOFKEEP +# Create assets directory in game folder +mkdir -p "$PROJECT_DIR/game/assets" +cat > "$PROJECT_DIR/game/assets/.gitkeep" << EOFKEEP +# Game assets folder # Place your game assets here: # - Images (.png, .jpg) # - Sounds (.wav, .ogg, .mp3) @@ -541,6 +592,157 @@ cat > "$PROJECT_DIR/assets/.gitkeep" << EOFKEEP # - Other resources EOFKEEP +# Copy ReiLua API definitions for LSP to game folder +echo "Setting up game folder for development..." +if [ -f "$SCRIPT_DIR/../tools/ReiLua_API.lua" ]; then + cp "$SCRIPT_DIR/../tools/ReiLua_API.lua" "$PROJECT_DIR/game/" + echo " ✓ game/ReiLua_API.lua" +fi + +# Create .luarc.json for Lua Language Server in game folder +cat > "$PROJECT_DIR/game/.luarc.json" << EOFLUARC +{ + "runtime.version": "Lua 5.4", + "completion.enable": true, + "completion.callSnippet": "Replace", + "completion.displayContext": 3, + "diagnostics.globals": ["RL"], + "diagnostics.disable": [ + "lowercase-global", + "unused-local", + "duplicate-set-field", + "missing-fields", + "undefined-field" + ], + "workspace.checkThirdParty": false, + "workspace.library": ["ReiLua_API.lua"], + "hint.enable": true, + "hint.paramName": "All", + "hint.setType": true, + "hint.paramType": true +} +EOFLUARC + +echo " ✓ game/.luarc.json" + +# Create Zed editor configuration in project root +echo "Setting up Zed editor configuration..." +mkdir -p "$PROJECT_DIR/.zed" +mkdir -p "$PROJECT_DIR/scripts/run" + +# Create run scripts for tasks (cross-platform) +cat > "$PROJECT_DIR/scripts/run/run_dev.sh" << 'EOFRUNDEV' +#!/bin/bash +cd "$(dirname "$0")/../.." +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then + EXE=$(grep EXECUTABLE_NAME= project.info | cut -d= -f2) + ./build/${EXE}.exe --no-logo --log +else + EXE=$(grep EXECUTABLE_NAME= project.info | cut -d= -f2) + ./build/$EXE --no-logo --log +fi +EOFRUNDEV +chmod +x "$PROJECT_DIR/scripts/run/run_dev.sh" + +cat > "$PROJECT_DIR/scripts/run/run_no_splash.sh" << 'EOFRUNNOSPLASH' +#!/bin/bash +cd "$(dirname "$0")/../.." +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then + EXE=$(grep EXECUTABLE_NAME= project.info | cut -d= -f2) + ./build/${EXE}.exe --no-logo +else + EXE=$(grep EXECUTABLE_NAME= project.info | cut -d= -f2) + ./build/$EXE --no-logo +fi +EOFRUNNOSPLASH +chmod +x "$PROJECT_DIR/scripts/run/run_no_splash.sh" + +cat > "$PROJECT_DIR/scripts/run/run_release.sh" << 'EOFRUNRELEASE' +#!/bin/bash +cd "$(dirname "$0")/../.." +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then + EXE=$(grep EXECUTABLE_NAME= project.info | cut -d= -f2) + ./build/${EXE}.exe +else + EXE=$(grep EXECUTABLE_NAME= project.info | cut -d= -f2) + ./build/$EXE +fi +EOFRUNRELEASE +chmod +x "$PROJECT_DIR/scripts/run/run_release.sh" + +cat > "$PROJECT_DIR/.zed/settings.json" << EOFZED +{ + "inlay_hints": { + "enabled": true + }, + "lsp": { + "lua-language-server": { + "settings": { + "Lua.runtime.version": "Lua 5.4", + "Lua.workspace.library": [ + "game/ReiLua_API.lua" + ], + "Lua.completion.enable": true, + "Lua.completion.callSnippet": "Replace", + "Lua.completion.displayContext": 3, + "Lua.diagnostics.globals": [ + "RL" + ], + "Lua.hint.enable": true, + "Lua.hint.paramName": "All", + "Lua.hint.setType": true, + "Lua.hint.paramType": true, + "Lua.diagnostics.disable": [ + "lowercase-global", + "unused-local", + "duplicate-set-field", + "missing-fields", + "undefined-field" + ] + } + } + } +} +EOFZED + +cat > "$PROJECT_DIR/.zed/tasks.json" << EOFTASKS +[ + { + "label": "Run Game (Dev)", + "command": "./scripts/run/run_dev.sh", + "args": [], + "use_new_terminal": true + }, + { + "label": "Run Game (No Splash)", + "command": "./scripts/run/run_no_splash.sh", + "args": [], + "use_new_terminal": true + }, + { + "label": "Run Game (Release)", + "command": "./scripts/run/run_release.sh", + "args": [], + "use_new_terminal": true + }, + { + "label": "Build Dev", + "command": "./scripts/build_dev.sh", + "args": [], + "use_new_terminal": true + }, + { + "label": "Build Release", + "command": "./scripts/build_release.sh", + "args": [], + "use_new_terminal": true + } +] +EOFTASKS + +echo " ✓ .zed/settings.json" +echo " ✓ .zed/tasks.json" + echo "" echo "╔════════════════════════════════════════════════════════════════════╗" echo "║ ║" @@ -556,18 +758,22 @@ echo " Author: $AUTHOR_NAME" echo "" echo "Next Steps:" echo " 1. cd projects/$PROJECT_NAME" -echo " 2. Edit main.lua (your game code)" -echo " 3. Add assets to assets/ folder" +echo " 2. Edit game/main.lua (your game code)" +echo " 3. Add assets to game/assets/ folder" echo " 4. Build: ./scripts/build_dev.sh" echo " 5. Run: ./build/ReiLua" echo "" echo "Files Created:" -echo " ✓ main.lua - Game entry point" +echo " ✓ game/main.lua - Game entry point" +echo " ✓ game/assets/ - Asset directory" +echo " ✓ game/ReiLua_API.lua - API definitions for LSP" +echo " ✓ game/.luarc.json - Lua Language Server config" +echo " ✓ .zed/settings.json - Zed editor config" +echo " ✓ .zed/tasks.json - Build and run tasks" echo " ✓ project.info - Project metadata" echo " ✓ README.md - Project documentation" echo " ✓ resources.rc - Windows metadata (embedded in .exe)" echo " ✓ scripts/macos/create_app_bundle.sh - macOS bundle with metadata" -echo " ✓ assets/ - Asset directory" echo "" echo "Build Scripts Updated:" echo " ✓ Lua path: ../lua (sibling directory)" @@ -33,12 +33,14 @@ int main( int argn, const char** argc ) { bool interpret_mode = false; bool show_console = false; bool skip_splash = false; + bool enable_logging = false; #ifdef _WIN32 /* Check for --log and --no-logo arguments */ for ( int i = 1; i < argn; i++ ) { if ( strcmp( argc[i], "--log" ) == 0 ) { show_console = true; + enable_logging = true; } if ( strcmp( argc[i], "--no-logo" ) == 0 ) { skip_splash = true; @@ -59,11 +61,13 @@ int main( int argn, const char** argc ) { FreeConsole(); } #else - /* Check for --no-logo on non-Windows platforms */ + /* Check for --no-logo and --log on non-Windows platforms */ for ( int i = 1; i < argn; i++ ) { if ( strcmp( argc[i], "--no-logo" ) == 0 ) { skip_splash = true; - break; + } + if ( strcmp( argc[i], "--log" ) == 0 ) { + enable_logging = true; } } #endif @@ -96,26 +100,44 @@ int main( int argn, const char** argc ) { else { /* Only flags were provided, use default path search */ char testPath[ STRING_LEN ] = { '\0' }; - sprintf( testPath, "%s/main.lua", GetWorkingDirectory() ); + /* Check for game/main.lua in working directory */ + sprintf( testPath, "%s/game/main.lua", GetWorkingDirectory() ); if ( FileExists( testPath ) ) { - sprintf( basePath, "%s", GetWorkingDirectory() ); + sprintf( basePath, "%s/game/", GetWorkingDirectory() ); } + /* Check for main.lua in working directory */ else { - sprintf( basePath, "%s", GetApplicationDirectory() ); + sprintf( testPath, "%s/main.lua", GetWorkingDirectory() ); + if ( FileExists( testPath ) ) { + sprintf( basePath, "%s", GetWorkingDirectory() ); + } + /* Check exe directory */ + else { + sprintf( basePath, "%s", GetApplicationDirectory() ); + } } } } - /* If no argument given, check current directory first, then exe directory. */ + /* If no argument given, check game folder first, then current directory, then exe directory. */ else { char testPath[ STRING_LEN ] = { '\0' }; - sprintf( testPath, "%s/main.lua", GetWorkingDirectory() ); + /* Check for game/main.lua in working directory */ + sprintf( testPath, "%s/game/main.lua", GetWorkingDirectory() ); if ( FileExists( testPath ) ) { - sprintf( basePath, "%s", GetWorkingDirectory() ); + sprintf( basePath, "%s/game/", GetWorkingDirectory() ); } + /* Check for main.lua in working directory */ else { - sprintf( basePath, "%s", GetApplicationDirectory() ); + sprintf( testPath, "%s/main.lua", GetWorkingDirectory() ); + if ( FileExists( testPath ) ) { + sprintf( basePath, "%s", GetWorkingDirectory() ); + } + /* Check exe directory */ + else { + sprintf( basePath, "%s", GetApplicationDirectory() ); + } } } @@ -135,7 +157,7 @@ int main( int argn, const char** argc ) { } else { printVersion(); - stateInit( argn, argc, basePath ); + stateInit( argn, argc, basePath, enable_logging ); /* Show splash screens if not skipped */ if ( !skip_splash ) { diff --git a/src/state.c b/src/state.c index 4fdc729..2e946ea 100644 --- a/src/state.c +++ b/src/state.c @@ -10,7 +10,7 @@ State* state; -bool stateInit( int argn, const char** argc, const char* basePath ) { +bool stateInit( int argn, const char** argc, const char* basePath, bool enable_logging ) { state = malloc( sizeof( State ) ); state->basePath = malloc( STRING_LEN * sizeof( char ) ); @@ -36,6 +36,20 @@ bool stateInit( int argn, const char** argc, const char* basePath ) { state->mouseScale = (Vector2){ 1, 1 }; state->customFontLoaded = false; + /* Set log level based on build type and --log flag */ +#ifdef NDEBUG + /* Release build - only show warnings/errors unless --log is specified */ + if ( enable_logging ) { + SetTraceLogLevel( LOG_INFO ); + } + else { + SetTraceLogLevel( LOG_WARNING ); + } +#else + /* Debug/Dev build - always show all logs */ + SetTraceLogLevel( LOG_INFO ); +#endif + InitWindow( state->resolution.x, state->resolution.y, "ReiLua" ); if ( !IsWindowReady() ) { |
