editor.html 22 KB

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