sounds
This commit is contained in:
parent
c6ba3e38a2
commit
37087d08a7
189 changed files with 12864 additions and 9589 deletions
61
js/main.js
61
js/main.js
|
|
@ -7,6 +7,54 @@ let perfResizeTimer = 0;
|
|||
let lastPerfLevel = 0;
|
||||
window.__tarinaiFps = 0;
|
||||
|
||||
const LOADING_SPRITES = [
|
||||
"assets/sprites/tarinai_01_smile.webp",
|
||||
"assets/sprites/tarinai_02_angry.webp",
|
||||
"assets/sprites/tarinai_03_teary.webp",
|
||||
"assets/sprites/tarinai_04_jito.webp",
|
||||
"assets/sprites/tarinai_05_drool.webp",
|
||||
"assets/sprites/tarinai_06_cry.webp",
|
||||
"assets/sprites/tarinai_07_sleep.webp",
|
||||
"assets/sprites/tarinai_08_pokan.webp",
|
||||
"assets/sprites/tarinai_11_weak.webp",
|
||||
"assets/sprites/tarinai_21_normal_happy.webp",
|
||||
];
|
||||
let loadingSpriteTimer = 0;
|
||||
|
||||
function shuffledLoadingSprites() {
|
||||
const list = [...LOADING_SPRITES];
|
||||
for (let i = list.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[list[i], list[j]] = [list[j], list[i]];
|
||||
}
|
||||
return list.slice(0, 4);
|
||||
}
|
||||
|
||||
function renderLoadingSprites() {
|
||||
const strip = document.getElementById("loadingSpriteStrip");
|
||||
if (!strip) return;
|
||||
strip.innerHTML = "";
|
||||
const frag = document.createDocumentFragment();
|
||||
for (const src of shuffledLoadingSprites()) {
|
||||
const card = document.createElement("div");
|
||||
card.className = "loading-sprite-card";
|
||||
const img = document.createElement("img");
|
||||
img.src = src;
|
||||
img.alt = "";
|
||||
img.loading = "eager";
|
||||
card.appendChild(img);
|
||||
frag.appendChild(card);
|
||||
}
|
||||
strip.appendChild(frag);
|
||||
}
|
||||
|
||||
function initLoadingShowcase() {
|
||||
renderLoadingSprites();
|
||||
if (loadingSpriteTimer) clearInterval(loadingSpriteTimer);
|
||||
loadingSpriteTimer = window.setInterval(renderLoadingSprites, 1200);
|
||||
}
|
||||
|
||||
|
||||
function setLoadingProgress(text = "", ratio = 0) {
|
||||
const screen = document.getElementById("loadingScreen");
|
||||
if (!screen) return;
|
||||
|
|
@ -20,6 +68,7 @@ function setLoadingProgress(text = "", ratio = 0) {
|
|||
}
|
||||
|
||||
function hideLoadingScreen() {
|
||||
if (loadingSpriteTimer) { clearInterval(loadingSpriteTimer); loadingSpriteTimer = 0; }
|
||||
setLoadingProgress("\u8d77\u52d5\u5b8c\u4e86", 1);
|
||||
const screen = document.getElementById("loadingScreen");
|
||||
if (!screen) return;
|
||||
|
|
@ -34,6 +83,7 @@ function loop() {
|
|||
fpsFrames += 1;
|
||||
if (fpsTimer >= 0.5) {
|
||||
window.__tarinaiFps = Math.round(fpsFrames / Math.max(fpsTimer, 0.001));
|
||||
window.TarinaiPerformance?.updateFps?.(window.__tarinaiFps, world);
|
||||
fpsTimer = 0;
|
||||
fpsFrames = 0;
|
||||
}
|
||||
|
|
@ -49,7 +99,7 @@ function loop() {
|
|||
}
|
||||
perfResizeTimer = 0;
|
||||
}
|
||||
const statsInterval = perf >= 3 ? 1.20 : perf === 2 ? 0.92 : perf === 1 ? 0.68 : 0.48;
|
||||
const statsInterval = world.performanceQuality?.().statsInterval ?? (perf >= 3 ? 1.20 : perf === 2 ? 0.92 : perf === 1 ? 0.68 : 0.48);
|
||||
if (statsTimer > statsInterval) {
|
||||
renderStats();
|
||||
statsTimer = 0;
|
||||
|
|
@ -57,6 +107,7 @@ function loop() {
|
|||
requestAnimationFrame(loop);
|
||||
}
|
||||
|
||||
initLoadingShowcase();
|
||||
setLoadingProgress("\u521d\u671f\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\u4e2d", 0.08);
|
||||
loadImages(null, (done, total) => {
|
||||
const p = total > 0 ? done / total : 1;
|
||||
|
|
@ -79,3 +130,11 @@ loadImages(null, (done, total) => {
|
|||
loop();
|
||||
requestAnimationFrame(hideLoadingScreen);
|
||||
});
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
const swUrl = window.TARINAI_APP?.withVersion?.("./service-worker.js") || "./service-worker.js?v=15.19.1";
|
||||
navigator.serviceWorker.register(swUrl, { updateViaCache: "none" }).catch(() => undefined);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue