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