feat(store): serve stock artwork and link official store media
Show the installed game artwork in the local store and marketplace. Use the official cover and gallery for each mapped product, with on-demand video playback. Include store cover images and screenshots in optional offline asset packs. Verified TypeScript, browser script syntax, local service startup, game artwork endpoints, a sample image pack, and BMD-4M WebM byte-range delivery. In-game verification is pending.
This commit is contained in:
1 parent
2dda694db0
commit
3c1210f249
14 files changed
+2580
-91
No files matched your search
@@ -13,6 +13,7 @@ const T = {
|
||||
buy: '购买', freeBuy: '老福爷付过了', owned: '已拥有', pickAccount: '请先在右上角选择账号', redeem: '兑换', codePlaceholder: '输入兑换码',
|
||||
empty: '没有符合条件的商品', includes: '本特惠包包含', back: '‹ 返回目录', bonusTitle: 'Premium bonuses', bonusText: '高级载具获得的银狮与研发点有加成,并可直接使用。',
|
||||
footer: 'WTOffline 本地商店 · 买完关闭本窗口,机库会自动刷新', badgeOwned: '已拥有', badgeHot: '人气商品',
|
||||
cover: '封面', screenshot: '截图 {index}', video: '演示视频', videoNumber: '演示视频 {index}', videoUnavailable: '暂时无法播放官方视频。',
|
||||
},
|
||||
en: {
|
||||
store: 'Store', toMarket: 'Market', eagles: 'Golden Eagles', lions: 'Silver Lions', premium: 'Premium', premiumOff: 'inactive', premiumLeft: '{days} days left',
|
||||
@@ -22,6 +23,7 @@ const T = {
|
||||
buy: 'Buy', freeBuy: '老福爷付过了', owned: 'Owned', pickAccount: 'Pick an account at the top right', redeem: 'Redeem', codePlaceholder: 'Enter a code',
|
||||
empty: 'Nothing matches the filters', includes: 'This pack includes', back: '‹ Back to catalog', bonusTitle: 'Premium bonuses', bonusText: 'Premium vehicles earn more Silver Lions and research points and are ready to use.',
|
||||
footer: 'WTOffline local store · close this window after buying to refresh the hangar', badgeOwned: 'Owned', badgeHot: 'Best seller',
|
||||
cover: 'Cover', screenshot: 'Screenshot {index}', video: 'Demo video', videoNumber: 'Demo video {index}', videoUnavailable: 'The official video is unavailable.',
|
||||
},
|
||||
};
|
||||
const ROMAN = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X'];
|
||||
@@ -82,6 +84,7 @@ function matches(product) {
|
||||
}
|
||||
|
||||
function render() {
|
||||
stopProductVideo($('detail').querySelector('video'));
|
||||
for (const tab of document.querySelectorAll('.snav-item')) tab.classList.toggle('active', tab.dataset.tab === currentTab);
|
||||
const product = detailId && state.products.find((p) => p.id === detailId);
|
||||
$('redeemPanel').hidden = currentTab !== 'redeem';
|
||||
@@ -100,9 +103,92 @@ function render() {
|
||||
for (const item of items) grid.appendChild(productCard(item));
|
||||
}
|
||||
|
||||
function productImage(product, className) {
|
||||
if (product.unitName) return WtoUi.vehicleImg(product.unitName, className);
|
||||
return WtoUi.storeImg(product.guid, '', className ? className + ' cover' : 'cover');
|
||||
function productArtwork(product) {
|
||||
const group = product.artworkGroup ? [WtoUi.artworkUrl('group', product.artworkGroup)] : [];
|
||||
const image = product.unitName ? WtoUi.artworkUrl('vehicle', product.unitName) : WtoUi.artworkUrl('product', product.kind);
|
||||
return [...group, image];
|
||||
}
|
||||
|
||||
function productImage(product) {
|
||||
const { cover } = WtoUi.storeMedia(product.id);
|
||||
const urls = product.unitName ? [cover, ...WtoUi.vehicleUrls(product.unitName)] : [cover];
|
||||
return WtoUi.tieredImg(urls, productArtwork(product), '');
|
||||
}
|
||||
|
||||
function stopProductVideo(video) {
|
||||
if (!video) return;
|
||||
video.onerror = null;
|
||||
video.pause();
|
||||
video.remove();
|
||||
video.removeAttribute('src');
|
||||
video.load();
|
||||
}
|
||||
|
||||
function showPackVideo(media, status, product, urls) {
|
||||
const player = document.createElement('video');
|
||||
player.controls = true;
|
||||
player.playsInline = true;
|
||||
player.preload = 'metadata';
|
||||
const sources = urls.filter((url) => player.canPlayType(url.endsWith('.webm') ? 'video/webm' : 'video/mp4'));
|
||||
let timer;
|
||||
|
||||
function next() {
|
||||
clearTimeout(timer);
|
||||
if (player.parentNode !== media) return;
|
||||
const url = sources.shift();
|
||||
if (!url) {
|
||||
stopProductVideo(player);
|
||||
media.replaceChildren(productImage(product));
|
||||
status.textContent = t('videoUnavailable');
|
||||
status.hidden = false;
|
||||
return;
|
||||
}
|
||||
player.src = url;
|
||||
timer = setTimeout(next, 4500);
|
||||
void player.play().catch(() => {});
|
||||
}
|
||||
|
||||
player.onerror = next;
|
||||
player.onloadedmetadata = () => clearTimeout(timer);
|
||||
media.replaceChildren(player);
|
||||
next();
|
||||
}
|
||||
|
||||
function renderProductMedia(detail, product) {
|
||||
const media = detail.querySelector('.media');
|
||||
const status = detail.querySelector('.media-status');
|
||||
const toolbar = detail.querySelector('.thumbs');
|
||||
const { screenshots, videos } = WtoUi.storeMedia(product.id);
|
||||
let selected;
|
||||
|
||||
function addChoice(label, show) {
|
||||
const button = Object.assign(document.createElement('button'), { type: 'button', textContent: label });
|
||||
button.setAttribute('aria-pressed', 'false');
|
||||
button.onclick = () => {
|
||||
stopProductVideo(media.querySelector('video'));
|
||||
selected?.setAttribute('aria-pressed', 'false');
|
||||
selected = button;
|
||||
button.setAttribute('aria-pressed', 'true');
|
||||
status.hidden = true;
|
||||
show();
|
||||
};
|
||||
toolbar.appendChild(button);
|
||||
return button;
|
||||
}
|
||||
|
||||
const cover = addChoice(t('cover'), () => media.replaceChildren(productImage(product)));
|
||||
screenshots.forEach((url, index) => {
|
||||
addChoice(t('screenshot', { index: index + 1 }), () => media.replaceChildren(WtoUi.tieredImg([url], productArtwork(product), '')));
|
||||
});
|
||||
for (const vehicle of product.vehicles || []) {
|
||||
addChoice(WtoUi.text(vehicle.title), () => media.replaceChildren(WtoUi.vehicleImg(vehicle.unitName, '')));
|
||||
}
|
||||
videos.forEach((sources, index) => {
|
||||
const label = videos.length === 1 ? t('video') : t('videoNumber', { index: index + 1 });
|
||||
addChoice(label, () => showPackVideo(media, status, product, sources));
|
||||
});
|
||||
toolbar.hidden = toolbar.childElementCount <= 1;
|
||||
cover.click();
|
||||
}
|
||||
|
||||
function contentsOf(product) {
|
||||
@@ -127,7 +213,7 @@ function productCard(product) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'pw';
|
||||
card.innerHTML = '<div class="pw-poster"></div><div class="pw-desc"><div class="pw-game">War Thunder</div><div class="pw-title"></div><div class="pw-comment"></div><ul class="pw-contents"></ul></div><div class="pw-price"></div><div class="pw-buy"></div>';
|
||||
card.querySelector('.pw-poster').appendChild(productImage(product, ''));
|
||||
card.querySelector('.pw-poster').appendChild(productImage(product));
|
||||
if (product.owned) card.querySelector('.pw-poster').appendChild(Object.assign(document.createElement('div'), { className: 'badge owned', textContent: t('badgeOwned') }));
|
||||
card.querySelector('.pw-title').textContent = WtoUi.text(product.title);
|
||||
if (product.country) {
|
||||
@@ -145,20 +231,13 @@ function productCard(product) {
|
||||
|
||||
function renderDetail(product) {
|
||||
const detail = $('detail');
|
||||
detail.innerHTML = '<span class="back"></span><h1></h1><div class="detail-cols"><div class="detail-left"><div class="media"></div><div class="thumbs"></div>'
|
||||
detail.innerHTML = '<span class="back"></span><h1></h1><div class="detail-cols"><div class="detail-left"><div class="media"></div><div class="thumbs"></div><p class="media-status" role="status" hidden></p>'
|
||||
+ '<h2></h2><div class="bonus"><h3></h3><div></div></div></div><div class="detail-right"><div class="buy-panel"><div class="price"></div><div class="btns"></div>'
|
||||
+ '<div class="includes"><h4></h4><ul></ul></div></div></div></div>';
|
||||
detail.querySelector('.back').textContent = t('back');
|
||||
detail.querySelector('.back').onclick = () => { detailId = ''; render(); };
|
||||
detail.querySelector('h1').textContent = WtoUi.text(product.title);
|
||||
const media = detail.querySelector('.media');
|
||||
media.appendChild(productImage(product, ''));
|
||||
const thumbs = detail.querySelector('.thumbs');
|
||||
for (const v of product.vehicles || []) {
|
||||
const thumb = WtoUi.vehicleImg(v.unitName, v.unitName === product.unitName ? 'active' : '');
|
||||
thumb.onclick = () => { media.innerHTML = ''; media.appendChild(WtoUi.vehicleImg(v.unitName, '')); };
|
||||
thumbs.appendChild(thumb);
|
||||
}
|
||||
renderProductMedia(detail, product);
|
||||
detail.querySelector('.detail-left h2').textContent = product.vehicles ? product.vehicles.map((v) => WtoUi.text(v.title)).join(' / ') : WtoUi.text(product.title);
|
||||
detail.querySelector('.bonus h3').textContent = t('bonusTitle');
|
||||
detail.querySelector('.bonus div').textContent = t('bonusText');
|
||||
@@ -210,4 +289,4 @@ $('tabs').onclick = (event) => {
|
||||
};
|
||||
|
||||
applyStaticTexts();
|
||||
Promise.all([WtoUi.loadLabels(), WtoUi.loadImageSources()]).then(() => loadState(WtoUi.savedAccount()));
|
||||
Promise.all([WtoUi.loadLabels(), WtoUi.loadImageSources(true)]).then(() => loadState(WtoUi.savedAccount()));
|
||||
@@ -2,6 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="referrer" content="no-referrer" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Gaijin.Net Store · WTOffline</title>
|
||||
<link rel="stylesheet" href="/store/styles.css" />
|
||||
|
||||
@@ -36,8 +36,7 @@ body { background: var(--navy-40) linear-gradient(180deg, #1b2530 0%, #27323f 42
|
||||
.pw { position: relative; display: flex; flex-direction: column; height: 344px; background: var(--navy-60); overflow: hidden; cursor: pointer; transition: transform 0.3s; }
|
||||
.pw:hover { transform: translateY(-3px); }
|
||||
.pw-poster { position: relative; height: 162px; display: flex; align-items: center; justify-content: center; background: linear-gradient(180deg, #33475a, var(--navy-60)); }
|
||||
.pw-poster img { max-width: 92%; max-height: 92%; object-fit: contain; }
|
||||
.pw-poster img.cover { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: cover; }
|
||||
.pw-poster img { width: 92%; height: 92%; object-fit: contain; }
|
||||
.badge { position: absolute; left: 0; right: 0; top: 0; height: 30px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; color: #fff; font-size: 14px; text-transform: uppercase; background: linear-gradient(90deg, #0050e0, #1a8cff); }
|
||||
.badge.owned { background: linear-gradient(90deg, #3a8a2a, #6cc04a); }
|
||||
.pw-desc { flex: 1; padding: 10px 14px 0; min-height: 0; overflow: hidden; }
|
||||
@@ -60,11 +59,12 @@ body { background: var(--navy-40) linear-gradient(180deg, #1b2530 0%, #27323f 42
|
||||
.detail-cols { display: flex; gap: 24px; align-items: flex-start; }
|
||||
.detail-left { flex: 1; min-width: 0; }
|
||||
.media { height: 452px; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 40%, #3a4d60, #1b2633 75%); }
|
||||
.media img { max-width: 90%; max-height: 90%; object-fit: contain; }
|
||||
.media img.cover { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: cover; }
|
||||
.thumbs { display: flex; gap: 8px; padding: 8px 0; }
|
||||
.thumbs img { width: 132px; height: 85px; object-fit: contain; background: #1b2633; border: 2px solid transparent; cursor: pointer; }
|
||||
.thumbs img.active { border-color: #f9ae3d; }
|
||||
.media img, .media video { width: 100%; height: 100%; object-fit: contain; }
|
||||
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0; }
|
||||
.thumbs[hidden] { display: none; }
|
||||
.thumbs button { padding: 6px 12px; background: #1b2633; color: var(--text); border: 1px solid #425367; cursor: pointer; }
|
||||
.thumbs button[aria-pressed='true'] { border-color: #f9ae3d; }
|
||||
.media-status { margin: 0; color: var(--muted); }
|
||||
.detail-left h2 { color: #fff; font-size: 32px; font-weight: 300; margin: 24px 0 8px; }
|
||||
.bonus { margin-top: 24px; padding: 28px 32px; background: linear-gradient(90deg, #5c5030, #e8d08a); color: #3a2a10; }
|
||||
.bonus h3 { margin: 0 0 8px; font-size: 32px; text-transform: uppercase; }
|
||||
|
||||
Reference in new issue
Block a user