|
25 | 25 | left: 0; |
26 | 26 | width: 100vw; |
27 | 27 | height: 100vh; |
28 | | - //background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%); |
29 | 28 | background: linear-gradient(135deg, #0a0a0a 0%, #202020 100%); |
30 | 29 | display: flex; |
31 | 30 | flex-direction: column; |
|
114 | 113 | const progressBar = document.getElementById('progress-bar'); |
115 | 114 | const progressText = document.getElementById('progress-text'); |
116 | 115 | const loadingScreen = document.getElementById('loading-screen'); |
| 116 | + let progs = {} |
117 | 117 |
|
118 | 118 | function updateProgress(progress, text) { |
119 | 119 | progressBar.style.width = (progress * 100) + '%'; |
|
125 | 125 | setTimeout(() => { loadingScreen.style.display = 'none'; }, 500); |
126 | 126 | } |
127 | 127 |
|
128 | | - async function fetchBlock(url, text, startProgress, stepProgress) { |
| 128 | + async function fetchBlock(url, text) { |
129 | 129 | let response = await fetch(url); |
130 | 130 | const reader = response.body.getReader(); |
131 | 131 | const contentLength = +response.headers.get('Content-Length'); |
|
136 | 136 | break; |
137 | 137 | } |
138 | 138 | receivedLength += value.length; |
139 | | - const progress = startProgress + (receivedLength / contentLength) * stepProgress; |
140 | | - updateProgress(progress, text) |
| 139 | + progs[url] = receivedLength / contentLength; |
| 140 | + const minimalProgress = Math.min(...Object.values(progs)) |
| 141 | + updateProgress(minimalProgress, text) |
141 | 142 | } |
142 | 143 | } |
143 | 144 |
|
144 | 145 | updateProgress(0, 'Loading kool...'); |
145 | 146 |
|
146 | 147 | // Fetch essential files tracking progress before actually loading them - will be loaded from cache afterwards |
147 | | - await fetchBlock('kool-demo.js', 'Loading kool...', 0, 0.4) |
148 | | - await fetchBlock('assets/fonts/fira-sans-regular.png', 'Loading fonts...', 0.4, 0.6) |
149 | | - await fetchBlock('4ab48fc16bcbc6611bb2.wasm', 'Loading PhysX...', 0.6, 1.0) |
| 148 | + fetchBlock('kool-demo.js', 'Loading kool...') |
| 149 | + fetchBlock('assets/fonts/fira-sans-regular.png', 'Loading kool...') |
| 150 | + fetchBlock('4ab48fc16bcbc6611bb2.wasm', 'Loading kool...') |
150 | 151 |
|
151 | 152 | const script = document.createElement('script'); |
152 | 153 | script.src = 'kool-demo.js'; |
|
0 commit comments