full-size.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
  6. <title>$GODOT_PROJECT_NAME</title>
  7. <style>
  8. html, body, #canvas {
  9. margin: 0;
  10. padding: 0;
  11. border: 0;
  12. }
  13. body {
  14. color: white;
  15. background-color: black;
  16. overflow: hidden;
  17. touch-action: none;
  18. }
  19. #canvas {
  20. display: block;
  21. }
  22. #canvas:focus {
  23. outline: none;
  24. }
  25. #status, #status-splash, #status-progress {
  26. position: absolute;
  27. left: 0;
  28. right: 0;
  29. }
  30. #status, #status-splash {
  31. top: 0;
  32. bottom: 0;
  33. }
  34. #status {
  35. background-color: $GODOT_SPLASH_COLOR;
  36. display: flex;
  37. flex-direction: column;
  38. justify-content: center;
  39. align-items: center;
  40. visibility: hidden;
  41. }
  42. #status-splash {
  43. max-height: 100%;
  44. max-width: 100%;
  45. margin: auto;
  46. }
  47. #status-splash.show-image--false {
  48. display: none;
  49. }
  50. #status-splash.fullsize--true {
  51. height: 100%;
  52. width: 100%;
  53. object-fit: contain;
  54. }
  55. #status-splash.use-filter--false {
  56. image-rendering: pixelated;
  57. }
  58. #status-progress, #status-notice {
  59. display: none;
  60. }
  61. #status-progress {
  62. bottom: 10%;
  63. width: 50%;
  64. margin: 0 auto;
  65. }
  66. #status-notice {
  67. background-color: #5b3943;
  68. border-radius: 0.5rem;
  69. border: 1px solid #9b3943;
  70. color: #e0e0e0;
  71. font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
  72. line-height: 1.3;
  73. margin: 0 2rem;
  74. overflow: hidden;
  75. padding: 1rem;
  76. text-align: center;
  77. z-index: 1;
  78. }
  79. </style>
  80. $GODOT_HEAD_INCLUDE
  81. </head>
  82. <body>
  83. <canvas id="canvas">
  84. Your browser does not support the canvas tag.
  85. </canvas>
  86. <noscript>
  87. Your browser does not support JavaScript.
  88. </noscript>
  89. <div id="status">
  90. <img id="status-splash" class="$GODOT_SPLASH_CLASSES" src="$GODOT_SPLASH" alt="">
  91. <progress id="status-progress"></progress>
  92. <div id="status-notice"></div>
  93. </div>
  94. <script src="$GODOT_URL"></script>
  95. <script>
  96. const GODOT_CONFIG = $GODOT_CONFIG;
  97. const GODOT_THREADS_ENABLED = $GODOT_THREADS_ENABLED;
  98. const engine = new Engine(GODOT_CONFIG);
  99. (function () {
  100. const statusOverlay = document.getElementById('status');
  101. const statusProgress = document.getElementById('status-progress');
  102. const statusNotice = document.getElementById('status-notice');
  103. let initializing = true;
  104. let statusMode = '';
  105. function setStatusMode(mode) {
  106. if (statusMode === mode || !initializing) {
  107. return;
  108. }
  109. if (mode === 'hidden') {
  110. statusOverlay.remove();
  111. initializing = false;
  112. return;
  113. }
  114. statusOverlay.style.visibility = 'visible';
  115. statusProgress.style.display = mode === 'progress' ? 'block' : 'none';
  116. statusNotice.style.display = mode === 'notice' ? 'block' : 'none';
  117. statusMode = mode;
  118. }
  119. function setStatusNotice(text) {
  120. while (statusNotice.lastChild) {
  121. statusNotice.removeChild(statusNotice.lastChild);
  122. }
  123. const lines = text.split('\n');
  124. lines.forEach((line) => {
  125. statusNotice.appendChild(document.createTextNode(line));
  126. statusNotice.appendChild(document.createElement('br'));
  127. });
  128. }
  129. function displayFailureNotice(err) {
  130. console.error(err);
  131. if (err instanceof Error) {
  132. setStatusNotice(err.message);
  133. } else if (typeof err === 'string') {
  134. setStatusNotice(err);
  135. } else {
  136. setStatusNotice('An unknown error occurred.');
  137. }
  138. setStatusMode('notice');
  139. initializing = false;
  140. }
  141. const missing = Engine.getMissingFeatures({
  142. threads: GODOT_THREADS_ENABLED,
  143. });
  144. if (missing.length !== 0) {
  145. if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) {
  146. let serviceWorkerRegistrationPromise;
  147. try {
  148. serviceWorkerRegistrationPromise = navigator.serviceWorker.getRegistration();
  149. } catch (err) {
  150. serviceWorkerRegistrationPromise = Promise.reject(new Error('Service worker registration failed.'));
  151. }
  152. // There's a chance that installing the service worker would fix the issue
  153. Promise.race([
  154. serviceWorkerRegistrationPromise.then((registration) => {
  155. if (registration != null) {
  156. return Promise.reject(new Error('Service worker already exists.'));
  157. }
  158. return registration;
  159. }).then(() => engine.installServiceWorker()),
  160. // For some reason, `getRegistration()` can stall
  161. new Promise((resolve) => {
  162. setTimeout(() => resolve(), 2000);
  163. }),
  164. ]).then(() => {
  165. // Reload if there was no error.
  166. window.location.reload();
  167. }).catch((err) => {
  168. console.error('Error while registering service worker:', err);
  169. });
  170. } else {
  171. // Display the message as usual
  172. const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n';
  173. displayFailureNotice(missingMsg + missing.join('\n'));
  174. }
  175. } else {
  176. setStatusMode('progress');
  177. engine.startGame({
  178. 'onProgress': function (current, total) {
  179. if (current > 0 && total > 0) {
  180. statusProgress.value = current;
  181. statusProgress.max = total;
  182. } else {
  183. statusProgress.removeAttribute('value');
  184. statusProgress.removeAttribute('max');
  185. }
  186. },
  187. }).then(() => {
  188. setStatusMode('hidden');
  189. }, displayFailureNotice);
  190. }
  191. }());
  192. </script>
  193. </body>
  194. </html>