chore(battle): snapshot the LocalMP rework baseline

Records the uncommitted battle-session work exactly as it was left
(local service matchmaking, settlement, chat, native LocalMP hooks,
battle gui/exe patches) so the following review and rework commits
show every correction as a diff against this state.

This commit is not reviewed and is known to be incomplete: in-game
testing reported wrong settlement rewards, single-country teams,
missing random/fixed supplement slots, misattributed hit messages and
other regressions. Do not merge this branch before the rework lands.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 03:15:47 +08:00
1 parent 5c9204c031
commit b260d2899e
97 files changed
+7676 -396

No files matched your search

+115 -89
View File
@@ -2,6 +2,7 @@
'use strict';
const galleryPlayers = new WeakMap();
const CLIP_TIMEOUT_MS = 23_000;
function stopStoreGallery(root) {
const stage = root.querySelector('.media-stage');
@@ -29,8 +30,7 @@ function galleryItems(product) {
return entries;
}
function playStoreClip(stage, sources, poster, autoplay, onReady, onUnavailable) {
galleryPlayers.get(stage)?.();
function createClipVideoElement(poster, autoplay) {
const video = document.createElement('video');
video.controls = true;
video.playsInline = true;
@@ -41,6 +41,12 @@ function playStoreClip(stage, sources, poster, autoplay, onReady, onUnavailable)
video.loop = true;
}
if (poster) video.poster = poster;
return video;
}
function playStoreClip(stage, sources, poster, autoplay, onReady, onUnavailable) {
galleryPlayers.get(stage)?.();
const video = createClipVideoElement(poster, autoplay);
const playable = sources.filter((url) => video.canPlayType(/\.webm(?:$|\?)/i.test(url) ? 'video/webm' : 'video/mp4'));
let nextSource = 0;
let timer;
@@ -64,34 +70,125 @@ function playStoreClip(stage, sources, poster, autoplay, onReady, onUnavailable)
return;
}
video.src = url;
timer = setTimeout(attempt, 23_000);
timer = setTimeout(attempt, CLIP_TIMEOUT_MS);
void video.play().catch(() => {});
}
video.onerror = attempt;
video.oncanplay = () => {
clearTimeout(timer);
onReady();
};
video.oncanplay = () => { clearTimeout(timer); onReady(); };
stage.replaceChildren(video);
galleryPlayers.set(stage, dispose);
attempt();
}
function appendScreenshot(container, item, loaded, eager = false) {
const candidates = storeImageCandidates(item.screenshot);
const image = makeElement('img', 'gallery-screenshot');
image.alt = eager ? item.label : '';
image.loading = eager ? 'eager' : 'lazy';
image.crossOrigin = 'anonymous';
image.referrerPolicy = 'no-referrer';
let index = 0;
function tryNext() {
const nextUrl = candidates[index++];
if (!nextUrl) {
image.onload = image.onerror = null;
image.remove();
loaded(false);
return;
}
image.src = nextUrl;
}
image.onload = () => {
image.onload = image.onerror = null;
image.classList.add('ready');
loaded(true);
};
image.onerror = () => loaded(false);
image.src = item.screenshot;
image.onerror = tryNext;
container.append(image);
tryNext();
return image;
}
function renderStageScreenshot(stage, status, product, 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 renderStageMedia(stage, status, product, item, showPlay, onPlay) {
stage.replaceChildren();
if (item.screenshot) {
renderStageScreenshot(stage, status, product, 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 = () => onPlay(item, false);
stage.append(play);
}
function startStageVideo(stage, status, product, item, autoplay) {
const image = stage.querySelector('img');
const poster = image?.currentSrc || image?.getAttribute('src');
status.textContent = t('videoLoading');
status.hidden = false;
playStoreClip(stage, item.sources, poster, autoplay, () => { status.hidden = true; }, () => {
renderStageMedia(stage, status, product, item, true, (target, auto) => startStageVideo(stage, status, product, target, auto));
status.textContent = t('videoUnavailable');
status.hidden = false;
});
}
function createGalleryThumb(item, index, onSelect) {
const button = storeButton('media-thumb');
button.setAttribute('aria-label', item.label);
button.setAttribute('aria-pressed', 'false');
button.title = 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 = () => onSelect(index, true);
return button;
}
function bindGalleryControls(nav, rail, prev, next, buttons, itemsLength, getActive, onSelect) {
prev.setAttribute('aria-label', t('previousMedia'));
next.setAttribute('aria-label', t('nextMedia'));
prev.onclick = () => onSelect(getActive() - 1);
next.onclick = () => onSelect(getActive() + 1);
rail.append(...buttons);
rail.onkeydown = (event) => {
if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return;
event.preventDefault();
onSelect(getActive() + (event.key === 'ArrowRight' ? 1 : -1));
buttons[getActive()].focus({ preventScroll: true });
};
nav.hidden = itemsLength === 1;
}
function mountStoreGallery(root, product, autoplay) {
const items = galleryItems(product);
root.innerHTML = '<div class="media-stage"></div><div class="media-navigation"><button type="button">‹</button>'
@@ -106,51 +203,7 @@ function mountStoreGallery(root, product, autoplay) {
const caption = root.querySelector('.media-caption');
const status = root.querySelector('.media-status');
let active = 0;
function showImage(item, showPlay) {
stage.replaceChildren();
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 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, autoplay, () => { status.hidden = true; }, () => {
showImage(item, true);
status.textContent = t('videoUnavailable');
status.hidden = false;
});
}
const playItem = (item, auto = false) => startStageVideo(stage, status, product, item, auto);
function select(index, play = false, scroll = true) {
if (index < 0 || index >= items.length) return;
@@ -158,47 +211,20 @@ function mountStoreGallery(root, product, autoplay) {
buttons[active].setAttribute('aria-pressed', 'false');
active = index;
const item = items[index];
const button = buttons[index];
button.setAttribute('aria-pressed', 'true');
if (scroll) button.scrollIntoView({ block: 'nearest', inline: 'nearest' });
buttons[index].setAttribute('aria-pressed', 'true');
if (scroll) buttons[index].scrollIntoView({ block: 'nearest', inline: 'nearest' });
prev.disabled = index === 0;
next.disabled = index === items.length - 1;
caption.querySelector('.media-label').textContent = item.label;
caption.querySelector('.media-position').textContent = (index + 1) + ' / ' + items.length;
status.hidden = true;
showImage(item, !!item.sources);
if (play && item.sources) playItem(item);
renderStageMedia(stage, status, product, item, !!item.sources, playItem);
if (play && item.sources) playItem(item, false);
}
const buttons = items.map((item, index) => {
const button = storeButton('media-thumb');
button.setAttribute('aria-label', item.label);
button.setAttribute('aria-pressed', 'false');
button.title = 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;
});
prev.setAttribute('aria-label', t('previousMedia'));
next.setAttribute('aria-label', t('nextMedia'));
prev.onclick = () => select(active - 1);
next.onclick = () => select(active + 1);
rail.append(...buttons);
rail.onkeydown = (event) => {
if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return;
event.preventDefault();
select(active + (event.key === 'ArrowRight' ? 1 : -1));
buttons[active].focus({ preventScroll: true });
};
nav.hidden = caption.hidden = items.length === 1;
const buttons = items.map((item, index) => createGalleryThumb(item, index, select));
bindGalleryControls(nav, rail, prev, next, buttons, items.length, () => active, select);
caption.hidden = items.length === 1;
select(0, false, false);
const initial = items[0];
if (autoplay && initial.sources) playItem(initial, true);
if (autoplay && items[0].sources) playItem(items[0], true);
}
@@ -24,19 +24,31 @@ function rankLabel(rank) {
return t('rank', { rank: ROMAN[rank] || rank });
}
const LOCAL_STORE_MEDIA_PREFIX = '/_wto/ui/store-media/';
const PUBLIC_STORE_CDN = 'https://static-store.gaijin.net/';
function storeImageCandidates(localUrl) {
if (!localUrl) return [];
if (!localUrl.startsWith(LOCAL_STORE_MEDIA_PREFIX)) return [localUrl];
return [localUrl, PUBLIC_STORE_CDN + localUrl.slice(LOCAL_STORE_MEDIA_PREFIX.length)];
}
function productArtwork(product) {
const image = product.unitName ? WtoUi.artworkUrl('vehicle', product.unitName) : WtoUi.artworkUrl('product', product.kind);
return product.artworkGroup ? [WtoUi.artworkUrl('group', product.artworkGroup), image] : [image];
const fallbacks = product.artworkGroup ? [WtoUi.artworkUrl('group', product.artworkGroup), image] : [image];
if (product.unitName) fallbacks.push('/_wto/ui/vehicle/' + encodeURIComponent(product.unitName) + '.svg');
return fallbacks;
}
function productImage(product, className = '') {
const { cover } = WtoUi.storeMedia(product.id);
const urls = product.unitName ? [cover, ...WtoUi.vehicleUrls(product.unitName)] : [cover];
const candidates = storeImageCandidates(cover);
const urls = product.unitName ? [...candidates, ...WtoUi.vehicleUrls(product.unitName)] : candidates;
return WtoUi.tieredImg(urls, productArtwork(product), className);
}
function productScreenshot(product, url, className = '') {
return WtoUi.tieredImg([url], productArtwork(product), className);
return WtoUi.tieredImg(storeImageCandidates(url), productArtwork(product), className);
}
function vehicleMeta(vehicle) {