summaryrefslogtreecommitdiff
path: root/scripts/create_project.sh
blob: e6a21731b17f0aa9bd654b97885c04b4079a3221 (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
#!/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}

# 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 '*.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
    # Cross-platform sed: detect OS and use appropriate syntax
    if [[ "$OSTYPE" == "darwin"* ]]; then
        # macOS requires empty string after -i
        SED_INPLACE="sed -i ''"
    else
        # Linux/Windows Git Bash
        SED_INPLACE="sed -i"
    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

# 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

## 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
├── 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
\`\`\`

## Game Development

Edit \`main.lua\` and add your game code:

\`\`\`lua
function init()
    -- Initialize your game
end

function update(dt)
    -- Update game logic
end

function draw()
    -- Draw your game
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})
\`\`\`

## License

Add your license information here.

---

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

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

function init()
    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)
    
    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()
    end
end
EOFLUA

# Create assets directory
mkdir -p "$PROJECT_DIR/assets"
cat > "$PROJECT_DIR/assets/.gitkeep" << EOFKEEP
# Place your game assets here:
# - Images (.png, .jpg)
# - Sounds (.wav, .ogg, .mp3)
# - Fonts (.ttf)
# - Other resources
EOFKEEP

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 main.lua (your game code)"
echo "  3. Add assets to 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 "  ✓ 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)"
echo "  ✓ Raylib path: ../raylib (sibling directory)"
echo ""
echo "All projects are in: projects/ folder"
echo "Happy game development! 🎮"
echo ""