summaryrefslogtreecommitdiff
path: root/scripts/create_project.sh
blob: 9e71f8add118c3b6fa9ed8c4d7e141d98c83a477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
#!/bin/bash
# ReiLua-Enhanced Project Setup Script
# Creates a new game project with custom metadata

set -e

echo "╔════════════════════════════════════════════════════════════════════╗"
echo "║                                                                    ║"
echo "║              ReiLua-Enhanced - Project Setup Wizard               ║"
echo "║                                                                    ║"
echo "╚════════════════════════════════════════════════════════════════════╝"
echo ""

# Get script directory (ReiLua-Enhanced root)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"

# Function to validate alphanumeric input
validate_alphanumeric() {
    if [[ ! "$1" =~ ^[a-zA-Z0-9]+$ ]]; then
        return 1
    fi
    return 0
}

# Get project information
echo "Please provide your project information:"
echo "=========================================="
echo ""

# Project Name
while true; do
    read -p "Project Name (alphanumeric only, e.g., MyAwesomeGame): " PROJECT_NAME
    if validate_alphanumeric "$PROJECT_NAME"; then
        break
    else
        echo "❌ Invalid! Use only letters and numbers (no spaces or symbols)."
    fi
done

# Executable Name
read -p "Executable Name (default: $PROJECT_NAME): " EXECUTABLE_NAME
EXECUTABLE_NAME=${EXECUTABLE_NAME:-$PROJECT_NAME}

# Author Name
read -p "Author Name: " AUTHOR_NAME
if [ -z "$AUTHOR_NAME" ]; then
    AUTHOR_NAME="Unknown Author"
fi

# Author Email
read -p "Author Email: " AUTHOR_EMAIL
if [ -z "$AUTHOR_EMAIL" ]; then
    AUTHOR_EMAIL="author@example.com"
fi

# Description
read -p "Project Description: " DESCRIPTION
if [ -z "$DESCRIPTION" ]; then
    DESCRIPTION="A game made with ReiLua"
fi

# Company/Organization (for bundle identifier)
read -p "Company/Organization (for bundle ID, default: reilua): " COMPANY
COMPANY=${COMPANY:-reilua}

# Convert to lowercase and remove spaces for bundle ID
BUNDLE_ID=$(echo "${COMPANY}.${PROJECT_NAME}" | tr '[:upper:]' '[:lower:]' | tr -d ' ')

# Version
read -p "Version (default: 1.0.0): " VERSION
VERSION=${VERSION:-1.0.0}

echo ""
echo "=========================================="
echo "Project Summary:"
echo "=========================================="
echo "Project Name:     $PROJECT_NAME"
echo "Executable:       $EXECUTABLE_NAME"
echo "Author:           $AUTHOR_NAME"
echo "Email:            $AUTHOR_EMAIL"
echo "Description:      $DESCRIPTION"
echo "Bundle ID:        $BUNDLE_ID"
echo "Version:          $VERSION"
echo "=========================================="
echo ""

read -p "Create project with these settings? (Y/n): " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]] && [[ ! -z $REPLY ]]; then
    echo "Setup cancelled."
    exit 0
fi

# Create project directory
PROJECTS_ROOT="$SCRIPT_DIR/../projects"
mkdir -p "$PROJECTS_ROOT"

PROJECT_DIR="$PROJECTS_ROOT/${PROJECT_NAME}"

if [ -d "$PROJECT_DIR" ]; then
    echo ""
    echo "❌ ERROR: Directory 'projects/$PROJECT_NAME' already exists!"
    read -p "Delete it and continue? (y/N): " -n 1 -r
    echo ""
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        rm -rf "$PROJECT_DIR"
    else
        echo "Setup cancelled."
        exit 1
    fi
fi

echo ""
echo "Creating project directory: projects/$PROJECT_NAME"
mkdir -p "$PROJECT_DIR"

# Copy ReiLua structure
echo "Copying ReiLua-Enhanced files..."

# Create directory structure first
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/.." && \
 find . -type f \
    ! -path './build/*' \
    ! -path './deps/*' \
    ! -path './.git/*' \
    ! -path './projects/*' \
    ! -path './docs/*' \
    ! -path './docs_md/*' \
    ! -path './examples/*' \
    ! -path './template/*' \
    ! -path './tools/*' \
    ! -name '*.app' \
    ! -name '*.dmg' \
    ! -name '*.zip' \
    ! -name '*.o' \
    ! -name '*.md' \
    ! -name 'changelog' \
    ! -name 'devnotes' \
    ! -name 'logo.png' \
    ! -name 'LICENSE' \
    ! -name 'zed.sample.settings.json' \
    ! -name 'create_project.sh' \
    -exec sh -c 'mkdir -p "$0/$(dirname "{}")" && cp "{}" "$0/{}"' "$PROJECT_DIR" \;)

echo "✓ Files copied (essentials only: src, lib, scripts, assets)"
echo ""
echo "Setting up project files..."

# Get absolute paths for lua and raylib (sibling to ReiLua-Enhanced)
LUA_PATH="$(cd "$SCRIPT_DIR/.." && pwd)/lua"
RAYLIB_PATH="$(cd "$SCRIPT_DIR/.." && pwd)/raylib"

# Update build_static_libs.sh with correct paths
if [ -f "$PROJECT_DIR/scripts/macos/build_static_libs.sh" ]; then
    cat > "$PROJECT_DIR/scripts/macos/build_static_libs.sh" << 'EOFSCRIPT'
#!/bin/bash
# Build static raylib and lua libraries for macOS

set -e

echo "========================================"
echo "Building Static Libraries for macOS"
echo "========================================"
echo ""

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$SCRIPT_DIR/../.."
cd "$PROJECT_ROOT"

# Look for lua and raylib as siblings to this project
LUA_SRC="$(cd "$PROJECT_ROOT/.." && pwd)/lua"
RAYLIB_SRC="$(cd "$PROJECT_ROOT/.." && pwd)/raylib"

if [ ! -d "$LUA_SRC" ]; then
    echo "ERROR: Lua source not found at: $LUA_SRC"
    echo ""
    echo "Expected: ../lua relative to project"
    exit 1
fi

if [ ! -d "$RAYLIB_SRC" ]; then
    echo "ERROR: Raylib source not found at: $RAYLIB_SRC"
    echo ""
    echo "Expected: ../raylib relative to project"
    exit 1
fi

echo "Using sources:"
echo "  Lua:    $LUA_SRC"
echo "  Raylib: $RAYLIB_SRC"
echo ""

mkdir -p "$PROJECT_ROOT/lib/macos"

# Build Lua
echo "========================================"
echo "Building Lua 5.4 (static)"
echo "========================================"
cd "$LUA_SRC"
make clean || true

CFLAGS="-O2 -Wall -DLUA_USE_MACOSX -DLUA_USE_DLOPEN"
OBJS=""
for file in lapi lcode lctype ldebug ldo ldump lfunc lgc llex lmem lobject lopcodes lparser lstate lstring ltable ltm lundump lvm lzio lauxlib lbaselib ldblib liolib lmathlib loslib ltablib lstrlib lutf8lib loadlib lcorolib linit; do
    cc $CFLAGS -c ${file}.c -o ${file}.o
    OBJS="$OBJS ${file}.o"
done
ar rcs liblua.a $OBJS
cp liblua.a "$PROJECT_ROOT/lib/macos/"
LUASIZE=$(du -h "$PROJECT_ROOT/lib/macos/liblua.a" | cut -f1)
echo "✓ Lua: $LUASIZE"

# Build Raylib
echo ""
echo "========================================"
echo "Building Raylib 5.5 (static)"
echo "========================================"
cd "$RAYLIB_SRC"
rm -rf build_static
mkdir -p build_static && cd build_static
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF -DCUSTOMIZE_BUILD=ON
make -j$(sysctl -n hw.ncpu)
cp raylib/libraylib.a "$PROJECT_ROOT/lib/macos/"
RAYLIBSIZE=$(du -h "$PROJECT_ROOT/lib/macos/libraylib.a" | cut -f1)
echo "✓ Raylib: $RAYLIBSIZE"

echo ""
echo "Static libraries ready in lib/macos/"
EOFSCRIPT
    chmod +x "$PROJECT_DIR/scripts/macos/build_static_libs.sh"
fi

# Create custom resources.rc for Windows
cat > "$PROJECT_DIR/resources.rc" << EOFRC
IDI_ICON1 ICON "icon.ico"

1 VERSIONINFO
FILEVERSION ${VERSION//./,},0
PRODUCTVERSION ${VERSION//./,},0
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "CompanyName", "$AUTHOR_NAME"
            VALUE "FileDescription", "$DESCRIPTION"
            VALUE "FileVersion", "$VERSION"
            VALUE "InternalName", "$EXECUTABLE_NAME"
            VALUE "LegalCopyright", "Copyright (C) $AUTHOR_NAME, $(date +%Y)"
            VALUE "OriginalFilename", "${EXECUTABLE_NAME}.exe"
            VALUE "ProductName", "$PROJECT_NAME"
            VALUE "ProductVersion", "$VERSION"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END
EOFRC

# Create updated create_app_bundle.sh for macOS
cat > "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" << 'EOFBUNDLE'
#!/bin/bash
# Create macOS App Bundle with Icon and Metadata

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$SCRIPT_DIR/../.."
cd "$PROJECT_ROOT"

# Read project metadata
PROJECT_NAME="__PROJECT_NAME__"
EXECUTABLE_NAME="__EXECUTABLE_NAME__"
BUNDLE_ID="__BUNDLE_ID__"
VERSION="__VERSION__"
AUTHOR_NAME="__AUTHOR_NAME__"
DESCRIPTION="__DESCRIPTION__"

if [ ! -f "build/ReiLua" ]; then
    echo "ERROR: ReiLua executable not found! Build first."
    exit 1
fi

APP_NAME="${1:-$EXECUTABLE_NAME}"
APP_BUNDLE="${APP_NAME}.app"

echo "Creating $APP_BUNDLE..."
mkdir -p "$APP_BUNDLE/Contents/MacOS"
mkdir -p "$APP_BUNDLE/Contents/Resources"

cp build/ReiLua "$APP_BUNDLE/Contents/MacOS/$APP_NAME"
chmod +x "$APP_BUNDLE/Contents/MacOS/$APP_NAME"

# Convert icon
ICNS_FILE="$APP_BUNDLE/Contents/Resources/icon.icns"
if [ -f "icon.ico" ]; then
    mkdir -p icon.iconset
    sips -s format png icon.ico --out icon.iconset/icon_512x512.png -z 512 512 2>/dev/null || true
    if [ -f "icon.iconset/icon_512x512.png" ]; then
        sips -z 256 256 icon.iconset/icon_512x512.png --out icon.iconset/icon_256x256.png
        sips -z 128 128 icon.iconset/icon_512x512.png --out icon.iconset/icon_128x128.png
        sips -z 64 64   icon.iconset/icon_512x512.png --out icon.iconset/icon_64x64.png
        sips -z 32 32   icon.iconset/icon_512x512.png --out icon.iconset/icon_32x32.png
        sips -z 16 16   icon.iconset/icon_512x512.png --out icon.iconset/icon_16x16.png
        cp icon.iconset/icon_512x512.png icon.iconset/icon_256x256@2x.png
        cp icon.iconset/icon_256x256.png icon.iconset/icon_128x128@2x.png
        cp icon.iconset/icon_128x128.png icon.iconset/icon_64x64@2x.png
        cp icon.iconset/icon_64x64.png   icon.iconset/icon_32x32@2x.png
        cp icon.iconset/icon_32x32.png   icon.iconset/icon_16x16@2x.png
        iconutil -c icns icon.iconset -o "$ICNS_FILE"
    fi
    rm -rf icon.iconset
fi

# Create Info.plist with project metadata
cat > "$APP_BUNDLE/Contents/Info.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleExecutable</key>
    <string>$APP_NAME</string>
    <key>CFBundleIconFile</key>
    <string>icon.icns</string>
    <key>CFBundleIdentifier</key>
    <string>$BUNDLE_ID</string>
    <key>CFBundleName</key>
    <string>$PROJECT_NAME</string>
    <key>CFBundleDisplayName</key>
    <string>$PROJECT_NAME</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$VERSION</string>
    <key>CFBundleVersion</key>
    <string>$VERSION</string>
    <key>NSHumanReadableCopyright</key>
    <string>Copyright © $(date +%Y) $AUTHOR_NAME. All rights reserved.</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.12</string>
    <key>NSHighResolutionCapable</key>
    <true/>
</dict>
</plist>
EOF

echo "✓ $APP_BUNDLE created!"
echo "  open $APP_BUNDLE"
EOFBUNDLE

# Replace placeholders in create_app_bundle.sh
if [ -f "$PROJECT_DIR/scripts/macos/create_app_bundle.sh" ]; then
    # Use direct sed replacement for macOS (creates backup with different approach)
    if [[ "$OSTYPE" == "darwin"* ]]; then
        # 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 -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
    chmod +x "$PROJECT_DIR/scripts/macos/create_app_bundle.sh"
fi

# Create project metadata file
cat > "$PROJECT_DIR/project.info" << EOFINFO
# Project Information
PROJECT_NAME=$PROJECT_NAME
EXECUTABLE_NAME=$EXECUTABLE_NAME
AUTHOR_NAME=$AUTHOR_NAME
AUTHOR_EMAIL=$AUTHOR_EMAIL
DESCRIPTION=$DESCRIPTION
BUNDLE_ID=$BUNDLE_ID
VERSION=$VERSION
COMPANY=$COMPANY
CREATED=$(date +%Y-%m-%d)
EOFINFO

# Create README for the project
cat > "$PROJECT_DIR/README.md" << EOFREADME
# $PROJECT_NAME

$DESCRIPTION

## Project Information

- **Author:** $AUTHOR_NAME <$AUTHOR_EMAIL>
- **Version:** $VERSION
- **Created:** $(date +%Y-%m-%d)
- **Built with:** ReiLua-Enhanced

## Project Structure

\`\`\`
$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
\`\`\`

**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 \`game/main.lua\`:

\`\`\`lua
function RL.init()
    -- Load your assets
    player = RL.LoadTexture("assets/sprites/player.png")
end

function RL.update(delta)
    -- Update game logic
end

function RL.draw()
    -- Draw your game
    RL.ClearBackground(RL.RAYWHITE)
    RL.DrawTexture(player, 100, 100, RL.WHITE)
end
\`\`\`

## Distribution

### Windows
\`\`\`bash
# After build_release.sh
# The executable is: build/${EXECUTABLE_NAME}.exe
\`\`\`

### macOS
\`\`\`bash
# Create app bundle
./scripts/macos/create_app_bundle.sh

# Create DMG for distribution
hdiutil create -volname '$PROJECT_NAME' \\
    -srcfolder '${EXECUTABLE_NAME}.app' \\
    -ov -format UDZO ${EXECUTABLE_NAME}.dmg
\`\`\`

### Linux
\`\`\`bash
# After build_release.sh
# 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.

---

Built with [ReiLua-Enhanced](https://github.com/nullstare/ReiLua)
EOFREADME

# Create example main.lua
cat > "$PROJECT_DIR/game/main.lua" << EOFLUA
-- $PROJECT_NAME
-- $DESCRIPTION
-- Author: $AUTHOR_NAME

function RL.init()
    RL.SetWindowTitle( "$PROJECT_NAME" )
    RL.SetWindowState( RL.FLAG_VSYNC_HINT )
    
    print("$PROJECT_NAME initialized!")
    print("Version: $VERSION")
    print("Author: $AUTHOR_NAME")
end

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 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 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)
# - Fonts (.ttf)
# - 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 "║                                                                    ║"
echo "║                    ✅ Project Setup Complete! ✅                  ║"
echo "║                                                                    ║"
echo "╚════════════════════════════════════════════════════════════════════╝"
echo ""
echo "Project Details:"
echo "  Name:       $PROJECT_NAME"
echo "  Location:   projects/$PROJECT_NAME"
echo "  Executable: $EXECUTABLE_NAME"
echo "  Author:     $AUTHOR_NAME"
echo ""
echo "Next Steps:"
echo "  1. cd projects/$PROJECT_NAME"
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 "  ✓ 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 ""
echo "Build Scripts Updated:"
echo "  ✓ Lua path:    ../lua (sibling directory)"
echo "  ✓ Raylib path: ../raylib (sibling directory)"
echo ""
echo "All projects are in: projects/ folder"
echo "Happy game development! 🎮"
echo ""