editor.html 23 KB

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