-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.html
More file actions
344 lines (297 loc) · 9.09 KB
/
app.html
File metadata and controls
344 lines (297 loc) · 9.09 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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FGEngine - Editor & Game</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
background-color: #0f0f11;
color: white;
overflow: hidden;
}
.header {
background-color: #2d2d30;
padding: 10px 20px;
border-bottom: 1px solid #3e3e42;
display: flex;
justify-content: space-between;
align-items: center;
height: 50px;
box-sizing: border-box;
}
.header h1 {
margin: 0;
font-size: 18px;
font-weight: 400;
}
.header .controls {
display: flex;
gap: 10px;
}
.header button {
background-color: #0e639c;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.2s;
}
.header button:hover {
background-color: #1177bb;
}
.header button.active {
background-color: #007acc;
}
.main-container {
display: flex;
height: calc(100vh - 70px);
}
.panel {
flex: 1;
position: relative;
background-color: #1e1e1e;
border-right: 1px solid #3e3e42;
display: flex;
flex-direction: column;
}
.panel:last-child {
border-right: none;
}
.panel-header {
background-color: #2d2d30;
padding: 8px 16px;
border-bottom: 1px solid #3e3e42;
font-size: 14px;
font-weight: 500;
}
.panel-content {
flex: 1;
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.canvas-container {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.app-canvas {
background-color: #000;
border: 1px solid #3e3e42;
max-width: 100%;
max-height: 100%;
}
.loading-indicator {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
color: #888;
}
.spinner {
width: 40px;
height: 40px;
border: 4px solid #3e3e42;
border-top: 4px solid #007acc;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.hidden {
display: none !important;
}
.single-panel {
border-right: none;
}
.error-message {
color: #f48771;
background-color: #332222;
padding: 20px;
border-radius: 4px;
margin: 20px;
border-left: 4px solid #f48771;
}
@media (max-width: 768px) {
.main-container {
flex-direction: column;
}
.panel {
border-right: none;
border-bottom: 1px solid #3e3e42;
}
.panel:last-child {
border-bottom: none;
}
}
</style>
</head>
<body>
<div class="header">
<h1>FGEngine - Editor & Game</h1>
<div class="controls">
<button id="editorBtn" class="active">Editor</button>
<button id="gameBtn">Game</button>
<button id="bothBtn">Both</button>
</div>
</div>
<div class="main-container">
<!-- Editor Panel -->
<div id="editorPanel" class="panel">
<div class="panel-header">Editor</div>
<div class="panel-content">
<div class="canvas-container">
<canvas id="editorCanvas" class="app-canvas" width="800" height="600"></canvas>
<div id="editorLoading" class="loading-indicator">
<div class="spinner"></div>
<div>Loading Editor...</div>
</div>
</div>
</div>
</div>
<!-- Game Panel -->
<div id="gamePanel" class="panel hidden">
<div class="panel-header">Game</div>
<div class="panel-content">
<div class="canvas-container">
<canvas id="gameCanvas" class="app-canvas" width="800" height="600"></canvas>
<div id="gameLoading" class="loading-indicator">
<div class="spinner"></div>
<div>Loading Game...</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Panel management
const editorBtn = document.getElementById('editorBtn');
const gameBtn = document.getElementById('gameBtn');
const bothBtn = document.getElementById('bothBtn');
const editorPanel = document.getElementById('editorPanel');
const gamePanel = document.getElementById('gamePanel');
function setActiveButton(activeBtn) {
[editorBtn, gameBtn, bothBtn].forEach(btn => btn.classList.remove('active'));
activeBtn.classList.add('active');
}
function showEditor() {
setActiveButton(editorBtn);
editorPanel.classList.remove('hidden');
gamePanel.classList.add('hidden');
editorPanel.classList.add('single-panel');
resizeCanvases();
}
function showGame() {
setActiveButton(gameBtn);
editorPanel.classList.add('hidden');
gamePanel.classList.remove('hidden');
gamePanel.classList.add('single-panel');
resizeCanvases();
}
function showBoth() {
setActiveButton(bothBtn);
editorPanel.classList.remove('hidden', 'single-panel');
gamePanel.classList.remove('hidden', 'single-panel');
resizeCanvases();
}
// Canvas management
const editorCanvas = document.getElementById('editorCanvas');
const gameCanvas = document.getElementById('gameCanvas');
const editorLoading = document.getElementById('editorLoading');
const gameLoading = document.getElementById('gameLoading');
function resizeCanvases() {
setTimeout(() => {
[editorCanvas, gameCanvas].forEach(canvas => {
const container = canvas.parentElement;
const rect = container.getBoundingClientRect();
const maxWidth = rect.width - 40;
const maxHeight = rect.height - 40;
// Maintain aspect ratio
const aspectRatio = canvas.width / canvas.height;
let newWidth = maxWidth;
let newHeight = newWidth / aspectRatio;
if (newHeight > maxHeight) {
newHeight = maxHeight;
newWidth = newHeight * aspectRatio;
}
canvas.style.width = newWidth + 'px';
canvas.style.height = newHeight + 'px';
});
}, 100);
}
// Event listeners
editorBtn.addEventListener('click', showEditor);
gameBtn.addEventListener('click', showGame);
bothBtn.addEventListener('click', showBoth);
window.addEventListener('resize', resizeCanvases);
// WebAssembly loading functions
async function loadEditorWasm() {
try {
editorLoading.style.display = 'flex';
// This is where you would load your WebAssembly module
// Example:
// const go = new Go();
// const result = await WebAssembly.instantiateStreaming(fetch("editor.wasm"), go.importObject);
// go.run(result.instance);
// For now, just simulate loading
await new Promise(resolve => setTimeout(resolve, 2000));
editorLoading.style.display = 'none';
console.log('Editor WASM loaded');
} catch (error) {
editorLoading.innerHTML = `<div class="error-message">Failed to load editor: ${error.message}</div>`;
console.error('Failed to load editor WASM:', error);
}
}
async function loadGameWasm() {
try {
gameLoading.style.display = 'flex';
// This is where you would load your WebAssembly module
// Example:
// const go = new Go();
// const result = await WebAssembly.instantiateStreaming(fetch("game.wasm"), go.importObject);
// go.run(result.instance);
// For now, just simulate loading
await new Promise(resolve => setTimeout(resolve, 2000));
gameLoading.style.display = 'none';
console.log('Game WASM loaded');
} catch (error) {
gameLoading.innerHTML = `<div class="error-message">Failed to load game: ${error.message}</div>`;
console.error('Failed to load game WASM:', error);
}
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
resizeCanvases();
// Load WebAssembly modules
loadEditorWasm();
// Game WASM will be loaded when the game panel is first shown
// Set up observer to load game when it becomes visible
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.target === gamePanel && entry.isIntersecting && gameLoading.style.display !== 'none') {
loadGameWasm();
}
});
});
observer.observe(gamePanel);
});
</script>
</body>
</html>