0.2.0-dev Download ZIP
901 lines ·26.2 KB Raw
| 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/stable/"> |
| 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/assets/share-image.webp"> |
| 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 | <link rel="preload" href="inter-regular.woff2" as="font" crossorigin="anonymous"> |
| 27 | <link rel="preload" href="inter-bold.woff2" as="font" crossorigin="anonymous"> |
| 28 | <title>Godot Engine Web Editor (___GODOT_VERSION___)</title> |
| 29 | <style id="web-editor-style"> |
| 30 | /* Use Inter in the same configuration as used in the editor (e.g. alternate lowercase `l`). */ |
| 31 | @font-face { |
| 32 | font-family: "Inter"; |
| 33 | src: url("inter-regular.woff2"); |
| 34 | font-weight: 400; |
| 35 | font-style: normal; |
| 36 | font-display: swap; |
| 37 | } |
| 38 | |
| 39 | @font-face { |
| 40 | font-family: "Inter"; |
| 41 | src: url("inter-bold.woff2"); |
| 42 | font-weight: 700; |
| 43 | font-style: normal; |
| 44 | font-display: swap; |
| 45 | } |
| 46 | |
| 47 | html, |
| 48 | body, |
| 49 | button, |
| 50 | input { |
| 51 | /* Apply a modern sans-serif font stack in case the Inter font fails to load. */ |
| 52 | font-family: "Inter", 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"; |
| 53 | font-size: 14px; |
| 54 | font-feature-settings: "calt" 0, "ss04" 1, "tnum" 1; |
| 55 | } |
| 56 | |
| 57 | *:focus-visible { |
| 58 | /* More visible outline for better keyboard navigation. */ |
| 59 | outline: 0.1875rem solid #538dda; |
| 60 | /* Make the outline always appear above other elements. */ |
| 61 | /* Otherwise, one of its sides can be hidden by tabs in the Download and More layouts. */ |
| 62 | position: relative; |
| 63 | } |
| 64 | |
| 65 | body { |
| 66 | touch-action: none; |
| 67 | margin: 0; |
| 68 | border: 0 none; |
| 69 | padding: 0; |
| 70 | font-size: 14px; |
| 71 | text-align: center; |
| 72 | background-color: #262626; |
| 73 | overflow: hidden; |
| 74 | } |
| 75 | |
| 76 | iframe { |
| 77 | margin: 0; |
| 78 | border: none; |
| 79 | padding: 0; |
| 80 | background-color: #262626; |
| 81 | overflow: hidden; |
| 82 | } |
| 83 | |
| 84 | h2 { |
| 85 | font-size: 21px; |
| 86 | } |
| 87 | |
| 88 | a { |
| 89 | color: hsl(205, 100%, 75%); |
| 90 | text-decoration-color: hsla(205, 100%, 75%, 0.3); |
| 91 | text-decoration-thickness: 0.125rem; |
| 92 | } |
| 93 | |
| 94 | a:hover { |
| 95 | filter: brightness(117.5%); |
| 96 | } |
| 97 | |
| 98 | a:active { |
| 99 | filter: brightness(82.5%); |
| 100 | } |
| 101 | |
| 102 | .welcome-modal { |
| 103 | display: none; |
| 104 | position: fixed; |
| 105 | z-index: 1; |
| 106 | left: 0; |
| 107 | top: 0; |
| 108 | width: 100%; |
| 109 | height: 100%; |
| 110 | overflow: auto; |
| 111 | background-color: hsla(0, 0%, 0%, 0.5); |
| 112 | text-align: left; |
| 113 | } |
| 114 | |
| 115 | .welcome-modal-title { |
| 116 | text-align: center; |
| 117 | } |
| 118 | |
| 119 | .welcome-modal-content { |
| 120 | background-color: #262626; |
| 121 | box-shadow: 0 0.25rem 0.25rem hsla(0, 0%, 0%, 0.5); |
| 122 | line-height: 1.5; |
| 123 | max-width: 38rem; |
| 124 | margin: 4rem auto 0 auto; |
| 125 | color: white; |
| 126 | border-radius: 0.5rem; |
| 127 | padding: 0.125rem 1.25rem 1.25rem 1.25rem; |
| 128 | } |
| 129 | |
| 130 | #tabs-buttons { |
| 131 | /* Remove spacing between items. */ |
| 132 | font-size: 0; |
| 133 | |
| 134 | /* Match the default background color of the editor window for a seamless appearance. */ |
| 135 | background-color: #141414; |
| 136 | } |
| 137 | |
| 138 | #tab-game { |
| 139 | /* Match the default background color of the editor window for a seamless appearance. */ |
| 140 | background-color: #141414; |
| 141 | /* Make the background span the entire page height. */ |
| 142 | min-height: 100vh; |
| 143 | } |
| 144 | |
| 145 | /* Don't show distracting focus outlines for the main tabs' contents. */ |
| 146 | .godot { |
| 147 | outline: none; |
| 148 | color: #d0d0d0; |
| 149 | background-color: #1b1b1b; |
| 150 | background-image: linear-gradient(to bottom, #403e48, #35333c); |
| 151 | border: 1px solid #484848; |
| 152 | box-shadow: 0 0 1px 1px #141414; |
| 153 | } |
| 154 | |
| 155 | #tab-status { |
| 156 | position: absolute; |
| 157 | top: 0; |
| 158 | left: 0; |
| 159 | right: 0; |
| 160 | bottom: 0; |
| 161 | display: flex; |
| 162 | flex-direction: column; |
| 163 | justify-content: center; |
| 164 | align-items: center; |
| 165 | } |
| 166 | |
| 167 | #tab-editor iframe:focus-visible, |
| 168 | #tab-game iframe:focus-visible, |
| 169 | #godot-canvas:focus-visible { |
| 170 | outline: none; |
| 171 | border: none; |
| 172 | box-shadow: none; |
| 173 | } |
| 174 | |
| 175 | .btn { |
| 176 | appearance: none; |
| 177 | color: #d0d0d0; |
| 178 | background-color: #424242; |
| 179 | border: 1px solid #484848; |
| 180 | /* Vertically center button text. */ |
| 181 | padding: 0.4375rem 0.5625rem 0.5rem; |
| 182 | margin: 0 0.5rem; |
| 183 | border-radius: 0.25rem; |
| 184 | } |
| 185 | |
| 186 | .btn:not(:disabled):hover { |
| 187 | color: #e4e4e4; |
| 188 | background-color: #4d4d4d; |
| 189 | border-color: #535353; |
| 190 | } |
| 191 | |
| 192 | .btn:active { |
| 193 | color: #e5e5e5; |
| 194 | background-color: #505050; |
| 195 | border-color: #565656; |
| 196 | } |
| 197 | |
| 198 | .btn:disabled { |
| 199 | color: #7f7f7f; |
| 200 | background-color: #3a3a3a; |
| 201 | border-color: #3a3a3a; |
| 202 | } |
| 203 | |
| 204 | .btn.tab-btn, |
| 205 | .btn.close-btn { |
| 206 | /* Match tab colors from the default editor theme. */ |
| 207 | background-color: transparent; |
| 208 | border-color: transparent; |
| 209 | } |
| 210 | |
| 211 | .btn.tab-btn:not(:disabled):hover, |
| 212 | .btn.close-btn:not(:disabled):hover { |
| 213 | background-color: #212121; |
| 214 | border-color: #212121; |
| 215 | } |
| 216 | |
| 217 | .btn.tab-btn { |
| 218 | /* Round top corners only. */ |
| 219 | border-radius: 0.25rem 0.25rem 0 0; |
| 220 | } |
| 221 | |
| 222 | .btn.next-to-close-btn { |
| 223 | /* Round top-left corner only. */ |
| 224 | border-radius: 0.25rem 0 0 0; |
| 225 | } |
| 226 | |
| 227 | .btn.close-btn { |
| 228 | /* Round top-right corner only. */ |
| 229 | border-radius: 0 0.25rem 0 0; |
| 230 | margin-left: -0.75rem; |
| 231 | font-weight: 700; |
| 232 | } |
| 233 | |
| 234 | /* Status display */ |
| 235 | |
| 236 | #status-progress { |
| 237 | width: 366px; |
| 238 | height: 7px; |
| 239 | background-color: #38363A; |
| 240 | border: 1px solid #444246; |
| 241 | padding: 1px; |
| 242 | box-shadow: 0 0 2px 1px #1B1C22; |
| 243 | border-radius: 2px; |
| 244 | visibility: visible; |
| 245 | } |
| 246 | |
| 247 | @media only screen and (orientation:portrait) { |
| 248 | #status-progress { |
| 249 | width: 61.8%; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | #status-progress-inner { |
| 254 | height: 100%; |
| 255 | width: 0; |
| 256 | box-sizing: border-box; |
| 257 | transition: width 0.5s linear; |
| 258 | background-color: #478cbf; |
| 259 | border: 1px solid #222223; |
| 260 | box-shadow: 0 0 1px 1px #27282E; |
| 261 | border-radius: 3px; |
| 262 | } |
| 263 | |
| 264 | #status-indeterminate { |
| 265 | visibility: visible; |
| 266 | position: relative; |
| 267 | } |
| 268 | |
| 269 | #status-indeterminate > div { |
| 270 | width: 4.5px; |
| 271 | height: 0; |
| 272 | border-style: solid; |
| 273 | border-width: 9px 3px 0 3px; |
| 274 | border-color: #2b2b2b transparent transparent transparent; |
| 275 | transform-origin: center 21px; |
| 276 | position: absolute; |
| 277 | } |
| 278 | |
| 279 | #status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); } |
| 280 | #status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); } |
| 281 | #status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); } |
| 282 | #status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); } |
| 283 | #status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); } |
| 284 | #status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); } |
| 285 | #status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); } |
| 286 | #status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); } |
| 287 | |
| 288 | #status-notice { |
| 289 | margin: 0 100px; |
| 290 | line-height: 1.3; |
| 291 | visibility: visible; |
| 292 | padding: 4px 6px; |
| 293 | } |
| 294 | </style> |
| 295 | </head> |
| 296 | <body> |
| 297 | <div |
| 298 | id="welcome-modal" |
| 299 | class="welcome-modal" |
| 300 | role="dialog" |
| 301 | aria-labelledby="welcome-modal-title" |
| 302 | aria-describedby="welcome-modal-description" |
| 303 | onclick="if (event.target === this) closeWelcomeModal()" |
| 304 | > |
| 305 | <div class="welcome-modal-content"> |
| 306 | <h2 id="welcome-modal-title" class="welcome-modal-title">Important - Please read before continuing</h2> |
| 307 | <div id="welcome-modal-description"> |
| 308 | <p> |
| 309 | The Godot Web Editor has some limitations compared to the native version.<br> |
| 310 | Its main focus is education and experimentation; |
| 311 | <strong>it is not recommended for production</strong>. |
| 312 | </p> |
| 313 | <p> |
| 314 | For a more optimal experience, <a |
| 315 | href="https://godotengine.org/download/" |
| 316 | target="_blank" |
| 317 | rel="noopener" |
| 318 | >download</a> the native Godot Editor. |
| 319 | </p> |
| 320 | <p> |
| 321 | Refer to the |
| 322 | <a |
| 323 | href="https://docs.godotengine.org/en/stable/tutorials/editor/using_the_web_editor.html" |
| 324 | target="_blank" |
| 325 | rel="noopener" |
| 326 | >Web editor documentation</a> for usage instructions and limitations. |
| 327 | </p> |
| 328 | </div> |
| 329 | <div id="welcome-modal-missing-description" style="display: none"> |
| 330 | <p> |
| 331 | <strong>The following features required by the Godot Web Editor are missing:</strong> |
| 332 | </p> |
| 333 | <ul id="welcome-modal-missing-list"> |
| 334 | </ul> |
| 335 | <p> |
| 336 | If you are self-hosting the web editor, refer to |
| 337 | <a |
| 338 | href="https://docs.godotengine.org/en/stable/tutorials/export/exporting_for_web.html" |
| 339 | target="_blank" |
| 340 | rel="noopener" |
| 341 | >Exporting for the Web</a> for more information. |
| 342 | </p> |
| 343 | </div> |
| 344 | <div style="text-align: center;"> |
| 345 | <label> |
| 346 | <input id="welcome-modal-dont-show-again-check" type="checkbox"> |
| 347 | Don't Show Again |
| 348 | </label> |
| 349 | </div> |
| 350 | <div style="text-align: center"> |
| 351 | <button id="welcome-modal-dismiss" class="btn" type="button" onclick="closeWelcomeModal()" style="margin-top: 1rem"> |
| 352 | OK |
| 353 | </button> |
| 354 | </div> |
| 355 | </div> |
| 356 | </div> |
| 357 | <div id="tabs-buttons"> |
| 358 | <button id="btn-tab-editor" class="btn tab-btn next-to-close-btn" disabled="disabled">Editor</button> |
| 359 | <button id="btn-close-editor" class="btn close-btn" disabled="disabled">×</button> |
| 360 | <button id="btn-tab-game" class="btn tab-btn next-to-close-btn" disabled="disabled">Game</button> |
| 361 | <button id="btn-close-game" class="btn close-btn" disabled="disabled">×</button> |
| 362 | <button id="btn-tab-update" class="btn tab-btn" style="display: none;">Update</button> |
| 363 | </div> |
| 364 | <div id="tabs"> |
| 365 | <div id="tab-loader"> |
| 366 | <div style="color: #e0e0e0;" id="persistence"> |
| 367 | <br> |
| 368 | <img src="logo.svg" alt="Godot Engine logo" width="1024" height="414" style="width: auto; height: auto; max-width: min(85%, 50vh); max-height: 200px"> |
| 369 | <br> |
| 370 | ___GODOT_VERSION___ - <a href="/releases/">Change version</a> |
| 371 | <br> |
| 372 | <br> |
| 373 | <button id="btn-start-editor" class="btn" style="margin-top: 2rem; margin-bottom: 3rem; font-weight: 700">Start Godot Editor</button> |
| 374 | <br> |
| 375 | <button class="btn" onclick="clearPersistence()" style="margin-bottom: 1.5rem">Clear Persistent Data</button> |
| 376 | <br> |
| 377 | <a href="https://docs.godotengine.org/en/stable/tutorials/editor/using_the_web_editor.html">Web editor documentation</a> |
| 378 | </div> |
| 379 | </div> |
| 380 | <div id="tab-editor" style="display: none;"> |
| 381 | <iframe id="editor-iframe" tabindex="1"></iframe> |
| 382 | </div> |
| 383 | <div id="tab-game" style="display: none;"> |
| 384 | <iframe id="game-iframe" tabindex="2"></iframe> |
| 385 | </div> |
| 386 | <div id="tab-status" style="display: none;"> |
| 387 | <div id="status-progress" style="display: none;" oncontextmenu="event.preventDefault();"> |
| 388 | <div id="status-progress-inner"></div> |
| 389 | </div> |
| 390 | <div id="status-indeterminate" style="display: none;" oncontextmenu="event.preventDefault();"> |
| 391 | <div></div> |
| 392 | <div></div> |
| 393 | <div></div> |
| 394 | <div></div> |
| 395 | <div></div> |
| 396 | <div></div> |
| 397 | <div></div> |
| 398 | <div></div> |
| 399 | </div> |
| 400 | <div id="status-notice" class="godot" style="display: none;"></div> |
| 401 | </div> |
| 402 | </div> |
| 403 | <script> |
| 404 | window.addEventListener('load', () => { |
| 405 | function notifyUpdate(sw) { |
| 406 | const btn = document.getElementById('btn-tab-update'); |
| 407 | btn.onclick = function () { |
| 408 | if (!window.confirm('Are you sure you want to update?\nClicking "OK" will reload all active instances!')) { |
| 409 | return; |
| 410 | } |
| 411 | sw.postMessage('update'); |
| 412 | btn.innerHTML = 'Updating...'; |
| 413 | btn.disabled = true; |
| 414 | }; |
| 415 | btn.style.display = ''; |
| 416 | } |
| 417 | if ('serviceWorker' in navigator) { |
| 418 | try { |
| 419 | navigator.serviceWorker.register('service.worker.js').then(function (reg) { |
| 420 | if (reg.waiting) { |
| 421 | notifyUpdate(reg.waiting); |
| 422 | } |
| 423 | reg.addEventListener('updatefound', function () { |
| 424 | const update = reg.installing; |
| 425 | update.addEventListener('statechange', function () { |
| 426 | if (update.state === 'installed') { |
| 427 | // It's a new install, claim and perform aggressive caching. |
| 428 | if (!reg.active) { |
| 429 | update.postMessage('claim'); |
| 430 | } else { |
| 431 | notifyUpdate(update); |
| 432 | } |
| 433 | } |
| 434 | }); |
| 435 | }); |
| 436 | }); |
| 437 | } catch (e) { |
| 438 | console.error('Error while registering service worker:', e); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | const missing = Engine.getMissingFeatures({ |
| 443 | threads: ___GODOT_THREADS_ENABLED___, |
| 444 | }); |
| 445 | if (missing.length) { |
| 446 | // Display error dialog as threading support is required for the editor. |
| 447 | document.getElementById('btn-start-editor').disabled = 'disabled'; |
| 448 | document.getElementById('welcome-modal-description').style.display = 'none'; |
| 449 | document.getElementById('welcome-modal-missing-description').style.display = 'block'; |
| 450 | document.getElementById('welcome-modal-dismiss').style.display = 'none'; |
| 451 | const list = document.getElementById('welcome-modal-missing-list'); |
| 452 | for (let i = 0; i < missing.length; i++) { |
| 453 | const node = document.createElement('li'); |
| 454 | node.innerText = missing[i]; |
| 455 | list.appendChild(node); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | if (missing.length || localStorage.getItem('welcomeModalDismissed') !== 'true') { |
| 460 | document.getElementById('welcome-modal').style.display = 'block'; |
| 461 | document.getElementById('welcome-modal-dismiss').focus(); |
| 462 | } |
| 463 | }); |
| 464 | |
| 465 | function closeWelcomeModal() { // eslint-disable-line no-unused-vars |
| 466 | document.getElementById('welcome-modal').style.display = 'none'; |
| 467 | const dontShowAgain = document.getElementById('welcome-modal-dont-show-again-check').checked; |
| 468 | if (dontShowAgain) { |
| 469 | localStorage.setItem('welcomeModalDismissed', 'true'); |
| 470 | } |
| 471 | } |
| 472 | </script> |
| 473 | <script src="godot.editor.js"></script> |
| 474 | <script> |
| 475 | const fileSizes = ___GODOT_EDITOR_FILESIZES___; |
| 476 | |
| 477 | function clearPersistence() { // eslint-disable-line no-unused-vars |
| 478 | function deleteDB(path) { |
| 479 | return new Promise(function (resolve, reject) { |
| 480 | const req = indexedDB.deleteDatabase(path); |
| 481 | req.onsuccess = function () { |
| 482 | resolve(); |
| 483 | }; |
| 484 | req.onerror = function (err) { |
| 485 | reject(err); |
| 486 | }; |
| 487 | req.onblocked = function (err) { |
| 488 | reject(err); |
| 489 | }; |
| 490 | }); |
| 491 | } |
| 492 | 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!')) { |
| 493 | return; |
| 494 | } |
| 495 | Promise.all([ |
| 496 | deleteDB('/home/web_user'), |
| 497 | ]).then(function (results) { |
| 498 | localStorage.setItem('welcomeModalDismissed', 'false'); |
| 499 | alert('Done.'); |
| 500 | }).catch(function (err) { |
| 501 | alert('Error deleting local files. Please retry after reloading the page.'); |
| 502 | }); |
| 503 | } |
| 504 | |
| 505 | function LoadStatus(document) { |
| 506 | const INDETERMINATE_STATUS_STEP_MS = 100; |
| 507 | const statusTab = document.getElementById('tab-status'); |
| 508 | const statusProgress = document.getElementById('status-progress'); |
| 509 | const statusProgressInner = document.getElementById('status-progress-inner'); |
| 510 | const statusIndeterminate = document.getElementById('status-indeterminate'); |
| 511 | const statusNotice = document.getElementById('status-notice'); |
| 512 | |
| 513 | let statusMode = 'hidden'; |
| 514 | |
| 515 | let animationCallbacks = []; |
| 516 | |
| 517 | function animateStatusIndeterminate(ms) { |
| 518 | const i = Math.floor((ms / INDETERMINATE_STATUS_STEP_MS) % 8); |
| 519 | if (statusIndeterminate.children[i].style.borderTopColor === '') { |
| 520 | Array.prototype.slice.call(statusIndeterminate.children).forEach((child) => { |
| 521 | child.style.borderTopColor = ''; |
| 522 | }); |
| 523 | statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf'; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | function setStatusMode(mode) { |
| 528 | if (statusMode === mode) { |
| 529 | return; |
| 530 | } |
| 531 | [statusProgress, statusIndeterminate, statusNotice].forEach((elem) => { |
| 532 | elem.style.display = 'none'; |
| 533 | }); |
| 534 | animationCallbacks = animationCallbacks.filter(function (value) { |
| 535 | return (value !== animateStatusIndeterminate); |
| 536 | }); |
| 537 | let display = ''; |
| 538 | switch (mode) { |
| 539 | case 'progress': |
| 540 | statusProgress.style.display = 'block'; |
| 541 | break; |
| 542 | case 'indeterminate': |
| 543 | statusIndeterminate.style.display = 'block'; |
| 544 | animationCallbacks.push(animateStatusIndeterminate); |
| 545 | break; |
| 546 | case 'notice': |
| 547 | statusNotice.style.display = 'block'; |
| 548 | break; |
| 549 | case 'hidden': |
| 550 | display = 'none'; |
| 551 | break; |
| 552 | default: |
| 553 | throw new Error('Invalid status mode'); |
| 554 | } |
| 555 | statusTab.style.display = display; |
| 556 | statusMode = mode; |
| 557 | }; |
| 558 | |
| 559 | function setStatusNotice(text) { |
| 560 | while (statusNotice.lastChild) { |
| 561 | statusNotice.removeChild(statusNotice.lastChild); |
| 562 | } |
| 563 | const lines = text.split('\n'); |
| 564 | lines.forEach((line) => { |
| 565 | statusNotice.appendChild(document.createTextNode(line)); |
| 566 | statusNotice.appendChild(document.createElement('br')); |
| 567 | }); |
| 568 | }; |
| 569 | |
| 570 | function updateProgress(active, progress) { |
| 571 | if (statusMode === 'notice') { |
| 572 | return; |
| 573 | } |
| 574 | if (active) { |
| 575 | setStatusMode('hidden'); |
| 576 | return; |
| 577 | } |
| 578 | const [current, total] = progress; |
| 579 | if (total > 0 && current < total) { |
| 580 | statusProgressInner.style.width = `${(current / total) * 100}%`; |
| 581 | setStatusMode('progress'); |
| 582 | } else { |
| 583 | setStatusMode('indeterminate'); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | function displayFailureNotice(err) { |
| 588 | console.error(err); |
| 589 | if (err instanceof Error) { |
| 590 | setStatusNotice(err.message); |
| 591 | } else if (typeof err === 'string') { |
| 592 | setStatusNotice(err); |
| 593 | } else { |
| 594 | setStatusNotice('An unknown error occurred.'); |
| 595 | } |
| 596 | setStatusMode('notice'); |
| 597 | } |
| 598 | |
| 599 | setStatusMode('indeterminate'); |
| 600 | let updating = false; |
| 601 | return { |
| 602 | update: (instance) => { |
| 603 | if (updating) { |
| 604 | return; |
| 605 | } |
| 606 | updating = true; |
| 607 | requestAnimationFrame(() => { |
| 608 | updating = false; |
| 609 | updateProgress(instance.active, instance.progress); |
| 610 | }); |
| 611 | }, |
| 612 | animate: (time) => { |
| 613 | animationCallbacks.forEach((callback) => callback(time)); |
| 614 | }, |
| 615 | setNotice: setStatusNotice, |
| 616 | setError: displayFailureNotice, |
| 617 | }; |
| 618 | }; |
| 619 | |
| 620 | (function () { |
| 621 | // EngineIFrame initialization (+ custom state). |
| 622 | const iframeStyle = document.getElementById('web-editor-style'); |
| 623 | const tabStatus = document.getElementById('tab-status'); |
| 624 | const WrappedIFrame = (name) => { |
| 625 | let loadStatus = null; |
| 626 | const tab = document.getElementById(`tab-${name}`); |
| 627 | const iframeOnload = (iframe) => { |
| 628 | const title = iframe.contentDocument.getElementsByTagName('title')[0]; |
| 629 | const observer = new MutationObserver(function () { |
| 630 | if (tab.style.display === 'none') { |
| 631 | return; |
| 632 | } |
| 633 | document.title = iframe.contentDocument.title; |
| 634 | }); |
| 635 | observer.observe(title, { childList: true }); |
| 636 | iframe.contentDocument.body.appendChild(iframe.contentDocument.importNode(iframeStyle, true)); |
| 637 | iframe.contentDocument.body.appendChild(iframe.contentDocument.importNode(tabStatus, true)); |
| 638 | loadStatus = new LoadStatus(iframe.contentDocument); |
| 639 | }; |
| 640 | const state = new EngineIFrame('godot.editor', document.getElementById(`${name}-iframe`), iframeOnload); |
| 641 | state.progress = [0, 0]; |
| 642 | state.active = false; |
| 643 | state.updateStatus = function () { |
| 644 | loadStatus.update(state); |
| 645 | }; |
| 646 | state.setError = function (error) { |
| 647 | loadStatus.setError(error); |
| 648 | }; |
| 649 | const reset = state.reset; |
| 650 | state.reset = function () { |
| 651 | state.progress = [0, 0]; |
| 652 | state.active = false; |
| 653 | return reset.apply(state); |
| 654 | }; |
| 655 | state.animate = function (time) { |
| 656 | if (loadStatus) { |
| 657 | loadStatus.animate(time); |
| 658 | } |
| 659 | }; |
| 660 | return state; |
| 661 | }; |
| 662 | const editorState = WrappedIFrame('editor'); |
| 663 | const gameState = WrappedIFrame('game'); |
| 664 | |
| 665 | // IFrame size adjuster. |
| 666 | const headerDiv = document.getElementById('tabs-buttons'); |
| 667 | let lastWidth = 0; |
| 668 | let lastHeight = 0; |
| 669 | const instances = [editorState, gameState]; |
| 670 | function adjustIframeDimensions(time) { |
| 671 | const headerHeight = headerDiv.offsetHeight + 1; |
| 672 | const width = window.innerWidth; |
| 673 | const height = window.innerHeight - headerHeight; |
| 674 | if (lastWidth !== width || lastHeight !== height) { |
| 675 | instances.forEach((e) => { |
| 676 | e.iframe.style.width = `${width}px`; |
| 677 | e.iframe.style.height = `${height}px`; |
| 678 | }); |
| 679 | lastWidth = width; |
| 680 | lastHeight = height; |
| 681 | } |
| 682 | editorState.animate(time); |
| 683 | gameState.animate(time); |
| 684 | requestAnimationFrame(adjustIframeDimensions); |
| 685 | } |
| 686 | requestAnimationFrame(adjustIframeDimensions); |
| 687 | |
| 688 | // Tabs |
| 689 | const tabs = [ |
| 690 | document.getElementById('tab-loader'), |
| 691 | document.getElementById('tab-editor'), |
| 692 | document.getElementById('tab-game'), |
| 693 | ]; |
| 694 | const loaderTitle = document.title; |
| 695 | function showTab(name) { |
| 696 | tabs.forEach(function (elem) { |
| 697 | elem.style.display = elem.id === `tab-${name}` ? 'block' : 'none'; |
| 698 | }); |
| 699 | if (name === 'editor' || name === 'game') { |
| 700 | const instance = name === 'game' ? gameState : editorState; |
| 701 | const title = instance.iframe.contentDocument.title; |
| 702 | if (title) { |
| 703 | document.title = title; |
| 704 | } |
| 705 | instance.focus(); |
| 706 | } else { |
| 707 | document.title = loaderTitle; |
| 708 | } |
| 709 | } |
| 710 | function setButtonEnabled(id, enabled) { |
| 711 | document.getElementById(id).disabled = enabled ? '' : 'disabled'; |
| 712 | } |
| 713 | function setEditorTabEnabled(enabled) { |
| 714 | setButtonEnabled('btn-tab-editor', enabled); |
| 715 | setButtonEnabled('btn-close-editor', enabled); |
| 716 | } |
| 717 | function setGameTabEnabled(enabled) { |
| 718 | setButtonEnabled('btn-tab-game', enabled); |
| 719 | setButtonEnabled('btn-close-game', enabled); |
| 720 | } |
| 721 | |
| 722 | // EngineIFrame Controllers. |
| 723 | const persistentPaths = ['/home/web_user']; |
| 724 | |
| 725 | function runGame(gameConfig) { |
| 726 | let session = null; |
| 727 | const onmessage = (event) => { |
| 728 | const cmd = event.data.cmd || ''; |
| 729 | if (event.data.pid !== gameState.pid) { |
| 730 | console.error('Invalid event', event); |
| 731 | return; |
| 732 | } |
| 733 | if (cmd == 'started') { |
| 734 | gameState.active = true; |
| 735 | gameState.updateStatus(); |
| 736 | editorState.addSession(session); |
| 737 | showTab('game'); |
| 738 | } else if (cmd == 'error') { |
| 739 | gameState.setError(event.data.msg); |
| 740 | } else if (cmd == 'progress') { |
| 741 | const [current, total] = event.data.msg; |
| 742 | gameState.progress = [current, total]; |
| 743 | gameState.updateStatus(); |
| 744 | } else if (cmd == 'stopped') { |
| 745 | gameState.reset(); |
| 746 | setGameTabEnabled(false); |
| 747 | showTab('editor'); |
| 748 | } else if (cmd == 'execute' || cmd == 'terminate') { |
| 749 | // Not implemented. |
| 750 | } else { |
| 751 | console.error('Invalid event', event); |
| 752 | } |
| 753 | }; |
| 754 | gameState.reset().then(() => { |
| 755 | session = gameState.start(gameConfig, onmessage, true); |
| 756 | }); |
| 757 | setGameTabEnabled(true); |
| 758 | showTab('game'); |
| 759 | } |
| 760 | |
| 761 | function runEditor(editorArgs) { |
| 762 | let OnEditorExit = function () { |
| 763 | gameState.reset(); |
| 764 | setGameTabEnabled(false); |
| 765 | editorState.reset(); |
| 766 | setEditorTabEnabled(false); |
| 767 | showTab('loader'); |
| 768 | }; |
| 769 | const onmessage = (event) => { |
| 770 | const cmd = event.data.cmd || ''; |
| 771 | if (editorState.pid !== event.data.pid) { |
| 772 | console.error('Invalid event', event); |
| 773 | return; |
| 774 | } |
| 775 | if (cmd == 'started') { |
| 776 | editorState.active = true; |
| 777 | editorState.updateStatus(); |
| 778 | showTab('editor'); |
| 779 | } else if (cmd == 'error') { |
| 780 | editorState.setError(event.data.msg); |
| 781 | } else if (cmd == 'stopped') { |
| 782 | OnEditorExit(); |
| 783 | } else if (cmd == 'progress') { |
| 784 | const [current, total] = event.data.msg; |
| 785 | editorState.progress = [current, total]; |
| 786 | editorState.updateStatus(); |
| 787 | } else if (cmd == 'execute') { |
| 788 | const [newPid, path, args] = event.data.msg; // eslint-disable-line no-unused-vars |
| 789 | if (!Array.isArray(args)) { |
| 790 | console.error('Invalid event', event); |
| 791 | return; |
| 792 | } |
| 793 | const is_editor = args.findIndex((v) => (v === '--editor' || v === '-e')) !== -1; |
| 794 | const is_project_manager = args.findIndex((v) => v === '--project-manager') !== -1; |
| 795 | const is_game = !is_editor && !is_project_manager; |
| 796 | if (is_game) { |
| 797 | const gameConfig = { |
| 798 | 'pid': newPid, |
| 799 | 'persistentPaths': persistentPaths, |
| 800 | 'unloadAfterInit': true, |
| 801 | 'canvasResizePolicy': 2, |
| 802 | 'fileSizes': fileSizes, |
| 803 | 'args': args, |
| 804 | }; |
| 805 | runGame(gameConfig); |
| 806 | } else { |
| 807 | OnEditorExit = function () { |
| 808 | runEditor(args); |
| 809 | }; |
| 810 | } |
| 811 | } else if (cmd == 'terminate') { |
| 812 | if (gameState.pid !== event.data.msg) { |
| 813 | return; |
| 814 | } |
| 815 | gameState.reset(); |
| 816 | setGameTabEnabled(false); |
| 817 | showTab('editor'); |
| 818 | } else { |
| 819 | console.error('Invalid event', event); |
| 820 | } |
| 821 | }; |
| 822 | const clamp = (value, min, max) => Math.min(Math.max(value, min), max); |
| 823 | // We need at least 6 free threads from the pool to start the editor. |
| 824 | // At least 4 more will be reserved for the godot thread pool (3 is the bare minimum with the multithreaded variant of the servers). |
| 825 | const concurrency = clamp(navigator.hardwareConcurrency ?? 1, 12, 24); |
| 826 | const pid = Math.round(Math.random() * (1 << 30)); |
| 827 | const editorConfig = { |
| 828 | 'pid': pid, |
| 829 | 'persistentPaths': persistentPaths, |
| 830 | 'unloadAfterInit': true, |
| 831 | 'canvasResizePolicy': 2, |
| 832 | 'args': editorArgs, |
| 833 | 'emscriptenPoolSize': concurrency, |
| 834 | 'persistentDrops': editorArgs.findIndex((v) => v == '--project-manager') !== -1, |
| 835 | 'godotPoolSize': Math.floor(concurrency / 3), // Ensures at least 4 threads for the pool (see above). |
| 836 | 'fileSizes': fileSizes, |
| 837 | }; |
| 838 | gameState.reset(); |
| 839 | setGameTabEnabled(false); |
| 840 | editorState.reset().then(() => editorState.start(editorConfig, onmessage)); |
| 841 | setEditorTabEnabled(true); |
| 842 | showTab('editor'); |
| 843 | } |
| 844 | |
| 845 | // Button handlers |
| 846 | const buttons = { |
| 847 | start: document.getElementById('btn-start-editor'), |
| 848 | editorShow: document.getElementById('btn-tab-editor'), |
| 849 | editorClose: document.getElementById('btn-close-editor'), |
| 850 | gameShow: document.getElementById('btn-tab-game'), |
| 851 | gameClose: document.getElementById('btn-close-game'), |
| 852 | }; |
| 853 | buttons.start.onclick = function () { |
| 854 | if (!Engine.isWebGLAvailable()) { |
| 855 | setEditorTabEnabled(true); |
| 856 | showTab('editor'); |
| 857 | editorState.setError('WebGL not available'); |
| 858 | } else { |
| 859 | runEditor(['--project-manager', '--single-window']); |
| 860 | } |
| 861 | }; |
| 862 | function closeGame(force) { |
| 863 | if (force && !window.confirm('Are you sure you want to forcibly close the game?')) { |
| 864 | return; |
| 865 | } |
| 866 | if (gameState.active && !force) { |
| 867 | showTab('game'); |
| 868 | gameState.stop(); |
| 869 | } else { |
| 870 | gameState.reset(); |
| 871 | setGameTabEnabled(false); |
| 872 | if (editorState.active) { |
| 873 | showTab('editor'); |
| 874 | } |
| 875 | } |
| 876 | } |
| 877 | function closeEditor(force) { |
| 878 | if (force && !window.confirm('Are you sure you want to forcibly close the editor?\nClicking "OK" may result in data loss!')) { |
| 879 | return; |
| 880 | } |
| 881 | if (editorState.active && !force) { |
| 882 | showTab('editor'); |
| 883 | editorState.stop(); |
| 884 | } else { |
| 885 | gameState.reset(); |
| 886 | setGameTabEnabled(false); |
| 887 | editorState.reset(); |
| 888 | setEditorTabEnabled(false); |
| 889 | showTab('loader'); |
| 890 | } |
| 891 | } |
| 892 | buttons.editorShow.onclick = () => showTab('editor'); |
| 893 | buttons.editorClose.onclick = () => closeEditor(false); |
| 894 | buttons.editorClose.ondblclick = () => closeEditor(true); |
| 895 | buttons.gameShow.onclick = () => showTab('game'); |
| 896 | buttons.gameClose.onclick = () => closeGame(false); |
| 897 | buttons.gameClose.ondblclick = () => closeGame(true); |
| 898 | })(); |
| 899 | </script> |
| 900 | </body> |
| 901 | </html> |