| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"> |
| 6 | <meta name="author" content="Godot Engine"> |
| 7 | <meta name="description" content="Use the Godot Engine editor directly in your web browser, without having to install anything."> |
| 8 | <meta name="mobile-web-app-capable" content="yes"> |
| 9 | <meta name="apple-mobile-web-app-capable" content="yes"> |
| 10 | <meta name="application-name" content="Godot"> |
| 11 | <meta name="apple-mobile-web-app-title" content="Godot"> |
| 12 | <meta name="theme-color" content="#202531"> |
| 13 | <meta name="msapplication-navbutton-color" content="#202531"> |
| 14 | <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> |
| 15 | <meta name="msapplication-starturl" content="/latest"> |
| 16 | <meta property="og:site_name" content="Godot Engine Web Editor"> |
| 17 | <meta property="og:url" name="twitter:url" content="https://editor.godotengine.org/releases/latest/"> |
| 18 | <meta property="og:title" name="twitter:title" content="Free and open source 2D and 3D game engine"> |
| 19 | <meta property="og:description" name="twitter:description" content="Use the Godot Engine editor directly in your web browser, without having to install anything."> |
| 20 | <meta property="og:image" name="twitter:image" content="https://godotengine.org/themes/godotengine/assets/og_image.png"> |
| 21 | <meta property="og:type" content="website"> |
| 22 | <meta name="twitter:card" content="summary"> |
| 23 | <link id="-gd-engine-icon" rel="icon" type="image/png" href="favicon.png"> |
| 24 | <link rel="apple-touch-icon" type="image/png" href="favicon.png"> |
| 25 | <link rel="manifest" href="manifest.json"> |
| 26 | <title>Godot Engine Web Editor (___GODOT_VERSION___)</title> |
| 27 | <style> |
| 28 | *:focus { |
| 29 | /* More visible outline for better keyboard navigation. */ |
| 30 | outline: 0.125rem solid hsl(220, 100%, 62.5%); |
| 31 | /* Make the outline always appear above other elements. */ |
| 32 | /* Otherwise, one of its sides can be hidden by tabs in the Download and More layouts. */ |
| 33 | position: relative; |
| 34 | } |
| 35 | |
| 36 | body { |
| 37 | touch-action: none; |
| 38 | font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; |
| 39 | margin: 0; |
| 40 | border: 0 none; |
| 41 | padding: 0; |
| 42 | text-align: center; |
| 43 | background-color: #333b4f; |
| 44 | overflow: hidden; |
| 45 | } |
| 46 | |
| 47 | a { |
| 48 | color: hsl(205, 100%, 75%); |
| 49 | text-decoration-color: hsla(205, 100%, 75%, 0.3); |
| 50 | text-decoration-thickness: 0.125rem; |
| 51 | } |
| 52 | |
| 53 | a:hover { |
| 54 | filter: brightness(117.5%); |
| 55 | } |
| 56 | |
| 57 | a:active { |
| 58 | filter: brightness(82.5%); |
| 59 | } |
| 60 | |
| 61 | .welcome-modal { |
| 62 | display: none; |
| 63 | position: fixed; |
| 64 | z-index: 1; |
| 65 | left: 0; |
| 66 | top: 0; |
| 67 | width: 100%; |
| 68 | height: 100%; |
| 69 | overflow: auto; |
| 70 | background-color: hsla(0, 0%, 0%, 0.5); |
| 71 | text-align: left; |
| 72 | } |
| 73 | |
| 74 | .welcome-modal-title { |
| 75 | text-align: center; |
| 76 | } |
| 77 | |
| 78 | .welcome-modal-content { |
| 79 | background-color: #333b4f; |
| 80 | box-shadow: 0 0.25rem 0.25rem hsla(0, 0%, 0%, 0.5); |
| 81 | line-height: 1.5; |
| 82 | max-width: 38rem; |
| 83 | margin: 4rem auto 0 auto; |
| 84 | color: white; |
| 85 | border-radius: 0.5rem; |
| 86 | padding: 1rem 1rem 2rem 1rem; |
| 87 | } |
| 88 | |
| 89 | #tabs-buttons { |
| 90 | /* Match the default background color of the editor window for a seamless appearance. */ |
| 91 | background-color: #202531; |
| 92 | } |
| 93 | |
| 94 | #tab-game { |
| 95 | /* Use a pure black background to better distinguish the running project */ |
| 96 | /* from the editor window, and to use a more neutral background color (no tint). */ |
| 97 | background-color: black; |
| 98 | /* Make the background span the entire page height. */ |
| 99 | min-height: 100vh; |
| 100 | } |
| 101 | |
| 102 | #canvas, #gameCanvas { |
| 103 | display: block; |
| 104 | margin: 0; |
| 105 | color: white; |
| 106 | } |
| 107 | |
| 108 | /* Don't show distracting focus outlines for the main tabs' contents. */ |
| 109 | #tab-editor canvas:focus, |
| 110 | #tab-game canvas:focus, |
| 111 | #canvas:focus, |
| 112 | #gameCanvas:focus { |
| 113 | outline: none; |
| 114 | } |
| 115 | |
| 116 | .godot { |
| 117 | color: #e0e0e0; |
| 118 | background-color: #3b3943; |
| 119 | background-image: linear-gradient(to bottom, #403e48, #35333c); |
| 120 | border: 1px solid #45434e; |
| 121 | box-shadow: 0 0 1px 1px #2f2d35; |
| 122 | } |
| 123 | |
| 124 | .btn { |
| 125 | appearance: none; |
| 126 | color: #e0e0e0; |
| 127 | background-color: #262c3b; |
| 128 | border: 1px solid #202531; |
| 129 | padding: 0.5rem 1rem; |
| 130 | margin: 0 0.5rem; |
| 131 | } |
| 132 | |
| 133 | .btn:not(:disabled):hover { |
| 134 | color: #e0e1e5; |
| 135 | border-color: #666c7b; |
| 136 | } |
| 137 | |
| 138 | .btn:active { |
| 139 | border-color: #699ce8; |
| 140 | color: #699ce8; |
| 141 | } |
| 142 | |
| 143 | .btn:disabled { |
| 144 | color: #aaa; |
| 145 | border-color: #242937; |
| 146 | } |
| 147 | |
| 148 | .btn.tab-btn { |
| 149 | padding: 0.3rem 1rem; |
| 150 | } |
| 151 | |
| 152 | .btn.close-btn { |
| 153 | padding: 0.3rem 1rem; |
| 154 | margin-left: -0.75rem; |
| 155 | font-weight: 700; |
| 156 | } |
| 157 | |
| 158 | /* Status display */ |
| 159 | |
| 160 | #status { |
| 161 | position: absolute; |
| 162 | left: 0; |
| 163 | top: 0; |
| 164 | right: 0; |
| 165 | bottom: 0; |
| 166 | display: flex; |
| 167 | justify-content: center; |
| 168 | align-items: center; |
| 169 | /* don't consume click events - make children visible explicitly */ |
| 170 | visibility: hidden; |
| 171 | } |
| 172 | |
| 173 | #status-progress { |
| 174 | width: 366px; |
| 175 | height: 7px; |
| 176 | background-color: #38363A; |
| 177 | border: 1px solid #444246; |
| 178 | padding: 1px; |
| 179 | box-shadow: 0 0 2px 1px #1B1C22; |
| 180 | border-radius: 2px; |
| 181 | visibility: visible; |
| 182 | } |
| 183 | |
| 184 | @media only screen and (orientation:portrait) { |
| 185 | #status-progress { |
| 186 | width: 61.8%; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | #status-progress-inner { |
| 191 | height: 100%; |
| 192 | width: 0; |
| 193 | box-sizing: border-box; |
| 194 | transition: width 0.5s linear; |
| 195 | background-color: #202020; |
| 196 | border: 1px solid #222223; |
| 197 | box-shadow: 0 0 1px 1px #27282E; |
| 198 | border-radius: 3px; |
| 199 | } |
| 200 | |
| 201 | #status-indeterminate { |
| 202 | visibility: visible; |
| 203 | position: relative; |
| 204 | } |
| 205 | |
| 206 | #status-indeterminate > div { |
| 207 | width: 4.5px; |
| 208 | height: 0; |
| 209 | border-style: solid; |
| 210 | border-width: 9px 3px 0 3px; |
| 211 | border-color: #2b2b2b transparent transparent transparent; |
| 212 | transform-origin: center 21px; |
| 213 | position: absolute; |
| 214 | } |
| 215 | |
| 216 | #status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); } |
| 217 | #status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); } |
| 218 | #status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); } |
| 219 | #status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); } |
| 220 | #status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); } |
| 221 | #status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); } |
| 222 | #status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); } |
| 223 | #status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); } |
| 224 | |
| 225 | #status-notice { |
| 226 | margin: 0 100px; |
| 227 | line-height: 1.3; |
| 228 | visibility: visible; |
| 229 | padding: 4px 6px; |
| 230 | } |
| 231 | </style> |
| 232 | </head> |
| 233 | <body> |
| 234 | <div |
| 235 | id="welcome-modal" |
| 236 | class="welcome-modal" |
| 237 | role="dialog" |
| 238 | aria-labelledby="welcome-modal-title" |
| 239 | aria-describedby="welcome-modal-description" |
| 240 | onclick="if (event.target === this) closeWelcomeModal(false)" |
| 241 | > |
| 242 | <div class="welcome-modal-content"> |
| 243 | <h2 id="welcome-modal-title" class="welcome-modal-title">Important - Please read before continuing</h2> |
| 244 | <div id="welcome-modal-description"> |
| 245 | <p> |
| 246 | The Godot Web Editor has some limitations compared to the native version. |
| 247 | Its main focus is education and experimentation; |
| 248 | <strong>it is not recommended for production</strong>. |
| 249 | </p> |
| 250 | <p> |
| 251 | Refer to the |
| 252 | <a |
| 253 | href="https://docs.godotengine.org/en/latest/tutorials/editor/using_the_web_editor.html" |
| 254 | target="_blank" |
| 255 | rel="noopener" |
| 256 | >Web editor documentation</a> for usage instructions and limitations. |
| 257 | </p> |
| 258 | </div> |
| 259 | <div id="welcome-modal-missing-description" style="display: none"> |
| 260 | <p> |
| 261 | <strong>The following features required by the Godot Web Editor are missing:</strong> |
| 262 | </p> |
| 263 | <ul id="welcome-modal-missing-list"> |
| 264 | </ul> |
| 265 | <p> |
| 266 | If you are self-hosting the web editor, |
| 267 | refer to |
| 268 | <a |
| 269 | href="https://docs.godotengine.org/en/latest/tutorials/export/exporting_for_web.html" |
| 270 | target="_blank" |
| 271 | rel="noopener" |
| 272 | >Exporting for the Web</a> for more information. |
| 273 | </p> |
| 274 | </div> |
| 275 | <div style="text-align: center"> |
| 276 | <button id="welcome-modal-dismiss" class="btn" type="button" onclick="closeWelcomeModal(true)" style="margin-top: 1rem"> |
| 277 | OK, don't show again |
| 278 | </button> |
| 279 | </div> |
| 280 | </div> |
| 281 | </div> |
| 282 | <div id="tabs-buttons"> |
| 283 | <button id="btn-tab-loader" class="btn tab-btn" onclick="showTab('loader')">Loader</button> |
| 284 | <button id="btn-tab-editor" class="btn tab-btn" disabled="disabled" onclick="showTab('editor')">Editor</button> |
| 285 | <button id="btn-close-editor" class="btn close-btn" disabled="disabled" onclick="closeEditor()">×</button> |
| 286 | <button id="btn-tab-game" class="btn tab-btn" disabled="disabled" onclick="showTab('game')">Game</button> |
| 287 | <button id="btn-close-game" class="btn close-btn" disabled="disabled" onclick="closeGame()">×</button> |
| 288 | <button id="btn-tab-update" class="btn tab-btn" style="display: none;">Update</button> |
| 289 | </div> |
| 290 | <div id="tabs"> |
| 291 | <div id="tab-loader"> |
| 292 | <div style="color: #e0e0e0;" id="persistence"> |
| 293 | <br > |
| 294 | <img src="logo.svg" alt="Godot Engine logo" width="1024" height="414" style="width: auto; height: auto; max-width: min(85%, 50vh); max-height: 250px"> |
| 295 | <br > |
| 296 | ___GODOT_VERSION___ |
| 297 | <br > |
| 298 | <a href="/releases/">Need an old version?</a> |
| 299 | <br > |
| 300 | <br > |
| 301 | <br > |
| 302 | <label for="videoMode" style="margin-right: 1rem">Video driver:</label> |
| 303 | <select id="videoMode"> |
| 304 | <option value="" selected="selected">Auto</option> |
| 305 | <option value="opengl3">WebGL 2</option> |
| 306 | </select> |
| 307 | <br > |
| 308 | <br > |
| 309 | <label for="zip-file" style="margin-right: 1rem">Preload project ZIP:</label> |
| 310 | <input id="zip-file" type="file" name="files" style="margin-bottom: 1rem"> |
| 311 | <br > |
| 312 | <a href="demo.zip">(Try this for example)</a> |
| 313 | <br > |
| 314 | <br > |
| 315 | <button id="startButton" class="btn" style="margin-bottom: 4rem; font-weight: 700">Start Godot editor</button> |
| 316 | <br > |
| 317 | <button class="btn" onclick="clearPersistence()" style="margin-bottom: 1.5rem">Clear persistent data</button> |
| 318 | <br > |
| 319 | <a href="https://docs.godotengine.org/en/latest/tutorials/editor/using_the_web_editor.html">Web editor documentation</a> |
| 320 | </div> |
| 321 | </div> |
| 322 | <div id="tab-editor" style="display: none;"> |
| 323 | <canvas id="editor-canvas" tabindex="1"> |
| 324 | HTML5 canvas appears to be unsupported in the current browser.<br > |
| 325 | Please try updating or use a different browser. |
| 326 | </canvas> |
| 327 | </div> |
| 328 | <div id="tab-game" style="display: none;"> |
| 329 | <canvas id="game-canvas" tabindex="2"> |
| 330 | HTML5 canvas appears to be unsupported in the current browser.<br > |
| 331 | Please try updating or use a different browser. |
| 332 | </canvas> |
| 333 | </div> |
| 334 | <div id="tab-status" style="display: none;"> |
| 335 | <div id="status-progress" style="display: none;" oncontextmenu="event.preventDefault();"> |
| 336 | <div id="status-progress-inner"></div> |
| 337 | </div> |
| 338 | <div id="status-indeterminate" style="display: none;" oncontextmenu="event.preventDefault();"> |
| 339 | <div></div> |
| 340 | <div></div> |
| 341 | <div></div> |
| 342 | <div></div> |
| 343 | <div></div> |
| 344 | <div></div> |
| 345 | <div></div> |
| 346 | <div></div> |
| 347 | </div> |
| 348 | <div id="status-notice" class="godot" style="display: none;"></div> |
| 349 | </div> |
| 350 | </div> |
| 351 | <script> |
| 352 | window.addEventListener('load', () => { |
| 353 | function notifyUpdate(sw) { |
| 354 | const btn = document.getElementById('btn-tab-update'); |
| 355 | btn.onclick = function () { |
| 356 | if (!window.confirm('Are you sure you want to update?\nClicking "OK" will reload all active instances!')) { |
| 357 | return; |
| 358 | } |
| 359 | sw.postMessage('update'); |
| 360 | btn.innerHTML = 'Updating...'; |
| 361 | btn.disabled = true; |
| 362 | }; |
| 363 | btn.style.display = ''; |
| 364 | } |
| 365 | if ('serviceWorker' in navigator) { |
| 366 | try { |
| 367 | navigator.serviceWorker.register('service.worker.js').then(function (reg) { |
| 368 | if (reg.waiting) { |
| 369 | notifyUpdate(reg.waiting); |
| 370 | } |
| 371 | reg.addEventListener('updatefound', function () { |
| 372 | const update = reg.installing; |
| 373 | update.addEventListener('statechange', function () { |
| 374 | if (update.state === 'installed') { |
| 375 | // It's a new install, claim and perform aggressive caching. |
| 376 | if (!reg.active) { |
| 377 | update.postMessage('claim'); |
| 378 | } else { |
| 379 | notifyUpdate(update); |
| 380 | } |
| 381 | } |
| 382 | }); |
| 383 | }); |
| 384 | }); |
| 385 | } catch (e) { |
| 386 | console.error('Error while registering service worker:', e); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | const missing = Engine.getMissingFeatures({ |
| 391 | threads: ___GODOT_THREADS_ENABLED___, |
| 392 | }); |
| 393 | if (missing.length) { |
| 394 | // Display error dialog as threading support is required for the editor. |
| 395 | document.getElementById('startButton').disabled = 'disabled'; |
| 396 | document.getElementById('welcome-modal-description').style.display = 'none'; |
| 397 | document.getElementById('welcome-modal-missing-description').style.display = 'block'; |
| 398 | document.getElementById('welcome-modal-dismiss').style.display = 'none'; |
| 399 | const list = document.getElementById('welcome-modal-missing-list'); |
| 400 | for (let i = 0; i < missing.length; i++) { |
| 401 | const node = document.createElement('li'); |
| 402 | node.innerText = missing[i]; |
| 403 | list.appendChild(node); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if (missing.length || localStorage.getItem('welcomeModalDismissed') !== 'true') { |
| 408 | document.getElementById('welcome-modal').style.display = 'block'; |
| 409 | document.getElementById('welcome-modal-dismiss').focus(); |
| 410 | } |
| 411 | }); |
| 412 | |
| 413 | function closeWelcomeModal(dontShowAgain) { // eslint-disable-line no-unused-vars |
| 414 | document.getElementById('welcome-modal').style.display = 'none'; |
| 415 | if (dontShowAgain) { |
| 416 | localStorage.setItem('welcomeModalDismissed', 'true'); |
| 417 | } |
| 418 | } |
| 419 | </script> |
| 420 | <script src="godot.editor.js"></script> |
| 421 | <script> |
| 422 | let editor = null; |
| 423 | let game = null; |
| 424 | let setStatusMode; |
| 425 | let setStatusNotice; |
| 426 | let video_driver = ''; |
| 427 | |
| 428 | function clearPersistence() { // eslint-disable-line no-unused-vars |
| 429 | function deleteDB(path) { |
| 430 | return new Promise(function (resolve, reject) { |
| 431 | const req = indexedDB.deleteDatabase(path); |
| 432 | req.onsuccess = function () { |
| 433 | resolve(); |
| 434 | }; |
| 435 | req.onerror = function (err) { |
| 436 | reject(err); |
| 437 | }; |
| 438 | req.onblocked = function (err) { |
| 439 | reject(err); |
| 440 | }; |
| 441 | }); |
| 442 | } |
| 443 | if (!window.confirm('Are you sure you want to delete all the locally stored files?\nClicking "OK" will permanently remove your projects and editor settings!')) { |
| 444 | return; |
| 445 | } |
| 446 | Promise.all([ |
| 447 | deleteDB('/home/web_user'), |
| 448 | ]).then(function (results) { |
| 449 | alert('Done.'); |
| 450 | }).catch(function (err) { |
| 451 | alert('Error deleting local files. Please retry after reloading the page.'); |
| 452 | }); |
| 453 | } |
| 454 | |
| 455 | function selectVideoMode() { |
| 456 | const select = document.getElementById('videoMode'); |
| 457 | video_driver = select.selectedOptions[0].value; |
| 458 | } |
| 459 | |
| 460 | const tabs = [ |
| 461 | document.getElementById('tab-loader'), |
| 462 | document.getElementById('tab-editor'), |
| 463 | document.getElementById('tab-game'), |
| 464 | ]; |
| 465 | function showTab(name) { |
| 466 | tabs.forEach(function (elem) { |
| 467 | if (elem.id === `tab-${name}`) { |
| 468 | elem.style.display = 'block'; |
| 469 | if (name === 'editor' || name === 'game') { |
| 470 | const canvas = document.getElementById(`${name}-canvas`); |
| 471 | canvas.focus(); |
| 472 | } |
| 473 | } else { |
| 474 | elem.style.display = 'none'; |
| 475 | } |
| 476 | }); |
| 477 | } |
| 478 | |
| 479 | function setButtonEnabled(id, enabled) { |
| 480 | if (enabled) { |
| 481 | document.getElementById(id).disabled = ''; |
| 482 | } else { |
| 483 | document.getElementById(id).disabled = 'disabled'; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | function setLoaderEnabled(enabled) { |
| 488 | setButtonEnabled('btn-tab-loader', enabled); |
| 489 | setButtonEnabled('btn-tab-editor', !enabled); |
| 490 | setButtonEnabled('btn-close-editor', !enabled); |
| 491 | } |
| 492 | |
| 493 | function setGameTabEnabled(enabled) { |
| 494 | setButtonEnabled('btn-tab-game', enabled); |
| 495 | setButtonEnabled('btn-close-game', enabled); |
| 496 | } |
| 497 | |
| 498 | function closeGame() { |
| 499 | if (game) { |
| 500 | game.requestQuit(); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | function closeEditor() { // eslint-disable-line no-unused-vars |
| 505 | closeGame(); |
| 506 | if (editor) { |
| 507 | editor.requestQuit(); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | function startEditor(zip) { |
| 512 | const INDETERMINATE_STATUS_STEP_MS = 100; |
| 513 | const persistentPaths = ['/home/web_user']; |
| 514 | |
| 515 | let editorCanvas = document.getElementById('editor-canvas'); |
| 516 | let gameCanvas = document.getElementById('game-canvas'); |
| 517 | const statusProgress = document.getElementById('status-progress'); |
| 518 | const statusProgressInner = document.getElementById('status-progress-inner'); |
| 519 | const statusIndeterminate = document.getElementById('status-indeterminate'); |
| 520 | const statusNotice = document.getElementById('status-notice'); |
| 521 | const headerDiv = document.getElementById('tabs-buttons'); |
| 522 | |
| 523 | let initializing = true; |
| 524 | let statusMode = 'hidden'; |
| 525 | |
| 526 | showTab('status'); |
| 527 | |
| 528 | let animationCallbacks = []; |
| 529 | function animate(time) { |
| 530 | animationCallbacks.forEach((callback) => callback(time)); |
| 531 | requestAnimationFrame(animate); |
| 532 | } |
| 533 | requestAnimationFrame(animate); |
| 534 | |
| 535 | let lastScale = 0; |
| 536 | let lastWidth = 0; |
| 537 | let lastHeight = 0; |
| 538 | function adjustCanvasDimensions() { |
| 539 | const scale = window.devicePixelRatio || 1; |
| 540 | const headerHeight = headerDiv.offsetHeight + 1; |
| 541 | const width = window.innerWidth; |
| 542 | const height = window.innerHeight - headerHeight; |
| 543 | if (lastScale !== scale || lastWidth !== width || lastHeight !== height) { |
| 544 | editorCanvas.width = width * scale; |
| 545 | editorCanvas.height = height * scale; |
| 546 | editorCanvas.style.width = `${width}px`; |
| 547 | editorCanvas.style.height = `${height}px`; |
| 548 | lastScale = scale; |
| 549 | lastWidth = width; |
| 550 | lastHeight = height; |
| 551 | } |
| 552 | } |
| 553 | animationCallbacks.push(adjustCanvasDimensions); |
| 554 | adjustCanvasDimensions(); |
| 555 | |
| 556 | function replaceCanvas(from) { |
| 557 | const out = document.createElement('canvas'); |
| 558 | out.id = from.id; |
| 559 | out.tabIndex = from.tabIndex; |
| 560 | from.parentNode.replaceChild(out, from); |
| 561 | lastScale = 0; |
| 562 | return out; |
| 563 | } |
| 564 | |
| 565 | function animateStatusIndeterminate(ms) { |
| 566 | const i = Math.floor((ms / INDETERMINATE_STATUS_STEP_MS) % 8); |
| 567 | if (statusIndeterminate.children[i].style.borderTopColor === '') { |
| 568 | Array.prototype.slice.call(statusIndeterminate.children).forEach((child) => { |
| 569 | child.style.borderTopColor = ''; |
| 570 | }); |
| 571 | statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf'; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | setStatusMode = function (mode) { |
| 576 | if (statusMode === mode || !initializing) { |
| 577 | return; |
| 578 | } |
| 579 | [statusProgress, statusIndeterminate, statusNotice].forEach((elem) => { |
| 580 | elem.style.display = 'none'; |
| 581 | }); |
| 582 | animationCallbacks = animationCallbacks.filter(function (value) { |
| 583 | return (value !== animateStatusIndeterminate); |
| 584 | }); |
| 585 | switch (mode) { |
| 586 | case 'progress': |
| 587 | statusProgress.style.display = 'block'; |
| 588 | break; |
| 589 | case 'indeterminate': |
| 590 | statusIndeterminate.style.display = 'block'; |
| 591 | animationCallbacks.push(animateStatusIndeterminate); |
| 592 | break; |
| 593 | case 'notice': |
| 594 | statusNotice.style.display = 'block'; |
| 595 | break; |
| 596 | case 'hidden': |
| 597 | break; |
| 598 | default: |
| 599 | throw new Error('Invalid status mode'); |
| 600 | } |
| 601 | statusMode = mode; |
| 602 | }; |
| 603 | |
| 604 | setStatusNotice = function (text) { |
| 605 | while (statusNotice.lastChild) { |
| 606 | statusNotice.removeChild(statusNotice.lastChild); |
| 607 | } |
| 608 | const lines = text.split('\n'); |
| 609 | lines.forEach((line) => { |
| 610 | statusNotice.appendChild(document.createTextNode(line)); |
| 611 | statusNotice.appendChild(document.createElement('br')); |
| 612 | }); |
| 613 | }; |
| 614 | |
| 615 | const gameConfig = { |
| 616 | 'persistentPaths': persistentPaths, |
| 617 | 'unloadAfterInit': false, |
| 618 | 'canvas': gameCanvas, |
| 619 | 'canvasResizePolicy': 1, |
| 620 | 'onExit': function () { |
| 621 | gameCanvas = replaceCanvas(gameCanvas); |
| 622 | setGameTabEnabled(false); |
| 623 | showTab('editor'); |
| 624 | game = null; |
| 625 | }, |
| 626 | }; |
| 627 | |
| 628 | let OnEditorExit = function () { |
| 629 | showTab('loader'); |
| 630 | setLoaderEnabled(true); |
| 631 | }; |
| 632 | function Execute(args) { |
| 633 | const is_editor = args.filter(function (v) { |
| 634 | return v === '--editor' || v === '-e'; |
| 635 | }).length !== 0; |
| 636 | const is_project_manager = args.filter(function (v) { |
| 637 | return v === '--project-manager'; |
| 638 | }).length !== 0; |
| 639 | const is_game = !is_editor && !is_project_manager; |
| 640 | if (video_driver) { |
| 641 | args.push('--rendering-driver', video_driver); |
| 642 | } |
| 643 | |
| 644 | if (is_game) { |
| 645 | if (game) { |
| 646 | console.error('A game is already running. Close it first'); |
| 647 | return; |
| 648 | } |
| 649 | setGameTabEnabled(true); |
| 650 | game = new Engine(gameConfig); |
| 651 | showTab('game'); |
| 652 | game.init().then(function () { |
| 653 | requestAnimationFrame(function () { |
| 654 | game.start({ 'args': args, 'canvas': gameCanvas }).then(function () { |
| 655 | gameCanvas.focus(); |
| 656 | }); |
| 657 | }); |
| 658 | }); |
| 659 | } else { // New editor instances will be run in the same canvas. We want to wait for it to exit. |
| 660 | OnEditorExit = function (code) { |
| 661 | setLoaderEnabled(true); |
| 662 | setTimeout(function () { |
| 663 | editor.init().then(function () { |
| 664 | setLoaderEnabled(false); |
| 665 | OnEditorExit = function () { |
| 666 | showTab('loader'); |
| 667 | setLoaderEnabled(true); |
| 668 | }; |
| 669 | editor.start({ 'args': args, 'persistentDrops': is_project_manager, 'canvas': editorCanvas }); |
| 670 | }); |
| 671 | }, 0); |
| 672 | OnEditorExit = null; |
| 673 | }; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | const clamp = (value, min, max) => Math.min(Math.max(value, min), max); |
| 678 | // We need at least 6 free threads from the pool to start the editor. |
| 679 | // At least 4 more will be reserved for the godot thread pool (3 is the bare minimum with the multithreaded variant of the servers). |
| 680 | const concurrency = clamp(navigator.hardwareConcurrency ?? 1, 12, 24); |
| 681 | const editorConfig = { |
| 682 | 'unloadAfterInit': false, |
| 683 | 'onProgress': function progressFunction(current, total) { |
| 684 | if (total > 0) { |
| 685 | statusProgressInner.style.width = `${(current / total) * 100}%`; |
| 686 | setStatusMode('progress'); |
| 687 | if (current === total) { |
| 688 | // wait for progress bar animation |
| 689 | setTimeout(() => { |
| 690 | setStatusMode('indeterminate'); |
| 691 | }, 100); |
| 692 | } |
| 693 | } else { |
| 694 | setStatusMode('indeterminate'); |
| 695 | } |
| 696 | }, |
| 697 | 'canvas': editorCanvas, |
| 698 | 'canvasResizePolicy': 0, |
| 699 | 'onExit': function () { |
| 700 | editorCanvas = replaceCanvas(editorCanvas); |
| 701 | if (OnEditorExit) { |
| 702 | OnEditorExit(); |
| 703 | } |
| 704 | }, |
| 705 | 'onExecute': Execute, |
| 706 | 'persistentPaths': persistentPaths, |
| 707 | 'emscriptenPoolSize': concurrency, |
| 708 | 'godotPoolSize': Math.floor(concurrency / 3), // Ensures at least 4 threads for the pool (see above). |
| 709 | }; |
| 710 | editor = new Engine(editorConfig); |
| 711 | |
| 712 | function displayFailureNotice(err) { |
| 713 | console.error(err); |
| 714 | if (err instanceof Error) { |
| 715 | setStatusNotice(err.message); |
| 716 | } else if (typeof err === 'string') { |
| 717 | setStatusNotice(err); |
| 718 | } else { |
| 719 | setStatusNotice('An unknown error occurred.'); |
| 720 | } |
| 721 | setStatusMode('notice'); |
| 722 | initializing = false; |
| 723 | } |
| 724 | |
| 725 | if (!Engine.isWebGLAvailable()) { |
| 726 | displayFailureNotice('WebGL not available'); |
| 727 | } else { |
| 728 | setStatusMode('indeterminate'); |
| 729 | editor.init('godot.editor').then(function () { |
| 730 | if (zip) { |
| 731 | editor.copyToFS('/tmp/preload.zip', zip); |
| 732 | } |
| 733 | try { |
| 734 | // Avoid user creating project in the persistent root folder. |
| 735 | editor.copyToFS('/home/web_user/keep', new Uint8Array()); |
| 736 | } catch (e) { |
| 737 | // File exists |
| 738 | } |
| 739 | selectVideoMode(); |
| 740 | showTab('editor'); |
| 741 | setLoaderEnabled(false); |
| 742 | const args = ['--project-manager', '--single-window']; |
| 743 | if (video_driver) { |
| 744 | args.push('--rendering-driver', video_driver); |
| 745 | } |
| 746 | editor.start({ 'args': args, 'persistentDrops': true }).then(function () { |
| 747 | setStatusMode('hidden'); |
| 748 | initializing = false; |
| 749 | }); |
| 750 | }).catch(displayFailureNotice); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | function preloadZip(target) { |
| 755 | return new Promise(function (resolve, reject) { |
| 756 | if (target.files.length > 0) { |
| 757 | target.files[0].arrayBuffer().then(function (data) { |
| 758 | resolve(data); |
| 759 | }); |
| 760 | } else { |
| 761 | resolve(); |
| 762 | } |
| 763 | }); |
| 764 | } |
| 765 | |
| 766 | document.getElementById('startButton').onclick = function () { |
| 767 | preloadZip(document.getElementById('zip-file')).then(function (zip) { |
| 768 | startEditor(zip); |
| 769 | }); |
| 770 | }; |
| 771 | </script> |
| 772 | </body> |
| 773 | </html> |