From 8c9367f3689aee05d33fc1cae8a5d1aa6d2b5fb8 Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sun, 9 Nov 2025 16:12:20 +0530 Subject: [PATCH] Add game folder workflow, custom executable names, cross-platform tasks, and logging controls --- .DS_Store | Bin 18436 -> 18436 bytes .gitignore | 6 +- CMakeLists.txt | 21 ++- include/state.h | 2 +- projects/.DS_Store | Bin 8196 -> 6148 bytes projects/README.md | 26 ++- scripts/.DS_Store | Bin 8196 -> 10244 bytes scripts/build_release.sh | 97 ++++++++--- scripts/create_project.sh | 352 ++++++++++++++++++++++++++++++-------- src/main.c | 42 +++-- src/state.c | 16 +- 11 files changed, 452 insertions(+), 110 deletions(-) diff --git a/.DS_Store b/.DS_Store index a7c8a329d5ca0c5a79b9c2ca3bc37607a7da88c9..5fe589ca4e9f717cefbf6a4025d00f3f576944a7 100644 GIT binary patch delta 1891 zcmeH|PfQa*6vp4QOWo2+cUxL0TCEiAZfnd!2*DTxD@MT>2xtNblC~^#VcBiAMT96| zf;VH(cQIIneyI+0eDOjeTK zaU8K&nG)L$)?Vsx?ksb0yxYT<^IoslS5fJ&s@grsc@pvD*odJ|XhX+!RX1YlgxsSf zb*)>OmV2`DrEE?Na_-;iy5yk?o2jm|Q)yaMzM07{cG8e#?fi(L40Q|-XXI?p7Tr6@ zxiU#ZSJh5Eqhu9b>+R2^^vSlYJl>`a>v-Sio&BSxr#EgGacxA7O%15=gsgUGF+H2r z$8(jrZo2bML%yiUllgabr{hUQ8woY96~1?t-q+k+mz#UkEr|=5i!YZs2hWJP|iIRHKM4HJd(nk77lB9@2 zMhpFxA^;F5u2&2sL&XlrKoSfvFS}DV8^q|Tmf@$$2)>{U?DzX^q&lB!^`FMO5@#;? zn@Z3ToWcV^9>;{+o=3aR5lLQ)c2`2+!fi0AH#m^ zqa3(}DBh+Xa!;thc{+b7?8TVm!F9ohZ^9hz76T}8j0Fy1vlzvr0*BM0A5Fo7OX40p z!Mkxq+=cH29xV|cIz`SDBJB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K*X?|fgw3tCov|Jh z()ogG+k0Kl@-5dH==aT&K40U8rY!XjdTzl_2gdp>vM;3S_#S&kxUzS^EOK}**j_({?LH#X`ZWe8kX-Cf@th+(zF3?YO7(G206W~VQHO~(R!JBfpk>MDOm)1`V9p3S-gU` zc(O$dYjG~t<8oYq&A1Bh#Wq}r8?YVI*oED=8wW9u1|G#@Xk!secoN6(aeNA& z##4A2pU0Q+6?_d}$20g2zKieSC-@nDj$h(ecnN>TEBFgu#cOyS|B_^>PFgN$(p^%s zv`T7`R!f_uEz)*rpEM|Cr6J*iR7t$UlRgClX^cqq#0!rV>Fn(juW{S<9Xoe*&Dg~I zaXwGAJL(rLUJ_f;vS$4Q4{x0Wq`+?lvNxtefc_~t6QDmp$j!(VIjJ=EQhJyttEHwo zho>>S$fcX^RvOh=lt6-A*-Y$gN*=+kPBb>E66LI5Th}%!Y7J$i9O!OH5Q`zR@j*pV zYbiIy+GdSd2$@ux%PZK7nO?k}&@aK8w%ci}(`Z{#8Q$8GIAp!ng5#Jcl3Q zdHguYfN$}8yo|rzgz4_7n8rV=W4e?nIJWB?BMF`nb1PrTAp?23R4vMF`eH6_+)Bz! zwLUFejj-Cl>;KN`-~Xp&@5pErfhYnqBLZ04k?Ba$yHq=Sc�y=TUli<8oy|0~P9m ua-3*TjuV~yhart)B+7M?AuS6^Gt~a`4*}Euhj(=UNB95KQh6rc|NjEJtftHW 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 index a08bf1543e601f91f451d934759a2f83ae3cc8b9..12fb8bbb3c6a7a340a58002b6bac8919074a2a62 100644 GIT binary patch delta 1226 zcmZux&rcIU6n?V>TcovHXe$y-kX|&H1`|T`V5l`li-%SrrYPEMx6^iU*jaYBEqGZD zTqUVZJb3Wn!8>yC=*6S)?m_1OSk1qjC*k z8es@ccs1PKOt#aP5>ea`+yhjgghrtW>HW>u!S+t%AQ&17c_JbLWoUo_tUn6RG;ni_ z>t)8vLKH2Fmi{LfB7pEfrUP{!?}LvQ>+w99(#FCVng$L&(}Plz8J~pOlNhLQss!@N z$B%&yHh3bbi%Cmh;g-WXVjWM?Sc>|$KtU>B9S~laba?Ds-%vWHT`+b<_)uQn=@`_S%Vf0otw+X3tDvPmMcI>9rMLK zq?KpKN8ZY|g+cM-6DfArrqp~=vyDo=T6L&f?8B=iHR|X#XRN>-!!@|My5`h*E9cUU zoLS|VvT4v(-V#4KkErdSKgB7oYPPMJUX5nApE9jXS>DWY*X0``RLEf~1)B;fnS9yO zbi=Hr7JuP8!wk%766f{CTc|O}ljC`&PCh6qx7kPXB@+M=mmA^$ 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 -if [[ "$OSTYPE" == "darwin"* ]]; then - EXE_NAME="ReiLua" -else - EXE_NAME="ReiLua.exe" +# 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 -EXESIZE=$(du -h "$EXE_NAME" | cut -f1) +# Detect executable extension based on platform +if [[ "$OSTYPE" == "darwin"* ]]; then + EXE_FILE="$EXE_NAME" +else + 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_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 - -### Development Build -\`\`\`bash -./scripts/build_dev.sh -\`\`\` - -### Release Build -\`\`\`bash -# Copy your Lua files and assets -mkdir -p build -cp *.lua build/ -cp -r assets build/ - -# Build -./scripts/build_release.sh -\`\`\` - -### macOS App Bundle -\`\`\`bash -./scripts/macos/create_app_bundle.sh -\`\`\` - ## Project Structure \`\`\` $PROJECT_NAME/ -├── main.lua # Your game entry point -├── assets/ # Game assets (images, sounds, etc.) -├── build/ # Build output directory +├── game/ # Your game files (edit here!) +│ ├── main.lua # Game entry point +│ └── assets/ # Game assets +├── build/ # Build output (auto-generated) ├── 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 \`\`\` +**Important:** All your game development happens in the \`game/\` folder! + +## 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 +\`\`\` + +### 2. Build for Development + +\`\`\`bash +./scripts/build_dev.sh +\`\`\` + +### 3. Run Your Game + +From project root, ReiLua will automatically load from \`game/\` folder: + +\`\`\`bash +./build/ReiLua --no-logo --log +\`\`\` + +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 -end - -function draw() - -- Draw your game here - RL.clearBackground(RL.RAYWHITE) +function RL.update( delta ) + -- Game logic goes here + -- delta is time since last frame in seconds - RL.drawText("$PROJECT_NAME", 10, 10, 40, RL.BLACK) - RL.drawText("Press ESC to exit", 10, 60, 20, RL.DARKGRAY) - - if RL.isKeyPressed(RL.KEY_ESCAPE) then - RL.closeWindow() + if RL.IsKeyPressed( RL.KEY_ESCAPE ) then + RL.CloseWindow() end end + +function RL.draw() + RL.ClearBackground( RL.RAYWHITE ) + + 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)" diff --git a/src/main.c b/src/main.c index 72dbdca..19a49a3 100644 --- a/src/main.c +++ b/src/main.c @@ -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() ) {