editor.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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. if (missing.length) {
  361. // Display error dialog as threading support is required for the editor.
  362. document.getElementById('startButton').disabled = 'disabled';
  363. document.getElementById('welcome-modal-description').style.display = 'none';
  364. document.getElementById('welcome-modal-missing-description').style.display = 'block';
  365. document.getElementById('welcome-modal-dismiss').style.display = 'none';
  366. const list = document.getElementById('welcome-modal-missing-list');
  367. for (let i = 0; i < missing.length; i++) {
  368. const node = document.createElement('li');
  369. node.innerText = missing[i];
  370. list.appendChild(node);
  371. }
  372. }
  373. if (missing.length || localStorage.getItem('welcomeModalDismissed') !== 'true') {
  374. document.getElementById('welcome-modal').style.display = 'block';
  375. document.getElementById('welcome-modal-dismiss').focus();
  376. }
  377. });
  378. function closeWelcomeModal(dontShowAgain) { // eslint-disable-line no-unused-vars
  379. document.getElementById('welcome-modal').style.display = 'none';
  380. if (dontShowAgain) {
  381. localStorage.setItem('welcomeModalDismissed', 'true');
  382. }
  383. }
  384. </script>
  385. <script src="godot.editor.js"></script>
  386. <script>
  387. let editor = null;
  388. let game = null;
  389. let setStatusMode;
  390. let setStatusNotice;
  391. let video_driver = '';
  392. function clearPersistence() { // eslint-disable-line no-unused-vars
  393. function deleteDB(path) {
  394. return new Promise(function (resolve, reject) {
  395. const req = indexedDB.deleteDatabase(path);
  396. req.onsuccess = function () {
  397. resolve();
  398. };
  399. req.onerror = function (err) {
  400. reject(err);
  401. };
  402. req.onblocked = function (err) {
  403. reject(err);
  404. };
  405. });
  406. }
  407. 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!')) {
  408. return;
  409. }
  410. Promise.all([
  411. deleteDB('/home/web_user'),
  412. ]).then(function (results) {
  413. alert('Done.');
  414. }).catch(function (err) {
  415. alert('Error deleting local files. Please retry after reloading the page.');
  416. });
  417. }
  418. function selectVideoMode() {
  419. const select = document.getElementById('videoMode');
  420. video_driver = select.selectedOptions[0].value;
  421. }
  422. const tabs = [
  423. document.getElementById('tab-loader'),
  424. document.getElementById('tab-editor'),
  425. document.getElementById('tab-game'),
  426. ];
  427. function showTab(name) {
  428. tabs.forEach(function (elem) {
  429. if (elem.id === `tab-${name}`) {
  430. elem.style.display = 'block';
  431. if (name === 'editor' || name === 'game') {
  432. const canvas = document.getElementById(`${name}-canvas`);
  433. canvas.focus();
  434. }
  435. } else {
  436. elem.style.display = 'none';
  437. }
  438. });
  439. }
  440. function setButtonEnabled(id, enabled) {
  441. if (enabled) {
  442. document.getElementById(id).disabled = '';
  443. } else {
  444. document.getElementById(id).disabled = 'disabled';
  445. }
  446. }
  447. function setLoaderEnabled(enabled) {
  448. setButtonEnabled('btn-tab-loader', enabled);
  449. setButtonEnabled('btn-tab-editor', !enabled);
  450. setButtonEnabled('btn-close-editor', !enabled);
  451. }
  452. function setGameTabEnabled(enabled) {
  453. setButtonEnabled('btn-tab-game', enabled);
  454. setButtonEnabled('btn-close-game', enabled);
  455. }
  456. function closeGame() {
  457. if (game) {
  458. game.requestQuit();
  459. }
  460. }
  461. function closeEditor() { // eslint-disable-line no-unused-vars
  462. closeGame();
  463. if (editor) {
  464. editor.requestQuit();
  465. }
  466. }
  467. function startEditor(zip) {
  468. const INDETERMINATE_STATUS_STEP_MS = 100;
  469. const persistentPaths = ['/home/web_user'];
  470. let editorCanvas = document.getElementById('editor-canvas');
  471. let gameCanvas = document.getElementById('game-canvas');
  472. const statusProgress = document.getElementById('status-progress');
  473. const statusProgressInner = document.getElementById('status-progress-inner');
  474. const statusIndeterminate = document.getElementById('status-indeterminate');
  475. const statusNotice = document.getElementById('status-notice');
  476. const headerDiv = document.getElementById('tabs-buttons');
  477. let initializing = true;
  478. let statusMode = 'hidden';
  479. showTab('status');
  480. let animationCallbacks = [];
  481. function animate(time) {
  482. animationCallbacks.forEach((callback) => callback(time));
  483. requestAnimationFrame(animate);
  484. }
  485. requestAnimationFrame(animate);
  486. let lastScale = 0;
  487. let lastWidth = 0;
  488. let lastHeight = 0;
  489. function adjustCanvasDimensions() {
  490. const scale = window.devicePixelRatio || 1;
  491. const headerHeight = headerDiv.offsetHeight + 1;
  492. const width = window.innerWidth;
  493. const height = window.innerHeight - headerHeight;
  494. if (lastScale !== scale || lastWidth !== width || lastHeight !== height) {
  495. editorCanvas.width = width * scale;
  496. editorCanvas.height = height * scale;
  497. editorCanvas.style.width = `${width}px`;
  498. editorCanvas.style.height = `${height}px`;
  499. lastScale = scale;
  500. lastWidth = width;
  501. lastHeight = height;
  502. }
  503. }
  504. animationCallbacks.push(adjustCanvasDimensions);
  505. adjustCanvasDimensions();
  506. function replaceCanvas(from) {
  507. const out = document.createElement('canvas');
  508. out.id = from.id;
  509. out.tabIndex = from.tabIndex;
  510. from.parentNode.replaceChild(out, from);
  511. lastScale = 0;
  512. return out;
  513. }
  514. function animateStatusIndeterminate(ms) {
  515. const i = Math.floor((ms / INDETERMINATE_STATUS_STEP_MS) % 8);
  516. if (statusIndeterminate.children[i].style.borderTopColor === '') {
  517. Array.prototype.slice.call(statusIndeterminate.children).forEach((child) => {
  518. child.style.borderTopColor = '';
  519. });
  520. statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf';
  521. }
  522. }
  523. setStatusMode = function (mode) {
  524. if (statusMode === mode || !initializing) {
  525. return;
  526. }
  527. [statusProgress, statusIndeterminate, statusNotice].forEach((elem) => {
  528. elem.style.display = 'none';
  529. });
  530. animationCallbacks = animationCallbacks.filter(function (value) {
  531. return (value !== animateStatusIndeterminate);
  532. });
  533. switch (mode) {
  534. case 'progress':
  535. statusProgress.style.display = 'block';
  536. break;
  537. case 'indeterminate':
  538. statusIndeterminate.style.display = 'block';
  539. animationCallbacks.push(animateStatusIndeterminate);
  540. break;
  541. case 'notice':
  542. statusNotice.style.display = 'block';
  543. break;
  544. case 'hidden':
  545. break;
  546. default:
  547. throw new Error('Invalid status mode');
  548. }
  549. statusMode = mode;
  550. };
  551. setStatusNotice = function (text) {
  552. while (statusNotice.lastChild) {
  553. statusNotice.removeChild(statusNotice.lastChild);
  554. }
  555. const lines = text.split('\n');
  556. lines.forEach((line) => {
  557. statusNotice.appendChild(document.createTextNode(line));
  558. statusNotice.appendChild(document.createElement('br'));
  559. });
  560. };
  561. const gameConfig = {
  562. 'persistentPaths': persistentPaths,
  563. 'unloadAfterInit': false,
  564. 'canvas': gameCanvas,
  565. 'canvasResizePolicy': 1,
  566. 'onExit': function () {
  567. gameCanvas = replaceCanvas(gameCanvas);
  568. setGameTabEnabled(false);
  569. showTab('editor');
  570. game = null;
  571. },
  572. };
  573. let OnEditorExit = function () {
  574. showTab('loader');
  575. setLoaderEnabled(true);
  576. };
  577. function Execute(args) {
  578. const is_editor = args.filter(function (v) {
  579. return v === '--editor' || v === '-e';
  580. }).length !== 0;
  581. const is_project_manager = args.filter(function (v) {
  582. return v === '--project-manager';
  583. }).length !== 0;
  584. const is_game = !is_editor && !is_project_manager;
  585. if (video_driver) {
  586. args.push('--rendering-driver', video_driver);
  587. }
  588. if (is_game) {
  589. if (game) {
  590. console.error('A game is already running. Close it first');
  591. return;
  592. }
  593. setGameTabEnabled(true);
  594. game = new Engine(gameConfig);
  595. showTab('game');
  596. game.init().then(function () {
  597. requestAnimationFrame(function () {
  598. game.start({ 'args': args, 'canvas': gameCanvas }).then(function () {
  599. gameCanvas.focus();
  600. });
  601. });
  602. });
  603. } else { // New editor instances will be run in the same canvas. We want to wait for it to exit.
  604. OnEditorExit = function (code) {
  605. setLoaderEnabled(true);
  606. setTimeout(function () {
  607. editor.init().then(function () {
  608. setLoaderEnabled(false);
  609. OnEditorExit = function () {
  610. showTab('loader');
  611. setLoaderEnabled(true);
  612. };
  613. editor.start({ 'args': args, 'persistentDrops': is_project_manager, 'canvas': editorCanvas });
  614. });
  615. }, 0);
  616. OnEditorExit = null;
  617. };
  618. }
  619. }
  620. const editorConfig = {
  621. 'unloadAfterInit': false,
  622. 'onProgress': function progressFunction(current, total) {
  623. if (total > 0) {
  624. statusProgressInner.style.width = `${(current / total) * 100}%`;
  625. setStatusMode('progress');
  626. if (current === total) {
  627. // wait for progress bar animation
  628. setTimeout(() => {
  629. setStatusMode('indeterminate');
  630. }, 100);
  631. }
  632. } else {
  633. setStatusMode('indeterminate');
  634. }
  635. },
  636. 'canvas': editorCanvas,
  637. 'canvasResizePolicy': 0,
  638. 'onExit': function () {
  639. editorCanvas = replaceCanvas(editorCanvas);
  640. if (OnEditorExit) {
  641. OnEditorExit();
  642. }
  643. },
  644. 'onExecute': Execute,
  645. 'persistentPaths': persistentPaths,
  646. };
  647. editor = new Engine(editorConfig);
  648. function displayFailureNotice(err) {
  649. const msg = err.message || err;
  650. console.error(msg);
  651. setStatusNotice(msg);
  652. setStatusMode('notice');
  653. initializing = false;
  654. }
  655. if (!Engine.isWebGLAvailable()) {
  656. displayFailureNotice('WebGL not available');
  657. } else {
  658. setStatusMode('indeterminate');
  659. editor.init('godot.editor').then(function () {
  660. if (zip) {
  661. editor.copyToFS('/tmp/preload.zip', zip);
  662. }
  663. try {
  664. // Avoid user creating project in the persistent root folder.
  665. editor.copyToFS('/home/web_user/keep', new Uint8Array());
  666. } catch (e) {
  667. // File exists
  668. }
  669. selectVideoMode();
  670. showTab('editor');
  671. setLoaderEnabled(false);
  672. const args = ['--project-manager', '--single-window'];
  673. if (video_driver) {
  674. args.push('--rendering-driver', video_driver);
  675. }
  676. editor.start({ 'args': args, 'persistentDrops': true }).then(function () {
  677. setStatusMode('hidden');
  678. initializing = false;
  679. });
  680. }).catch(displayFailureNotice);
  681. }
  682. }
  683. function preloadZip(target) {
  684. return new Promise(function (resolve, reject) {
  685. if (target.files.length > 0) {
  686. target.files[0].arrayBuffer().then(function (data) {
  687. resolve(data);
  688. });
  689. } else {
  690. resolve();
  691. }
  692. });
  693. }
  694. document.getElementById('startButton').onclick = function () {
  695. preloadZip(document.getElementById('zip-file')).then(function (zip) {
  696. startEditor(zip);
  697. });
  698. };
  699. </script>
  700. </body>
  701. </html>