full-size.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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">
  6. <title>$GODOT_PROJECT_NAME</title>
  7. <style>
  8. body {
  9. touch-action: none;
  10. margin: 0;
  11. border: 0 none;
  12. padding: 0;
  13. text-align: center;
  14. background-color: black;
  15. }
  16. #canvas {
  17. display: block;
  18. margin: 0;
  19. color: white;
  20. }
  21. #canvas:focus {
  22. outline: none;
  23. }
  24. .godot {
  25. font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
  26. color: #e0e0e0;
  27. background-color: #3b3943;
  28. background-image: linear-gradient(to bottom, #403e48, #35333c);
  29. border: 1px solid #45434e;
  30. box-shadow: 0 0 1px 1px #2f2d35;
  31. }
  32. /* Status display */
  33. #status {
  34. position: absolute;
  35. left: 0;
  36. top: 0;
  37. right: 0;
  38. bottom: 0;
  39. display: flex;
  40. justify-content: center;
  41. align-items: center;
  42. /* don't consume click events - make children visible explicitly */
  43. visibility: hidden;
  44. }
  45. #status-progress {
  46. width: 366px;
  47. height: 7px;
  48. background-color: #38363A;
  49. border: 1px solid #444246;
  50. padding: 1px;
  51. box-shadow: 0 0 2px 1px #1B1C22;
  52. border-radius: 2px;
  53. visibility: visible;
  54. }
  55. @media only screen and (orientation:portrait) {
  56. #status-progress {
  57. width: 61.8%;
  58. }
  59. }
  60. #status-progress-inner {
  61. height: 100%;
  62. width: 0;
  63. box-sizing: border-box;
  64. transition: width 0.5s linear;
  65. background-color: #202020;
  66. border: 1px solid #222223;
  67. box-shadow: 0 0 1px 1px #27282E;
  68. border-radius: 3px;
  69. }
  70. #status-indeterminate {
  71. height: 42px;
  72. visibility: visible;
  73. position: relative;
  74. }
  75. #status-indeterminate > div {
  76. width: 4.5px;
  77. height: 0;
  78. border-style: solid;
  79. border-width: 9px 3px 0 3px;
  80. border-color: #2b2b2b transparent transparent transparent;
  81. transform-origin: center 21px;
  82. position: absolute;
  83. }
  84. #status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); }
  85. #status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); }
  86. #status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); }
  87. #status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); }
  88. #status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); }
  89. #status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); }
  90. #status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); }
  91. #status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); }
  92. #status-notice {
  93. margin: 0 100px;
  94. line-height: 1.3;
  95. visibility: visible;
  96. padding: 4px 6px;
  97. visibility: visible;
  98. }
  99. </style>
  100. $GODOT_HEAD_INCLUDE
  101. </head>
  102. <body>
  103. <canvas id="canvas">
  104. HTML5 canvas appears to be unsupported in the current browser.<br >
  105. Please try updating or use a different browser.
  106. </canvas>
  107. <div id="status">
  108. <div id="status-progress" style="display: none;" oncontextmenu="event.preventDefault();">
  109. <div id ="status-progress-inner"></div>
  110. </div>
  111. <div id="status-indeterminate" style="display: none;" oncontextmenu="event.preventDefault();">
  112. <div></div>
  113. <div></div>
  114. <div></div>
  115. <div></div>
  116. <div></div>
  117. <div></div>
  118. <div></div>
  119. <div></div>
  120. </div>
  121. <div id="status-notice" class="godot" style="display: none;"></div>
  122. </div>
  123. <script src="$GODOT_URL"></script>
  124. <script>
  125. const GODOT_CONFIG = $GODOT_CONFIG;
  126. const engine = new Engine(GODOT_CONFIG);
  127. (function () {
  128. const INDETERMINATE_STATUS_STEP_MS = 100;
  129. const statusProgress = document.getElementById('status-progress');
  130. const statusProgressInner = document.getElementById('status-progress-inner');
  131. const statusIndeterminate = document.getElementById('status-indeterminate');
  132. const statusNotice = document.getElementById('status-notice');
  133. let initializing = true;
  134. let statusMode = 'hidden';
  135. let animationCallbacks = [];
  136. function animate(time) {
  137. animationCallbacks.forEach((callback) => callback(time));
  138. requestAnimationFrame(animate);
  139. }
  140. requestAnimationFrame(animate);
  141. function animateStatusIndeterminate(ms) {
  142. const i = Math.floor((ms / INDETERMINATE_STATUS_STEP_MS) % 8);
  143. if (statusIndeterminate.children[i].style.borderTopColor === '') {
  144. Array.prototype.slice.call(statusIndeterminate.children).forEach((child) => {
  145. child.style.borderTopColor = '';
  146. });
  147. statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf';
  148. }
  149. }
  150. function setStatusMode(mode) {
  151. if (statusMode === mode || !initializing) {
  152. return;
  153. }
  154. [statusProgress, statusIndeterminate, statusNotice].forEach((elem) => {
  155. elem.style.display = 'none';
  156. });
  157. animationCallbacks = animationCallbacks.filter(function (value) {
  158. return (value !== animateStatusIndeterminate);
  159. });
  160. switch (mode) {
  161. case 'progress':
  162. statusProgress.style.display = 'block';
  163. break;
  164. case 'indeterminate':
  165. statusIndeterminate.style.display = 'block';
  166. animationCallbacks.push(animateStatusIndeterminate);
  167. break;
  168. case 'notice':
  169. statusNotice.style.display = 'block';
  170. break;
  171. case 'hidden':
  172. break;
  173. default:
  174. throw new Error('Invalid status mode');
  175. }
  176. statusMode = mode;
  177. }
  178. function setStatusNotice(text) {
  179. while (statusNotice.lastChild) {
  180. statusNotice.removeChild(statusNotice.lastChild);
  181. }
  182. const lines = text.split('\n');
  183. lines.forEach((line) => {
  184. statusNotice.appendChild(document.createTextNode(line));
  185. statusNotice.appendChild(document.createElement('br'));
  186. });
  187. }
  188. function displayFailureNotice(err) {
  189. const msg = err.message || err;
  190. console.error(msg);
  191. setStatusNotice(msg);
  192. setStatusMode('notice');
  193. initializing = false;
  194. }
  195. const missing = Engine.getMissingFeatures();
  196. if (missing.length !== 0) {
  197. const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n';
  198. displayFailureNotice(missingMsg + missing.join('\n'));
  199. } else {
  200. setStatusMode('indeterminate');
  201. engine.startGame({
  202. 'onProgress': function (current, total) {
  203. if (total > 0) {
  204. statusProgressInner.style.width = `${(current / total) * 100}%`;
  205. setStatusMode('progress');
  206. if (current === total) {
  207. // wait for progress bar animation
  208. setTimeout(() => {
  209. setStatusMode('indeterminate');
  210. }, 500);
  211. }
  212. } else {
  213. setStatusMode('indeterminate');
  214. }
  215. },
  216. }).then(() => {
  217. setStatusMode('hidden');
  218. initializing = false;
  219. }, displayFailureNotice);
  220. }
  221. }());
  222. </script>
  223. </body>
  224. </html>