|
2 | 2 | <html lang="en"> |
3 | 3 | <head> |
4 | 4 | <meta charset="utf-8"> |
5 | | - <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"> |
| 5 | + <meta name="viewport" content="width=device-width, user-scalable=no"> |
6 | 6 | <title>tangram</title> |
7 | 7 | <style> |
8 | | -html, body, #canvas { |
| 8 | +body { |
| 9 | + touch-action: none; |
9 | 10 | margin: 0; |
| 11 | + border: 0 none; |
10 | 12 | padding: 0; |
11 | | - border: 0; |
12 | | -} |
13 | | - |
14 | | -body { |
15 | | - color: white; |
| 13 | + text-align: center; |
16 | 14 | background-color: black; |
17 | | - overflow: hidden; |
18 | | - touch-action: none; |
19 | 15 | } |
20 | 16 |
|
21 | 17 | #canvas { |
22 | 18 | display: block; |
| 19 | + margin: 0; |
| 20 | + color: white; |
23 | 21 | } |
24 | 22 |
|
25 | 23 | #canvas:focus { |
26 | 24 | outline: none; |
27 | 25 | } |
28 | 26 |
|
29 | | -#status, #status-splash, #status-progress { |
30 | | - position: absolute; |
31 | | - left: 0; |
32 | | - right: 0; |
| 27 | +.godot { |
| 28 | + font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif; |
| 29 | + color: #e0e0e0; |
| 30 | + background-color: #3b3943; |
| 31 | + background-image: linear-gradient(to bottom, #403e48, #35333c); |
| 32 | + border: 1px solid #45434e; |
| 33 | + box-shadow: 0 0 1px 1px #2f2d35; |
33 | 34 | } |
34 | 35 |
|
35 | | -#status, #status-splash { |
36 | | - top: 0; |
37 | | - bottom: 0; |
38 | | -} |
| 36 | +/* Status display */ |
39 | 37 |
|
40 | 38 | #status { |
41 | | - background-color: #242424; |
| 39 | + position: absolute; |
| 40 | + left: 0; |
| 41 | + top: 0; |
| 42 | + right: 0; |
| 43 | + bottom: 0; |
42 | 44 | display: flex; |
43 | | - flex-direction: column; |
44 | 45 | justify-content: center; |
45 | 46 | align-items: center; |
| 47 | + /* don't consume click events - make children visible explicitly */ |
46 | 48 | visibility: hidden; |
47 | 49 | } |
48 | 50 |
|
49 | | -#status-splash { |
50 | | - max-height: 100%; |
51 | | - max-width: 100%; |
52 | | - margin: auto; |
| 51 | +#status-progress { |
| 52 | + width: 366px; |
| 53 | + height: 7px; |
| 54 | + background-color: #38363A; |
| 55 | + border: 1px solid #444246; |
| 56 | + padding: 1px; |
| 57 | + box-shadow: 0 0 2px 1px #1B1C22; |
| 58 | + border-radius: 2px; |
| 59 | + visibility: visible; |
53 | 60 | } |
54 | 61 |
|
55 | | -#status-progress, #status-notice { |
56 | | - display: none; |
| 62 | +@media only screen and (orientation:portrait) { |
| 63 | + #status-progress { |
| 64 | + width: 61.8%; |
| 65 | + } |
57 | 66 | } |
58 | 67 |
|
59 | | -#status-progress { |
60 | | - bottom: 10%; |
61 | | - width: 50%; |
62 | | - margin: 0 auto; |
| 68 | +#status-progress-inner { |
| 69 | + height: 100%; |
| 70 | + width: 0; |
| 71 | + box-sizing: border-box; |
| 72 | + transition: width 0.5s linear; |
| 73 | + background-color: #202020; |
| 74 | + border: 1px solid #222223; |
| 75 | + box-shadow: 0 0 1px 1px #27282E; |
| 76 | + border-radius: 3px; |
| 77 | +} |
| 78 | + |
| 79 | +#status-indeterminate { |
| 80 | + height: 42px; |
| 81 | + visibility: visible; |
| 82 | + position: relative; |
| 83 | +} |
| 84 | + |
| 85 | +#status-indeterminate > div { |
| 86 | + width: 4.5px; |
| 87 | + height: 0; |
| 88 | + border-style: solid; |
| 89 | + border-width: 9px 3px 0 3px; |
| 90 | + border-color: #2b2b2b transparent transparent transparent; |
| 91 | + transform-origin: center 21px; |
| 92 | + position: absolute; |
63 | 93 | } |
64 | 94 |
|
| 95 | +#status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); } |
| 96 | +#status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); } |
| 97 | +#status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); } |
| 98 | +#status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); } |
| 99 | +#status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); } |
| 100 | +#status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); } |
| 101 | +#status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); } |
| 102 | +#status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); } |
| 103 | + |
65 | 104 | #status-notice { |
66 | | - background-color: #5b3943; |
67 | | - border-radius: 0.5rem; |
68 | | - border: 1px solid #9b3943; |
69 | | - color: #e0e0e0; |
70 | | - font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif; |
| 105 | + margin: 0 100px; |
71 | 106 | line-height: 1.3; |
72 | | - margin: 0 2rem; |
73 | | - overflow: hidden; |
74 | | - padding: 1rem; |
75 | | - text-align: center; |
76 | | - z-index: 1; |
| 107 | + visibility: visible; |
| 108 | + padding: 4px 6px; |
| 109 | + visibility: visible; |
77 | 110 | } |
78 | 111 | </style> |
79 | | - <link id="-gd-engine-icon" rel="icon" type="image/png" href="index.icon.png" /> |
80 | | -<link rel="apple-touch-icon" href="index.apple-touch-icon.png"/> |
| 112 | + <link id='-gd-engine-icon' rel='icon' type='image/png' href='index.icon.png' /> |
| 113 | +<link rel='apple-touch-icon' href='index.apple-touch-icon.png'/> |
81 | 114 |
|
82 | 115 | </head> |
83 | 116 | <body> |
84 | 117 | <canvas id="canvas"> |
85 | | - Your browser does not support the canvas tag. |
| 118 | + HTML5 canvas appears to be unsupported in the current browser.<br > |
| 119 | + Please try updating or use a different browser. |
86 | 120 | </canvas> |
87 | | - |
88 | | - <noscript> |
89 | | - Your browser does not support JavaScript. |
90 | | - </noscript> |
91 | | - |
92 | 121 | <div id="status"> |
93 | | - <img id="status-splash" src="index.png" alt=""> |
94 | | - <progress id="status-progress"></progress> |
95 | | - <div id="status-notice"></div> |
| 122 | + <div id="status-progress" style="display: none;" oncontextmenu="event.preventDefault();"> |
| 123 | + <div id ="status-progress-inner"></div> |
| 124 | + </div> |
| 125 | + <div id="status-indeterminate" style="display: none;" oncontextmenu="event.preventDefault();"> |
| 126 | + <div></div> |
| 127 | + <div></div> |
| 128 | + <div></div> |
| 129 | + <div></div> |
| 130 | + <div></div> |
| 131 | + <div></div> |
| 132 | + <div></div> |
| 133 | + <div></div> |
| 134 | + </div> |
| 135 | + <div id="status-notice" class="godot" style="display: none;"></div> |
96 | 136 | </div> |
97 | 137 |
|
98 | 138 | <script src="index.js"></script> |
99 | 139 | <script> |
100 | | -const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":true,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":17896608,"index.wasm":43016933},"focusCanvas":true,"gdextensionLibs":[]}; |
101 | | -const GODOT_THREADS_ENABLED = false; |
| 140 | +const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":23273104,"index.wasm":35708238},"focusCanvas":true,"gdextensionLibs":[]}; |
102 | 141 | const engine = new Engine(GODOT_CONFIG); |
103 | 142 |
|
104 | 143 | (function () { |
105 | | - const statusOverlay = document.getElementById('status'); |
| 144 | + const INDETERMINATE_STATUS_STEP_MS = 100; |
106 | 145 | const statusProgress = document.getElementById('status-progress'); |
| 146 | + const statusProgressInner = document.getElementById('status-progress-inner'); |
| 147 | + const statusIndeterminate = document.getElementById('status-indeterminate'); |
107 | 148 | const statusNotice = document.getElementById('status-notice'); |
108 | 149 |
|
109 | 150 | let initializing = true; |
110 | | - let statusMode = ''; |
| 151 | + let statusMode = 'hidden'; |
| 152 | + |
| 153 | + let animationCallbacks = []; |
| 154 | + function animate(time) { |
| 155 | + animationCallbacks.forEach((callback) => callback(time)); |
| 156 | + requestAnimationFrame(animate); |
| 157 | + } |
| 158 | + requestAnimationFrame(animate); |
| 159 | + |
| 160 | + function animateStatusIndeterminate(ms) { |
| 161 | + const i = Math.floor((ms / INDETERMINATE_STATUS_STEP_MS) % 8); |
| 162 | + if (statusIndeterminate.children[i].style.borderTopColor === '') { |
| 163 | + Array.prototype.slice.call(statusIndeterminate.children).forEach((child) => { |
| 164 | + child.style.borderTopColor = ''; |
| 165 | + }); |
| 166 | + statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf'; |
| 167 | + } |
| 168 | + } |
111 | 169 |
|
112 | 170 | function setStatusMode(mode) { |
113 | 171 | if (statusMode === mode || !initializing) { |
114 | 172 | return; |
115 | 173 | } |
116 | | - if (mode === 'hidden') { |
117 | | - statusOverlay.remove(); |
118 | | - initializing = false; |
119 | | - return; |
| 174 | + [statusProgress, statusIndeterminate, statusNotice].forEach((elem) => { |
| 175 | + elem.style.display = 'none'; |
| 176 | + }); |
| 177 | + animationCallbacks = animationCallbacks.filter(function (value) { |
| 178 | + return (value !== animateStatusIndeterminate); |
| 179 | + }); |
| 180 | + switch (mode) { |
| 181 | + case 'progress': |
| 182 | + statusProgress.style.display = 'block'; |
| 183 | + break; |
| 184 | + case 'indeterminate': |
| 185 | + statusIndeterminate.style.display = 'block'; |
| 186 | + animationCallbacks.push(animateStatusIndeterminate); |
| 187 | + break; |
| 188 | + case 'notice': |
| 189 | + statusNotice.style.display = 'block'; |
| 190 | + break; |
| 191 | + case 'hidden': |
| 192 | + break; |
| 193 | + default: |
| 194 | + throw new Error('Invalid status mode'); |
120 | 195 | } |
121 | | - statusOverlay.style.visibility = 'visible'; |
122 | | - statusProgress.style.display = mode === 'progress' ? 'block' : 'none'; |
123 | | - statusNotice.style.display = mode === 'notice' ? 'block' : 'none'; |
124 | 196 | statusMode = mode; |
125 | 197 | } |
126 | 198 |
|
|
136 | 208 | } |
137 | 209 |
|
138 | 210 | function displayFailureNotice(err) { |
139 | | - console.error(err); |
140 | | - if (err instanceof Error) { |
141 | | - setStatusNotice(err.message); |
142 | | - } else if (typeof err === 'string') { |
143 | | - setStatusNotice(err); |
144 | | - } else { |
145 | | - setStatusNotice('An unknown error occured'); |
146 | | - } |
| 211 | + const msg = err.message || err; |
| 212 | + console.error(msg); |
| 213 | + setStatusNotice(msg); |
147 | 214 | setStatusMode('notice'); |
148 | 215 | initializing = false; |
149 | 216 | } |
150 | 217 |
|
151 | | - const missing = Engine.getMissingFeatures({ |
152 | | - threads: GODOT_THREADS_ENABLED, |
153 | | - }); |
154 | | - |
| 218 | + const missing = Engine.getMissingFeatures(); |
155 | 219 | if (missing.length !== 0) { |
156 | | - if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) { |
157 | | - // There's a chance that installing the service worker would fix the issue |
158 | | - Promise.race([ |
159 | | - navigator.serviceWorker.getRegistration().then((registration) => { |
160 | | - if (registration != null) { |
161 | | - return Promise.reject(new Error('Service worker already exists.')); |
162 | | - } |
163 | | - return registration; |
164 | | - }).then(() => engine.installServiceWorker()), |
165 | | - // For some reason, `getRegistration()` can stall |
166 | | - new Promise((resolve) => { |
167 | | - setTimeout(() => resolve(), 2000); |
168 | | - }), |
169 | | - ]).catch((err) => { |
170 | | - console.error('Error while registering service worker:', err); |
171 | | - }).then(() => { |
172 | | - window.location.reload(); |
173 | | - }); |
174 | | - } else { |
175 | | - // Display the message as usual |
176 | | - const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n'; |
177 | | - displayFailureNotice(missingMsg + missing.join('\n')); |
178 | | - } |
| 220 | + const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n'; |
| 221 | + displayFailureNotice(missingMsg + missing.join('\n')); |
179 | 222 | } else { |
180 | | - setStatusMode('progress'); |
| 223 | + setStatusMode('indeterminate'); |
181 | 224 | engine.startGame({ |
182 | 225 | 'onProgress': function (current, total) { |
183 | | - if (current > 0 && total > 0) { |
184 | | - statusProgress.value = current; |
185 | | - statusProgress.max = total; |
| 226 | + if (total > 0) { |
| 227 | + statusProgressInner.style.width = `${(current / total) * 100}%`; |
| 228 | + setStatusMode('progress'); |
| 229 | + if (current === total) { |
| 230 | + // wait for progress bar animation |
| 231 | + setTimeout(() => { |
| 232 | + setStatusMode('indeterminate'); |
| 233 | + }, 500); |
| 234 | + } |
186 | 235 | } else { |
187 | | - statusProgress.removeAttribute('value'); |
188 | | - statusProgress.removeAttribute('max'); |
| 236 | + setStatusMode('indeterminate'); |
189 | 237 | } |
190 | 238 | }, |
191 | 239 | }).then(() => { |
192 | 240 | setStatusMode('hidden'); |
| 241 | + initializing = false; |
193 | 242 | }, displayFailureNotice); |
194 | 243 | } |
195 | 244 | }()); |
|
0 commit comments