Refresh the storefront and autoplay pack demos

Cache allowlisted official media so the in-game browser can load it locally. Match the official catalog snapshot and start pack demos muted and looping on entry.
This commit is contained in:
N0VAN0M4LY committed 2026-11-27 00:43:50 +08:00
1 parent 81e3add520
commit aa272fc82b
14 files changed
+645 -140

No files matched your search

+55 -16
View File
@@ -1,4 +1,4 @@
// Image gallery and on-demand playback for public demo clips.
// Images and demo clips for pack details.
'use strict';
const galleryPlayers = new WeakMap();
@@ -18,7 +18,7 @@ function galleryItems(product) {
sources,
}));
screenshots.forEach((url, index) => {
entries.push({ label: t('screenshot', { index: index + 1 }), image: () => WtoUi.tieredImg([url], [], ''), screenshot: true });
entries.push({ label: t('screenshot', { index: index + 1 }), screenshot: url });
});
entries.push({ label: t('cover'), image: cover });
if (product.vehicles && (videos.length || screenshots.length || product.vehicles.length > 1)) {
@@ -29,11 +29,17 @@ function galleryItems(product) {
return entries;
}
function playStoreClip(stage, sources, poster, onReady, onUnavailable) {
function playStoreClip(stage, sources, poster, autoplay, onReady, onUnavailable) {
galleryPlayers.get(stage)?.();
const video = document.createElement('video');
video.controls = true;
video.playsInline = true;
if (autoplay) {
video.autoplay = true;
video.defaultMuted = true;
video.muted = true;
video.loop = true;
}
if (poster) video.poster = poster;
const playable = sources.filter((url) => video.canPlayType(/\.webm(?:$|\?)/i.test(url) ? 'video/webm' : 'video/mp4'));
let nextSource = 0;
@@ -58,7 +64,7 @@ function playStoreClip(stage, sources, poster, onReady, onUnavailable) {
return;
}
video.src = url;
timer = setTimeout(attempt, 5500);
timer = setTimeout(attempt, 23_000);
void video.play().catch(() => {});
}
@@ -72,18 +78,21 @@ function playStoreClip(stage, sources, poster, onReady, onUnavailable) {
attempt();
}
function appendGalleryImage(container, item, placeholder) {
const image = item.image();
if (item.screenshot && !image.naturalWidth) {
const pending = makeElement('span', 'media-placeholder', placeholder);
image.addEventListener('load', () => pending.remove(), { once: true });
container.append(pending);
}
function appendScreenshot(container, item, loaded, eager = false) {
const image = makeElement('img', 'gallery-screenshot');
image.alt = eager ? item.label : '';
image.loading = eager ? 'eager' : 'lazy';
image.onload = () => {
image.classList.add('ready');
loaded(true);
};
image.onerror = () => loaded(false);
image.src = item.screenshot;
container.append(image);
return image;
}
function mountStoreGallery(root, product) {
function mountStoreGallery(root, product, autoplay) {
const items = galleryItems(product);
root.innerHTML = '<div class="media-stage"></div><div class="media-navigation"><button type="button">‹</button>'
+ '<div class="media-thumbs"></div><button type="button">›</button></div>'
@@ -100,21 +109,43 @@ function mountStoreGallery(root, product) {
function showImage(item, showPlay) {
stage.replaceChildren();
const image = appendGalleryImage(stage, item, t('screenshotPending'));
if (item.screenshot) {
showScreenshot(item);
return;
}
const image = item.image();
image.loading = 'eager';
image.alt = item.label;
stage.append(image);
if (!showPlay) return;
const play = storeButton('media-play', '▶ ' + t('playVideo'));
play.onclick = () => playItem(item);
stage.append(play);
}
function playItem(item) {
function showScreenshot(item) {
const gameArt = WtoUi.tieredImg([], productArtwork(product), '');
gameArt.loading = 'eager';
stage.append(gameArt);
status.textContent = t('screenshotLoading');
status.hidden = false;
const image = appendScreenshot(stage, item, (ok) => {
if (image.parentNode !== stage) return;
if (ok) {
gameArt.remove();
status.hidden = true;
} else {
status.textContent = t('screenshotUnavailable');
}
}, true);
}
function playItem(item, autoplay = false) {
const image = stage.querySelector('img');
const poster = image?.currentSrc || image?.getAttribute('src');
status.textContent = t('videoLoading');
status.hidden = false;
playStoreClip(stage, item.sources, poster, () => { status.hidden = true; }, () => {
playStoreClip(stage, item.sources, poster, autoplay, () => { status.hidden = true; }, () => {
showImage(item, true);
status.textContent = t('videoUnavailable');
status.hidden = false;
@@ -144,7 +175,13 @@ function mountStoreGallery(root, product) {
button.setAttribute('aria-label', item.label);
button.setAttribute('aria-pressed', 'false');
button.title = item.label;
appendGalleryImage(button, item, item.label);
if (item.screenshot) {
const label = makeElement('span', 'media-placeholder', item.label);
button.append(label);
appendScreenshot(button, item, (ok) => { if (ok) label.remove(); });
} else {
button.append(item.image());
}
if (item.sources) button.append(makeElement('span', 'thumb-play', '▶'));
button.onclick = () => select(index, true);
return button;
@@ -162,4 +199,6 @@ function mountStoreGallery(root, product) {
};
nav.hidden = caption.hidden = items.length === 1;
select(0, false, false);
const initial = items[0];
if (autoplay && initial.sources) playItem(initial, true);
}