editor.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. }
  204. </style>
  205. </head>
  206. <body>
  207. <div
  208. id="welcome-modal"
  209. class="welcome-modal"
  210. role="dialog"
  211. aria-labelledby="welcome-modal-title"
  212. aria-describedby="welcome-modal-description"
  213. onclick="if (event.target === this) closeWelcomeModal(false)"
  214. >
  215. <div class="welcome-modal-content">
  216. <h2 id="welcome-modal-title" class="welcome-modal-title">Important - Please read before continuing</h2>
  217. <div id="welcome-modal-description">
  218. <p>
  219. The Godot Web Editor has some limitations compared to the native version.
  220. Its main focus is education and experimentation;
  221. <strong>it is not recommended for production</strong>.
  222. </p>
  223. <p>
  224. Refer to the
  225. <a
  226. href="https://docs.godotengine.org/en/latest/tutorials/editor/using_the_web_editor.html"
  227. target="_blank"
  228. rel="noopener"
  229. >Web editor documentation</a> for usage instructions and limitations.
  230. </p>
  231. </div>
  232. <div id="welcome-modal-missing-description" style="display: none">
  233. <p>
  234. <strong>The following features required by the Godot Web Editor are missing:</strong>
  235. </p>
  236. <ul id="welcome-modal-missing-list">
  237. </ul>
  238. <p>
  239. If you are self-hosting the web editor,
  240. refer to
  241. <a
  242. href="https://docs.godotengine.org/en/latest/tutorials/export/exporting_for_web.html"
  243. target="_blank"
  244. rel="noopener"
  245. >Exporting for the Web</a> for more information.
  246. </p>
  247. </div>
  248. <div style="text-align: center">
  249. <button id="welcome-modal-dismiss" class="btn" type="button" onclick="closeWelcomeModal(true)" style="margin-top: 1rem">
  250. OK, don't show again
  251. </button>
  252. </div>
  253. </div>
  254. </div>
  255. <div id="tabs-buttons">
  256. <button id="btn-tab-loader" class="btn tab-btn" onclick="showTab('loader')">Loader</button>
  257. <button id="btn-tab-editor" class="btn tab-btn" disabled="disabled" onclick="showTab('editor')">Editor</button>
  258. <button id="btn-close-editor" class="btn close-btn" disabled="disabled" onclick="closeEditor()">×</button>
  259. <button id="btn-tab-game" class="btn tab-btn" disabled="disabled" onclick="showTab('game')">Game</button>
  260. <button id="btn-close-game" class="btn close-btn" disabled="disabled" onclick="closeGame()">×</button>
  261. <button id="btn-tab-update" class="btn tab-btn" style="display: none;">Update</button>
  262. </div>
  263. <div id="tabs">
  264. <div id="tab-loader">
  265. <div style="color: #e0e0e0;" id="persistence">
  266. <br >
  267. <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">
  268. <br >
  269. ___GODOT_VERSION___
  270. <br >
  271. <a href="releases/">Need an old version?</a>
  272. <br >
  273. <br >
  274. <br >
  275. <label for="videoMode" style="margin-right: 1rem">Video driver:</label>
  276. <select id="videoMode">
  277. <option value="" selected="selected">Auto</option>
  278. <option value="opengl3">WebGL 2</option>
  279. </select>
  280. <br >
  281. <br >
  282. <label for="zip-file" style="margin-right: 1rem">Preload project ZIP:</label>
  283. <input id="zip-file" type="file" name="files" style="margin-bottom: 1rem">
  284. <br >
  285. <a href="demo.zip">(Try this for example)</a>
  286. <br >
  287. <br >
  288. <button id="startButton" class="btn" style="margin-bottom: 4rem; font-weight: 700">Start Godot editor</button>
  289. <br >
  290. <button class="btn" onclick="clearPersistence()" style="margin-bottom: 1.5rem">Clear persistent data</button>
  291. <br >
  292. <a href="https://docs.godotengine.org/en/latest/tutorials/editor/using_the_web_editor.html">Web editor documentation</a>
  293. </div>
  294. </div>
  295. <div id="tab-editor" style="display: none;">
  296. <canvas id="editor-canvas" tabindex="1">
  297. HTML5 canvas appears to be unsupported in the current browser.<br >
  298. Please try updating or use a different browser.
  299. </canvas>
  300. </div>
  301. <div id="tab-game" style="display: none;">
  302. <canvas id="game-canvas" tabindex="2">
  303. HTML5 canvas appears to be unsupported in the current browser.<br >
  304. Please try updating or use a different browser.
  305. </canvas>
  306. </div>
  307. <div id="tab-status" style="display: none;">
  308. <div id="status-progress" style="display: none;" oncontextmenu="event.preventDefault();">
  309. <div id="status-progress-inner"></div>
  310. </div>
  311. <div id="status-indeterminate" style="display: none;" oncontextmenu="event.preventDefault();">
  312. <div></div>
  313. <div></div>
  314. <div></div>
  315. <div></div>
  316. <div></div>
  317. <div></div>
  318. <div></div>
  319. <div></div>
  320. </div>
  321. <div id="status-notice" class="godot" style="display: none;"></div>
  322. </div>
  323. </div>
  324. <script>
  325. window.addEventListener('load', () => {
  326. function notifyUpdate(sw) {
  327. const btn = document.getElementById('btn-tab-update');
  328. btn.onclick = function () {
  329. if (!window.confirm('Are you sure you want to update?\nClicking "OK" will reload all active instances!')) {
  330. return;
  331. }
  332. sw.postMessage('update');
  333. btn.innerHTML = 'Updating...';
  334. btn.disabled = true;
  335. };
  336. btn.style.display = '';
  337. }
  338. if ('serviceWorker' in navigator) {
  339. navigator.serviceWorker.register('service.worker.js').then(function (reg) {
  340. if (reg.waiting) {
  341. notifyUpdate(reg.waiting);
  342. }
  343. reg.addEventListener('updatefound', function () {
  344. const update = reg.installing;
  345. update.addEventListener('statechange', function () {
  346. if (update.state === 'installed') {
  347. // It's a new install, claim and perform aggressive caching.
  348. if (!reg.active) {
  349. update.postMessage('claim');
  350. } else {
  351. notifyUpdate(update);
  352. }
  353. }
  354. });
  355. });
  356. });
  357. }
  358. const missing = Engine.getMissingFeatures({
  359. threads: ___GODOT_THREADS_ENABLED___,
  360. });
  361. if (missing.length) {
  362. // Display error dialog as threading support is required for the editor.
  363. document.getElementById('startButton').disabled = 'disabled';
  364. document.getElementById('welcome-modal-description').style.display = 'none';
  365. document.getElementById('welcome-modal-missing-description').style.display = 'block';
  366. document.getElementById('welcome-modal-dismiss').style.display = 'none';
  367. const list = document.getElementById('welcome-modal-missing-list');
  368. for (let i = 0; i < missing.length; i++) {
  369. const node = document.createElement('li');
  370. node.innerText = missing[i];
  371. list.appendChild(node);
  372. }
  373. }
  374. if (missing.length || localStorage.getItem('welcomeModalDismissed') !== 'true') {
  375. document.getElementById('welcome-modal').style.display = 'block';
  376. document.getElementById('welcome-modal-dismiss').focus();
  377. }
  378. });
  379. function closeWelcomeModal(dontShowAgain) { // eslint-disable-line no-unused-vars
  380. document.getElementById('welcome-modal').style.display = 'none';
  381. if (dontShowAgain) {
  382. localStorage.setItem('welcomeModalDismissed', 'true');
  383. }
  384. }
  385. </script>
  386. <script src="godot.editor.js"></script>
  387. <script>
  388. let editor = null;
  389. let game = null;
  390. let setStatusMode;
  391. let setStatusNotice;
  392. let video_driver = '';
  393. function clearPersistence() { // eslint-disable-line no-unused-vars
  394. function deleteDB(path) {
  395. return new Promise(function (resolve, reject) {
  396. const req = indexedDB.deleteDatabase(path);
  397. req.onsuccess = function () {
  398. resolve();
  399. };
  400. req.onerror = function (err) {
  401. reject(err);
  402. };
  403. req.onblocked = function (err) {
  404. reject(err);
  405. };
  406. });
  407. }
  408. 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!')) {
  409. return;
  410. }
  411. Promise.all([
  412. deleteDB('/home/web_user'),
  413. ]).then(function (results) {
  414. alert('Done.');
  415. }).catch(function (err) {
  416. alert('Error deleting local files. Please retry after reloading the page.');
  417. });
  418. }
  419. function selectVideoMode() {
  420. const select = document.getElementById('videoMode');
  421. video_driver = select.selectedOptions[0].value;
  422. }
  423. const tabs = [
  424. document.getElementById('tab-loader'),
  425. document.getElementById('tab-editor'),
  426. document.getElementById('tab-game'),
  427. ];
  428. function showTab(name) {
  429. tabs.forEach(function (elem) {
  430. if (elem.id === `tab-${name}`) {
  431. elem.style.display = 'block';
  432. if (name === 'editor' || name === 'game') {
  433. const canvas = document.getElementById(`${name}-canvas`);
  434. canvas.focus();
  435. }
  436. } else {
  437. elem.style.display = 'none';
  438. }
  439. });
  440. }
  441. function setButtonEnabled(id, enabled) {
  442. if (enabled) {
  443. document.getElementById(id).disabled = '';
  444. } else {
  445. document.getElementById(id).disabled = 'disabled';
  446. }
  447. }
  448. function setLoaderEnabled(enabled) {
  449. setButtonEnabled('btn-tab-loader', enabled);
  450. setButtonEnabled('btn-tab-editor', !enabled);
  451. setButtonEnabled('btn-close-editor', !enabled);
  452. }
  453. function setGameTabEnabled(enabled) {
  454. setButtonEnabled('btn-tab-game', enabled);
  455. setButtonEnabled('btn-close-game', enabled);
  456. }
  457. function closeGame() {
  458. if (game) {
  459. game.requestQuit();
  460. }
  461. }
  462. function closeEditor() { // eslint-disable-line no-unused-vars
  463. closeGame();
  464. if (editor) {
  465. editor.requestQuit();
  466. }
  467. }
  468. function startEditor(zip) {
  469. const INDETERMINATE_STATUS_STEP_MS = 100;
  470. const persistentPaths = ['/home/web_user'];
  471. let editorCanvas = document.getElementById('editor-canvas');
  472. let gameCanvas = document.getElementById('game-canvas');
  473. const statusProgress = document.getElementById('status-progress');
  474. const statusProgressInner = document.getElementById('status-progress-inner');
  475. const statusIndeterminate = document.getElementById('status-indeterminate');
  476. const statusNotice = document.getElementById('status-notice');
  477. const headerDiv = document.getElementById('tabs-buttons');
  478. let initializing = true;
  479. let statusMode = 'hidden';
  480. showTab('status');
  481. let animationCallbacks = [];
  482. function animate(time) {
  483. animationCallbacks.forEach((callback) => callback(time));
  484. requestAnimationFrame(animate);
  485. }
  486. requestAnimationFrame(animate);
  487. let lastScale = 0;
  488. let lastWidth = 0;
  489. let lastHeight = 0;
  490. function adjustCanvasDimensions() {
  491. const scale = window.devicePixelRatio || 1;
  492. const headerHeight = headerDiv.offsetHeight + 1;
  493. const width = window.innerWidth;
  494. const height = window.innerHeight - headerHeight;
  495. if (lastScale !== scale || lastWidth !== width || lastHeight !== height) {
  496. editorCanvas.width = width * scale;
  497. editorCanvas.height = height * scale;
  498. editorCanvas.style.width = `${width}px`;
  499. editorCanvas.style.height = `${height}px`;
  500. lastScale = scale;
  501. lastWidth = width;
  502. lastHeight = height;
  503. }
  504. }
  505. animationCallbacks.push(adjustCanvasDimensions);
  506. adjustCanvasDimensions();
  507. function replaceCanvas(from) {
  508. const out = document.createElement('canvas');
  509. out.id = from.id;
  510. out.tabIndex = from.tabIndex;
  511. from.parentNode.replaceChild(out, from);
  512. lastScale = 0;
  513. return out;
  514. }
  515. function animateStatusIndeterminate(ms) {
  516. const i = Math.floor((ms / INDETERMINATE_STATUS_STEP_MS) % 8);
  517. if (statusIndeterminate.children[i].style.borderTopColor === '') {
  518. Array.prototype.slice.call(statusIndeterminate.children).forEach((child) => {
  519. child.style.borderTopColor = '';
  520. });
  521. statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf';
  522. }
  523. }
  524. setStatusMode = function (mode) {
  525. if (statusMode === mode || !initializing) {
  526. return;
  527. }
  528. [statusProgress, statusIndeterminate, statusNotice].forEach((elem) => {
  529. elem.style.display = 'none';
  530. });
  531. animationCallbacks = animationCallbacks.filter(function (value) {
  532. return (value !== animateStatusIndeterminate);
  533. });
  534. switch (mode) {
  535. case 'progress':
  536. statusProgress.style.display = 'block';
  537. break;
  538. case 'indeterminate':
  539. statusIndeterminate.style.display = 'block';
  540. animationCallbacks.push(animateStatusIndeterminate);
  541. break;
  542. case 'notice':
  543. statusNotice.style.display = 'block';
  544. break;
  545. case 'hidden':
  546. break;
  547. default:
  548. throw new Error('Invalid status mode');
  549. }
  550. statusMode = mode;
  551. };
  552. setStatusNotice = function (text) {
  553. while (statusNotice.lastChild) {
  554. statusNotice.removeChild(statusNotice.lastChild);
  555. }
  556. const lines = text.split('\n');
  557. lines.forEach((line) => {
  558. statusNotice.appendChild(document.createTextNode(line));
  559. statusNotice.appendChild(document.createElement('br'));
  560. });
  561. };
  562. const gameConfig = {
  563. 'persistentPaths': persistentPaths,
  564. 'unloadAfterInit': false,
  565. 'canvas': gameCanvas,
  566. 'canvasResizePolicy': 1,
  567. 'onExit': function () {
  568. gameCanvas = replaceCanvas(gameCanvas);
  569. setGameTabEnabled(false);
  570. showTab('editor');
  571. game = null;
  572. },
  573. };
  574. let OnEditorExit = function () {
  575. showTab('loader');
  576. setLoaderEnabled(true);
  577. };
  578. function Execute(args) {
  579. const is_editor = args.filter(function (v) {
  580. return v === '--editor' || v === '-e';
  581. }).length !== 0;
  582. const is_project_manager = args.filter(function (v) {
  583. return v === '--project-manager';
  584. }).length !== 0;
  585. const is_game = !is_editor && !is_project_manager;
  586. if (video_driver) {
  587. args.push('--rendering-driver', video_driver);
  588. }
  589. if (is_game) {
  590. if (game) {
  591. console.error('A game is already running. Close it first');
  592. return;
  593. }
  594. setGameTabEnabled(true);
  595. game = new Engine(gameConfig);
  596. showTab('game');
  597. game.init().then(function () {
  598. requestAnimationFrame(function () {
  599. game.start({ 'args': args, 'canvas': gameCanvas }).then(function () {
  600. gameCanvas.focus();
  601. });
  602. });
  603. });
  604. } else { // New editor instances will be run in the same canvas. We want to wait for it to exit.
  605. OnEditorExit = function (code) {
  606. setLoaderEnabled(true);
  607. setTimeout(function () {
  608. editor.init().then(function () {
  609. setLoaderEnabled(false);
  610. OnEditorExit = function () {
  611. showTab('loader');
  612. setLoaderEnabled(true);
  613. };
  614. editor.start({ 'args': args, 'persistentDrops': is_project_manager, 'canvas': editorCanvas });
  615. });
  616. }, 0);
  617. OnEditorExit = null;
  618. };
  619. }
  620. }
  621. const editorConfig = {
  622. 'unloadAfterInit': false,
  623. 'onProgress': function progressFunction(current, total) {
  624. if (total > 0) {
  625. statusProgressInner.style.width = `${(current / total) * 100}%`;
  626. setStatusMode('progress');
  627. if (current === total) {
  628. // wait for progress bar animation
  629. setTimeout(() => {
  630. setStatusMode('indeterminate');
  631. }, 100);
  632. }
  633. } else {
  634. setStatusMode('indeterminate');
  635. }
  636. },
  637. 'canvas': editorCanvas,
  638. 'canvasResizePolicy': 0,
  639. 'onExit': function () {
  640. editorCanvas = replaceCanvas(editorCanvas);
  641. if (OnEditorExit) {
  642. OnEditorExit();
  643. }
  644. },
  645. 'onExecute': Execute,
  646. 'persistentPaths': persistentPaths,
  647. };
  648. editor = new Engine(editorConfig);
  649. function displayFailureNotice(err) {
  650. console.error(err);
  651. if (err instanceof Error) {
  652. setStatusNotice(err.message);
  653. } else if (typeof err === 'string') {
  654. setStatusNotice(err);
  655. } else {
  656. setStatusNotice('An unknown error occured');
  657. }
  658. setStatusMode('notice');
  659. initializing = false;
  660. }
  661. if (!Engine.isWebGLAvailable()) {
  662. displayFailureNotice('WebGL not available');
  663. } else {
  664. setStatusMode('indeterminate');
  665. editor.init('godot.editor').then(function () {
  666. if (zip) {
  667. editor.copyToFS('/tmp/preload.zip', zip);
  668. }
  669. try {
  670. // Avoid user creating project in the persistent root folder.
  671. editor.copyToFS('/home/web_user/keep', new Uint8Array());
  672. } catch (e) {
  673. // File exists
  674. }
  675. selectVideoMode();
  676. showTab('editor');
  677. setLoaderEnabled(false);
  678. const args = ['--project-manager', '--single-window'];
  679. if (video_driver) {
  680. args.push('--rendering-driver', video_driver);
  681. }
  682. editor.start({ 'args': args, 'persistentDrops': true }).then(function () {
  683. setStatusMode('hidden');
  684. initializing = false;
  685. });
  686. }).catch(displayFailureNotice);
  687. }
  688. }
  689. function preloadZip(target) {
  690. return new Promise(function (resolve, reject) {
  691. if (target.files.length > 0) {
  692. target.files[0].arrayBuffer().then(function (data) {
  693. resolve(data);
  694. });
  695. } else {
  696. resolve();
  697. }
  698. });
  699. }
  700. document.getElementById('startButton').onclick = function () {
  701. preloadZip(document.getElementById('zip-file')).then(function (zip) {
  702. startEditor(zip);
  703. });
  704. };
  705. </script>
  706. </body>
  707. </html>