-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·211 lines (173 loc) · 5.97 KB
/
start.sh
File metadata and controls
executable file
·211 lines (173 loc) · 5.97 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
#!/usr/bin/env bash
# Start script for Lua Game Example
# Launches both the LOVE2D game (frontend) and integration examples (backend)
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo "==================================================================="
echo "Lua Game Example - Start Script"
echo "==================================================================="
echo ""
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Cleanup function
cleanup() {
echo ""
echo "-------------------------------------------------------------------"
echo "Shutting down..."
echo "-------------------------------------------------------------------"
# Kill all background jobs
jobs -p | xargs -r kill 2>/dev/null || true
echo "All processes stopped."
exit 0
}
# Set up trap to catch Ctrl+C
trap cleanup SIGINT SIGTERM
# Check prerequisites
echo "Checking prerequisites..."
echo ""
MISSING_DEPS=0
if ! command_exists love; then
echo -e "${RED}[ERROR]${NC} LOVE2D is not installed"
echo "Run ./install.sh to install dependencies"
MISSING_DEPS=1
fi
if ! command_exists node; then
echo -e "${RED}[ERROR]${NC} Node.js is not installed"
echo "Run ./install.sh to install dependencies"
MISSING_DEPS=1
fi
if [ ! -d "integration/node_modules" ]; then
echo -e "${RED}[ERROR]${NC} Node.js dependencies not installed"
echo "Run ./install.sh or: cd integration && npm install"
MISSING_DEPS=1
fi
if [ $MISSING_DEPS -eq 1 ]; then
echo ""
echo "Please install missing dependencies first."
exit 1
fi
echo -e "${GREEN}[OK]${NC} All prerequisites met"
echo ""
# Start menu
echo "==================================================================="
echo "Select what to start:"
echo "==================================================================="
echo ""
echo " 1) LOVE2D Game (Frontend)"
echo " 2) JavaScript Integration Examples (Backend)"
echo " 3) TypeScript Integration Examples (Backend)"
echo " 4) LOVE2D Game + JavaScript Backend"
echo " 5) LOVE2D Game + TypeScript Backend"
echo " 6) All (Game + Both Backends)"
echo ""
read -p "Enter your choice (1-6): " -n 1 -r
echo ""
echo ""
case $REPLY in
1)
echo "-------------------------------------------------------------------"
echo "Starting LOVE2D Game..."
echo "-------------------------------------------------------------------"
echo ""
love .
;;
2)
echo "-------------------------------------------------------------------"
echo "Starting JavaScript Integration Examples..."
echo "-------------------------------------------------------------------"
echo ""
cd integration
node lua-runner.js
;;
3)
echo "-------------------------------------------------------------------"
echo "Starting TypeScript Integration Examples..."
echo "-------------------------------------------------------------------"
echo ""
cd integration
npx ts-node lua-bridge.ts
;;
4)
echo "-------------------------------------------------------------------"
echo "Starting LOVE2D Game + JavaScript Backend..."
echo "-------------------------------------------------------------------"
echo ""
# Start JavaScript backend in background
echo -e "${BLUE}[Backend]${NC} Starting JavaScript integration..."
cd integration
node lua-runner.js &
BACKEND_PID=$!
cd ..
sleep 1
# Start LOVE2D game in foreground
echo -e "${BLUE}[Frontend]${NC} Starting LOVE2D game..."
echo ""
love .
# When game exits, cleanup
kill $BACKEND_PID 2>/dev/null || true
;;
5)
echo "-------------------------------------------------------------------"
echo "Starting LOVE2D Game + TypeScript Backend..."
echo "-------------------------------------------------------------------"
echo ""
# Start TypeScript backend in background
echo -e "${BLUE}[Backend]${NC} Starting TypeScript integration..."
cd integration
npx ts-node lua-bridge.ts &
BACKEND_PID=$!
cd ..
sleep 1
# Start LOVE2D game in foreground
echo -e "${BLUE}[Frontend]${NC} Starting LOVE2D game..."
echo ""
love .
# When game exits, cleanup
kill $BACKEND_PID 2>/dev/null || true
;;
6)
echo "-------------------------------------------------------------------"
echo "Starting All Services..."
echo "-------------------------------------------------------------------"
echo ""
# Start JavaScript backend
echo -e "${BLUE}[Backend]${NC} Starting JavaScript integration..."
cd integration
node lua-runner.js > ../logs/js-backend.log 2>&1 &
JS_PID=$!
cd ..
sleep 1
# Start TypeScript backend
echo -e "${BLUE}[Backend]${NC} Starting TypeScript integration..."
cd integration
npx ts-node lua-bridge.ts > ../logs/ts-backend.log 2>&1 &
TS_PID=$!
cd ..
sleep 1
# Start LOVE2D game
echo -e "${BLUE}[Frontend]${NC} Starting LOVE2D game..."
echo ""
echo "Backend logs:"
echo " - JavaScript: logs/js-backend.log"
echo " - TypeScript: logs/ts-backend.log"
echo ""
love .
# When game exits, cleanup
kill $JS_PID $TS_PID 2>/dev/null || true
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
echo ""
echo "==================================================================="
echo "All services stopped."
echo "==================================================================="