-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·664 lines (608 loc) · 22.9 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·664 lines (608 loc) · 22.9 KB
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
#!/bin/bash
# Fail fast: exit on error, treat unset variables as errors, and propagate
# failures through pipelines. Empty-array and optional-env expansions below are
# written to stay safe under `set -u` on bash 3.2 (macOS system bash).
set -euo pipefail
# Default values
GAME="flappy_goud"
LOCAL=false
SKIP_BUILD=false
NEXT=false
SDK_TYPE="csharp" # csharp, python, rust, typescript
GAME_ARGS=()
# Script directory for absolute paths
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Returns success when a localhost TCP port is available to bind.
is_port_available() {
local port="$1"
python3 - "$port" <<'PY'
import socket
import sys
port = int(sys.argv[1])
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.bind(("127.0.0.1", port))
except OSError:
sys.exit(1)
finally:
sock.close()
sys.exit(0)
PY
}
# Picks a web server port for TS web demo. Defaults to 8765, falls back if occupied.
pick_web_port() {
local preferred="${TS_WEB_PORT:-8765}"
local port
if is_port_available "$preferred"; then
echo "$preferred"
return 0
fi
for port in $(seq 8766 8799); do
if is_port_available "$port"; then
echo "$port"
return 0
fi
done
return 1
}
csharp_example_uses_project_reference() {
local project_file="$SCRIPT_DIR/examples/csharp/$1/$1.csproj"
[ -f "$project_file" ] && rg -q "<ProjectReference " "$project_file"
}
native_lib_name() {
case "$(uname -s)" in
Darwin) echo "libgoud_engine.dylib" ;;
Linux) echo "libgoud_engine.so" ;;
MINGW*|MSYS*|CYGWIN*) echo "goud_engine.dll" ;;
*) echo "libgoud_engine.so" ;;
esac
}
rust_sources_newer_than() {
local artifact="$1"
[ -f "$artifact" ] || return 0
find \
"$SCRIPT_DIR/Cargo.toml" \
"$SCRIPT_DIR/Cargo.lock" \
"$SCRIPT_DIR/goud_engine" \
"$SCRIPT_DIR/goud_engine_macros" \
-type f \
\( -name '*.rs' -o -name '*.toml' \) \
-newer "$artifact" \
-print -quit | grep -q .
}
typescript_sources_newer_than() {
local artifact="$1"
[ -f "$artifact" ] || return 0
find \
"$SCRIPT_DIR/codegen" \
"$SCRIPT_DIR/sdks/typescript" \
"$SCRIPT_DIR/goud_engine" \
-type f \
\( -name '*.py' -o -name '*.json' -o -name '*.ts' -o -name '*.rs' -o -name '*.toml' \) \
-not -path '*/node_modules/*' \
-not -path '*/dist/*' \
-not -path '*/wasm/*' \
-newer "$artifact" \
-print -quit | grep -q .
}
python_release_artifact_fresh() {
local artifact="$SCRIPT_DIR/target/release/$(native_lib_name)"
[ -f "$artifact" ] && ! rust_sources_newer_than "$artifact"
}
typescript_native_artifacts_fresh() {
local node_artifact
node_artifact="$(find "$SCRIPT_DIR/sdks/typescript" -maxdepth 2 -type f -name '*.node' | head -n 1)"
[ -n "$node_artifact" ] || return 1
[ -f "$SCRIPT_DIR/sdks/typescript/dist/node/index.js" ] || return 1
! typescript_sources_newer_than "$node_artifact"
}
typescript_web_artifacts_fresh() {
[ -f "$SCRIPT_DIR/sdks/typescript/wasm/goud_engine_bg.wasm" ] || return 1
[ -f "$SCRIPT_DIR/sdks/typescript/dist/web/web/index.js" ] || return 1
! typescript_sources_newer_than "$SCRIPT_DIR/sdks/typescript/wasm/goud_engine_bg.wasm"
}
# Compiles a TypeScript web example with tsc and serves the repo root over HTTP.
# Usage: serve_typescript_web <example_dir> <label>
serve_typescript_web() {
local example_dir="$1"
local label="$2"
local web_port
echo "Compiling $label for web..."
cd "$SCRIPT_DIR/examples/typescript/$example_dir"
npx tsc
web_port="$(pick_web_port)" || {
echo "Error: No available localhost port found for web server (8765-8799)."
exit 1
}
echo ""
if [ "$web_port" != "${TS_WEB_PORT:-8765}" ]; then
echo "Port ${TS_WEB_PORT:-8765} is in use; using $web_port instead."
fi
echo "Starting web server on http://localhost:$web_port"
echo "Open: http://localhost:$web_port/examples/typescript/$example_dir/web/index.html"
echo "Press Ctrl+C to stop."
echo ""
cd "$SCRIPT_DIR"
python3 -m http.server "$web_port" --bind 127.0.0.1
}
ensure_example_node_modules() {
local example_dir="$1"
if [ -d "$example_dir/node_modules" ]; then
echo "Skipping npm install; example dependencies already present in $example_dir/node_modules"
return 0
fi
echo "Installing example dependencies..."
cd "$example_dir" && npm install
}
# Parse command line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--)
shift
GAME_ARGS=("$@")
break
;;
--game)
GAME="$2"
shift
;;
--sdk)
SDK_TYPE="$2"
shift
;;
--local) LOCAL=true ;;
--skipBuild) SKIP_BUILD=true ;;
--next) NEXT=true ;;
-h|--help)
echo "Usage: ./dev.sh [OPTIONS]"
echo " ./dev.sh [OPTIONS] -- [game arguments]"
echo ""
echo "Options:"
echo " --game <name> Game to run (default: flappy_goud)"
echo " --sdk <type> SDK type: c, csharp, cpp, go, kotlin, lua, python, rust, swift, typescript (default: csharp)"
echo " --local Use local feed when needed; direct-project C# examples use a fast local path"
echo " --skipBuild Skip build step"
echo " --next Run version increment and rebuild"
echo " -- Pass remaining args to the game executable"
echo " -h, --help Show this help message"
echo ""
echo "C Games: flappy_bird (use --sdk c)"
echo "C# Games: flappy_goud, 3d_cube, goud_jumper, isometric_rpg, hello_ecs, feature_lab, sandbox, character_sandbox"
echo "Python Demos: python_demo, flappy_bird, sandbox (use --sdk python)"
echo "Go Games: flappy_bird, sandbox, feature_lab (use --sdk go)"
echo "Kotlin Games: flappy_bird, sandbox, feature_lab (use --sdk kotlin)"
echo "Lua Games: flappy_bird, sandbox, feature_lab (use --sdk lua)"
echo "C++ Games: smoke, cmake_example, flappy_bird, sandbox, feature_lab (use --sdk cpp)"
echo "Swift Games: flappy_bird, sandbox, feature_lab (use --sdk swift)"
echo "Rust SDK: rust_demo (use --sdk rust)"
echo "TypeScript: flappy_bird (desktop), flappy_bird_web (web), feature_lab (desktop), feature_lab_web (web), sandbox (desktop), sandbox_web (web) (use --sdk typescript)"
echo ""
echo "Examples:"
echo " ./dev.sh --game flappy_goud # Run C# Flappy Goud"
echo " ./dev.sh --sdk python --game python_demo # Run Python demo"
echo " ./dev.sh --sdk python --game flappy_bird # Run Python Flappy Bird"
echo " ./dev.sh --sdk c --game flappy_bird # Run C Flappy Bird"
echo " ./dev.sh --sdk cpp --game flappy_bird # Run C++ Flappy Bird"
echo " ./dev.sh --sdk cpp --game cmake_example # Run C++ CMake example"
echo " ./dev.sh --sdk cpp --game sandbox # Run C++ Sandbox"
echo " ./dev.sh --sdk cpp --game feature_lab # Run C++ Feature Lab"
echo " ./dev.sh --sdk go --game flappy_bird # Run Go Flappy Bird"
echo " ./dev.sh --sdk go --game sandbox # Run Go Sandbox"
echo " ./dev.sh --sdk go --game feature_lab # Run Go Feature Lab"
echo " ./dev.sh --sdk swift --game flappy_bird # Run Swift Flappy Bird"
echo " ./dev.sh --sdk swift --game sandbox # Run Swift Sandbox"
echo " ./dev.sh --sdk swift --game feature_lab # Run Swift Feature Lab"
echo " ./dev.sh --sdk rust # Run Rust SDK tests"
echo " ./dev.sh --sdk typescript --game flappy_bird # TS desktop"
echo " ./dev.sh --sdk typescript --game flappy_bird_web # TS web (browser)"
echo " ./dev.sh --sdk typescript --game feature_lab # TS Feature Lab desktop"
echo " ./dev.sh --sdk typescript --game feature_lab_web # TS Feature Lab web"
echo " ./dev.sh --game sandbox # C# Sandbox desktop"
echo " ./dev.sh --game sandbox --local # C# Sandbox desktop with fast local project-reference path"
echo " ./dev.sh --sdk python --game sandbox # Python Sandbox desktop"
echo " ./dev.sh --sdk typescript --game sandbox # TS Sandbox desktop"
echo " ./dev.sh --sdk typescript --game sandbox_web # TS Sandbox web"
echo " ./dev.sh --sdk kotlin --game flappy_bird # Kotlin Flappy Bird"
echo " ./dev.sh --sdk kotlin --game sandbox # Kotlin Sandbox"
echo " ./dev.sh --sdk kotlin --game feature_lab # Kotlin Feature Lab"
echo " ./dev.sh --sdk lua --game sandbox # Lua Sandbox"
echo " ./dev.sh --sdk lua --game feature_lab # Lua Feature Lab"
exit 0
;;
*)
echo "Unknown parameter: $1"
echo "Use --help for usage information"
exit 1
;;
esac
shift
done
# Validate SDK type
case $SDK_TYPE in
"c" | "csharp" | "cpp" | "go" | "kotlin" | "lua" | "python" | "rust" | "swift" | "typescript")
;;
*)
echo "Error: Invalid SDK type. Choose from: c, csharp, cpp, go, kotlin, lua, python, rust, swift, typescript"
exit 1
;;
esac
# Validate game selection based on SDK type
case $SDK_TYPE in
"csharp")
case $GAME in
"flappy_goud" | "3d_cube" | "goud_jumper" | "isometric_rpg" | "hello_ecs" | "feature_lab" | "sandbox" | "character_sandbox")
echo "Building and running C# game: $GAME..."
;;
*)
echo "Error: Invalid C# game selection."
echo "Choose from: flappy_goud, 3d_cube, goud_jumper, isometric_rpg, hello_ecs, feature_lab, sandbox, character_sandbox"
exit 1
;;
esac
;;
"c")
case $GAME in
"flappy_bird")
echo "Building and running C example: $GAME..."
;;
*)
echo "Error: Invalid C example selection."
echo "Choose from: flappy_bird"
exit 1
;;
esac
;;
"cpp")
case $GAME in
"smoke" | "cmake_example" | "flappy_bird" | "sandbox" | "feature_lab")
echo "Building and running C++ example: $GAME..."
;;
*)
echo "Error: Invalid C++ example selection."
echo "Choose from: smoke, cmake_example, flappy_bird, sandbox, feature_lab"
exit 1
;;
esac
;;
"go")
case $GAME in
"flappy_bird" | "sandbox" | "feature_lab")
echo "Building and running Go example: $GAME..."
;;
*)
echo "Error: Invalid Go example selection."
echo "Choose from: flappy_bird, sandbox, feature_lab"
exit 1
;;
esac
;;
"lua")
case $GAME in
"flappy_bird" | "sandbox" | "feature_lab")
echo "Building and running Lua example: $GAME..."
;;
*)
echo "Error: Invalid Lua example selection."
echo "Choose from: flappy_bird, sandbox, feature_lab"
exit 1
;;
esac
;;
"python")
case $GAME in
"python_demo" | "flappy_bird" | "sandbox")
echo "Running Python demo: $GAME..."
;;
*)
echo "Error: Invalid Python demo selection."
echo "Choose from: python_demo, flappy_bird, sandbox"
exit 1
;;
esac
;;
"rust")
echo "Running Rust SDK..."
;;
"typescript")
case $GAME in
"flappy_bird" | "flappy_bird_web" | "feature_lab" | "feature_lab_web" | "sandbox" | "sandbox_web")
echo "Building and running TypeScript example: $GAME..."
;;
*)
echo "Error: Invalid TypeScript example selection."
echo "Choose from: flappy_bird (desktop), flappy_bird_web (web), feature_lab (desktop), feature_lab_web (web), sandbox (desktop), sandbox_web (web)"
exit 1
;;
esac
;;
"kotlin")
case $GAME in
"flappy_bird" | "sandbox" | "feature_lab")
echo "Building and running Kotlin example: $GAME..."
;;
*)
echo "Error: Invalid Kotlin example selection."
echo "Choose from: flappy_bird, sandbox, feature_lab"
exit 1
;;
esac
;;
"swift")
case $GAME in
"flappy_bird" | "sandbox" | "feature_lab")
echo "Building and running Swift example: $GAME..."
;;
*)
echo "Error: Invalid Swift example selection."
echo "Choose from: flappy_bird, sandbox, feature_lab"
exit 1
;;
esac
;;
esac
# Build the project if not skipped
if [ "$SKIP_BUILD" = false ]; then
# Prune stale incremental compilation cache (>7 days old) to prevent unbounded growth
if [ -d "target/debug/incremental" ]; then
find "$SCRIPT_DIR/target/debug/incremental" -maxdepth 1 -type d -mtime +7 -exec rm -rf {} + 2>/dev/null || true
fi
FAST_LOCAL_CSHARP_PATH=false
if [ "$SDK_TYPE" = "csharp" ] && [ "$LOCAL" = true ] && csharp_example_uses_project_reference "$GAME"; then
FAST_LOCAL_CSHARP_PATH=true
fi
# Skip the preflight check on the direct project-reference fast path.
# build.sh will compile the core once, so running cargo check here just duplicates the work.
if [ "$FAST_LOCAL_CSHARP_PATH" = true ]; then
echo "Skipping preflight cargo check for fast local C# path; the core build below will validate and compile once."
elif ! cargo check; then
echo "Cargo check failed. Fixing errors before proceeding with full build."
exit 1
fi
if [ "$SDK_TYPE" = "csharp" ]; then
# Ensure local NuGet feed directory exists
mkdir -p "$HOME/nuget-local"
if [ "$FAST_LOCAL_CSHARP_PATH" = true ]; then
echo "Using fast local C# path for project-reference example: $GAME"
bash "$SCRIPT_DIR/build.sh" --release --local --core-only --host-runtime-only --skip-csharp-sdk-build
elif [ "$LOCAL" = false ]; then
bash "$SCRIPT_DIR/package.sh" --prod
else
bash "$SCRIPT_DIR/package.sh" --local
fi
elif [ "$SDK_TYPE" = "lua" ]; then
echo "Building lua-runner..."
cargo build -p lua-runner
elif [ "$SDK_TYPE" = "c" ]; then
# Build native library for C examples
if python_release_artifact_fresh; then
echo "Skipping native rebuild; release artifact is fresh."
else
echo "Building native library..."
cargo build --release
fi
elif [ "$SDK_TYPE" = "cpp" ]; then
# Build native library for C++ examples
if python_release_artifact_fresh; then
echo "Skipping native rebuild; release artifact is fresh."
else
echo "Building native library..."
cargo build --release
fi
elif [ "$SDK_TYPE" = "typescript" ]; then
if [ "$GAME" = "flappy_bird_web" ] || [ "$GAME" = "feature_lab_web" ] || [ "$GAME" = "sandbox_web" ]; then
if typescript_web_artifacts_fresh; then
echo "Skipping TypeScript web SDK rebuild; wasm artifacts are fresh."
else
echo "Running codegen..."
python3 "$SCRIPT_DIR/codegen/gen_ts_node.py"
python3 "$SCRIPT_DIR/codegen/gen_ts_web.py"
echo "Building TypeScript web SDK (wasm)..."
cd "$SCRIPT_DIR/sdks/typescript" && npm run build:web
cd "$SCRIPT_DIR"
fi
else
if typescript_native_artifacts_fresh; then
echo "Skipping TypeScript native SDK rebuild; native artifacts are fresh."
else
echo "Running codegen..."
python3 "$SCRIPT_DIR/codegen/gen_ts_node.py"
python3 "$SCRIPT_DIR/codegen/gen_ts_web.py"
echo "Building TypeScript native SDK..."
cd "$SCRIPT_DIR/sdks/typescript" && npm run build:native && npm run build:ts
cd "$SCRIPT_DIR"
fi
fi
TS_EXAMPLE_DIR="flappy_bird"
case $GAME in
"feature_lab" | "feature_lab_web")
TS_EXAMPLE_DIR="feature_lab"
;;
"sandbox" | "sandbox_web")
TS_EXAMPLE_DIR="sandbox"
;;
esac
ensure_example_node_modules "$SCRIPT_DIR/examples/typescript/$TS_EXAMPLE_DIR"
cd "$SCRIPT_DIR"
elif [ "$SDK_TYPE" = "kotlin" ]; then
echo "Kotlin SDK build is handled by Gradle."
elif [ "$SDK_TYPE" = "go" ]; then
echo "Building native library for Go SDK..."
cargo build --release
elif [ "$SDK_TYPE" = "swift" ]; then
# Build native library for Swift examples
if python_release_artifact_fresh; then
echo "Skipping native rebuild; release artifact is fresh."
else
echo "Building native library..."
cargo build --release
fi
else
# For Python and Rust, just build the native library
if [ "$SDK_TYPE" = "python" ] && python_release_artifact_fresh; then
echo "Skipping native rebuild; release Python artifact is fresh."
else
echo "Building native library..."
cargo build --release
fi
fi
fi
# If --next flag is set, run additional scripts
if [ "$NEXT" = true ]; then
echo "Running next script..."
"$SCRIPT_DIR/increment_version.sh"
"$SCRIPT_DIR/build.sh"
"$SCRIPT_DIR/package.sh" --local
fi
# Run the appropriate SDK demo
case $SDK_TYPE in
"csharp")
# cd into selected game directory and restore packages from the local feed
cd "$SCRIPT_DIR/examples/csharp/$GAME"
# Prefer host dotnet. If .NET 8 runtime is missing but a newer runtime exists,
# allow major roll-forward so net8 apps still launch.
DOTNET_CMD="dotnet"
DOTNET_RUNNER=()
if ! dotnet --list-runtimes | grep -q "Microsoft.NETCore.App 8\\."; then
if dotnet --list-runtimes | grep -q "Microsoft.NETCore.App "; then
DOTNET_RUNNER=(env DOTNET_ROLL_FORWARD=Major)
fi
fi
# Direct-project examples do not need local package publish or feed restore churn.
if [ "$LOCAL" = true ] && csharp_example_uses_project_reference "$GAME"; then
${DOTNET_RUNNER[@]+"${DOTNET_RUNNER[@]}"} "$DOTNET_CMD" restore --nologo
${DOTNET_RUNNER[@]+"${DOTNET_RUNNER[@]}"} "$DOTNET_CMD" build --no-restore --nologo -p:GeneratePackageOnBuild=false
else
${DOTNET_RUNNER[@]+"${DOTNET_RUNNER[@]}"} "$DOTNET_CMD" clean --nologo
${DOTNET_RUNNER[@]+"${DOTNET_RUNNER[@]}"} "$DOTNET_CMD" restore --source "$HOME/nuget-local" --source https://api.nuget.org/v3/index.json --nologo
${DOTNET_RUNNER[@]+"${DOTNET_RUNNER[@]}"} "$DOTNET_CMD" build --no-restore --nologo
fi
${DOTNET_RUNNER[@]+"${DOTNET_RUNNER[@]}"} "$DOTNET_CMD" run --no-build --nologo -- ${GAME_ARGS[@]+"${GAME_ARGS[@]}"}
;;
"c")
C_EXAMPLE_DIR="$SCRIPT_DIR/examples/c/$GAME"
C_BUILD_DIR="$C_EXAMPLE_DIR/build"
echo "Configuring C example: $GAME..."
cmake -B "$C_BUILD_DIR" \
-DGOUD_ENGINE_ROOT="$SCRIPT_DIR" \
-DCMAKE_BUILD_TYPE=Release \
"$C_EXAMPLE_DIR"
echo "Building C example: $GAME..."
cmake --build "$C_BUILD_DIR" --config Release
echo "Running C example: $GAME..."
cd "$C_EXAMPLE_DIR"
"$C_BUILD_DIR/flappy_bird"
;;
"cpp")
CPP_EXAMPLE_DIR="$SCRIPT_DIR/examples/cpp/$GAME"
CPP_BUILD_DIR="$CPP_EXAMPLE_DIR/build"
echo "Configuring C++ example: $GAME..."
cmake -B "$CPP_BUILD_DIR" \
-DGOUD_ENGINE_ROOT="$SCRIPT_DIR" \
-DCMAKE_BUILD_TYPE=Release \
"$CPP_EXAMPLE_DIR"
echo "Building C++ example: $GAME..."
cmake --build "$CPP_BUILD_DIR" --config Release
echo "Running C++ example: $GAME..."
cd "$CPP_EXAMPLE_DIR"
"$CPP_BUILD_DIR/$GAME"
;;
"lua")
echo "Running Lua $GAME..."
cargo run -p lua-runner -- "$SCRIPT_DIR/examples/lua/$GAME/main.lua"
;;
"python")
# Ensure Python SDK path is accessible
export PYTHONPATH="$SCRIPT_DIR/sdks/python:${PYTHONPATH:-}"
# Set library path for native bindings
if [[ "$OSTYPE" == "darwin"* ]]; then
export DYLD_LIBRARY_PATH="$SCRIPT_DIR/target/release:${DYLD_LIBRARY_PATH:-}"
export GOUD_ENGINE_LIB="${GOUD_ENGINE_LIB:-$SCRIPT_DIR/target/release/$(native_lib_name)}"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
export LD_LIBRARY_PATH="$SCRIPT_DIR/target/release:${LD_LIBRARY_PATH:-}"
export GOUD_ENGINE_LIB="${GOUD_ENGINE_LIB:-$SCRIPT_DIR/target/release/$(native_lib_name)}"
fi
cd "$SCRIPT_DIR/examples/python"
case $GAME in
"python_demo")
echo "Running Python SDK demo..."
python3 main.py
;;
"flappy_bird")
echo "Running Python Flappy Bird..."
python3 flappy_bird.py
;;
"sandbox")
echo "Running Python Sandbox..."
python3 sandbox.py
;;
esac
;;
"go")
GO_EXAMPLE_DIR="$SCRIPT_DIR/examples/go/$GAME"
echo "Building and running Go example: $GAME..."
# Set library path for native bindings
if [[ "$OSTYPE" == "darwin"* ]]; then
export DYLD_LIBRARY_PATH="$SCRIPT_DIR/target/release:${DYLD_LIBRARY_PATH:-}"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
export LD_LIBRARY_PATH="$SCRIPT_DIR/target/release:${LD_LIBRARY_PATH:-}"
fi
cd "$GO_EXAMPLE_DIR"
CGO_ENABLED=1 go run .
;;
"rust")
# Run Rust SDK tests and examples
echo "Running Rust SDK tests..."
cargo test --lib sdk -- --nocapture
echo ""
echo "Running Rust SDK doctests..."
cargo test --doc sdk -- --nocapture
echo ""
echo "=== Rust SDK Demo Complete ==="
echo "All Rust SDK tests passed!"
;;
"typescript")
case $GAME in
"flappy_bird")
echo "Running TypeScript Flappy Bird (desktop)..."
cd "$SCRIPT_DIR/examples/typescript/flappy_bird"
npx tsx desktop.ts
;;
"flappy_bird_web")
serve_typescript_web "flappy_bird" "Flappy Bird"
;;
"feature_lab")
echo "Running TypeScript Feature Lab (desktop)..."
cd "$SCRIPT_DIR/examples/typescript/feature_lab"
npx tsx desktop.ts
;;
"feature_lab_web")
serve_typescript_web "feature_lab" "Feature Lab"
;;
"sandbox")
echo "Running TypeScript Sandbox (desktop)..."
cd "$SCRIPT_DIR/examples/typescript/sandbox"
npx tsx desktop.ts
;;
"sandbox_web")
serve_typescript_web "sandbox" "Sandbox"
;;
esac
;;
"kotlin")
echo "Running Kotlin example: $GAME..."
cd "$SCRIPT_DIR/examples/kotlin/$GAME" && ./gradlew run --no-daemon
;;
"swift")
SWIFT_EXAMPLE_DIR="$SCRIPT_DIR/examples/swift/$GAME"
export GOUD_ENGINE_LIB_DIR="$SCRIPT_DIR/target/release"
echo "Building Swift example: $GAME..."
cd "$SWIFT_EXAMPLE_DIR"
swift build -c release
echo "Running Swift example: $GAME..."
if [[ "$OSTYPE" == "darwin"* ]]; then
DYLD_LIBRARY_PATH="$GOUD_ENGINE_LIB_DIR:${DYLD_LIBRARY_PATH:-}" swift run -c release --skip-build
else
LD_LIBRARY_PATH="$GOUD_ENGINE_LIB_DIR:${LD_LIBRARY_PATH:-}" swift run -c release --skip-build
fi
;;
esac