feat(store): sell multi-vehicle packs and localize country names

Offer the five three-vehicle packs and nine starter packs as bundles.
Grant their unowned vehicles and bonuses on purchase. Encode each
vehicle in an aircraftGift field and validate duplicate IDs and
vehicle assignments.

Read group labels from units.csv and country names from
_common_languages.csv. Use those names in packs and browser filters.

Type checking and local catalogue and price response checks passed.
In-game acceptance is pending.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 13:41:32 +08:00
1 parent 78f1857918
commit 259cd0f32c
12 files changed
+412 -104

No files matched your search

+46 -28
View File
@@ -6,16 +6,16 @@ const T = {
title: 'WTOffline 本地商店', hint: '买完关闭本窗口,机库会自动刷新', toMarket: '前往交易所',
eagles: '金鹰', lions: '银狮', premium: '高级账户', premiumOff: '未开通', premiumLeft: '剩余 {days} 天',
tabPacks: '礼包载具', tabPremium: '高级账户', tabEagles: '金鹰', tabRedeem: '兑换码',
search: '搜索载具名称', allCountries: '全部国家', allRanks: '全部等级', rank: '{rank} 级',
containsEagles: '附赠 {n} 金鹰', containsPremium: '附赠 {days} 天高级账户', premiumDays: '{days} 天高级账户',
search: '搜索礼包或载具名称', allCountries: '全部国家', allRanks: '全部等级', rank: '{rank} 级',
includesUnit: '包含载具:{name}', containsEagles: '附赠 {n} 金鹰', containsSilver: '附赠 {n} 银狮', containsPremium: '附赠 {days} 天高级账户', premiumDays: '{days} 天高级账户',
buy: '购买', owned: '已拥有', pickAccount: '请先选择账号', redeem: '兑换', codePlaceholder: '输入兑换码', empty: '没有符合条件的商品',
},
en: {
title: 'WTOffline Store', hint: 'Close this window after buying to refresh the hangar', toMarket: 'Go to Marketplace',
eagles: 'Golden Eagles', lions: 'Silver Lions', premium: 'Premium', premiumOff: 'inactive', premiumLeft: '{days} days left',
tabPacks: 'Vehicle packs', tabPremium: 'Premium Account', tabEagles: 'Golden Eagles', tabRedeem: 'Redeem code',
search: 'Search vehicles', allCountries: 'All nations', allRanks: 'All ranks', rank: 'Rank {rank}',
containsEagles: '+{n} Golden Eagles', containsPremium: '+{days} days of Premium Account', premiumDays: '{days} days of Premium Account',
search: 'Search packs or vehicles', allCountries: 'All nations', allRanks: 'All ranks', rank: 'Rank {rank}',
includesUnit: 'Vehicle: {name}', containsEagles: '+{n} Golden Eagles', containsSilver: '+{n} Silver Lions', containsPremium: '+{days} days of Premium Account', premiumDays: '{days} days of Premium Account',
buy: 'Buy', owned: 'Owned', pickAccount: 'Pick an account first', redeem: 'Redeem', codePlaceholder: 'Enter a code', empty: 'Nothing matches the filters',
},
};
@@ -35,8 +35,6 @@ function applyStaticTexts() {
async function loadState(userId) {
state = await WtoUi.getJson('/store/api/state' + (userId ? '?userId=' + encodeURIComponent(userId) : ''));
if (userId && !state.activeUserId) return loadState('');
if (state.activeUserId) WtoUi.saveAccount(state.activeUserId);
renderHeader();
renderFilters();
renderContent();
@@ -59,8 +57,9 @@ function fillSelect(select, firstText, values, textOf) {
function renderFilters() {
const packs = state.products.filter((p) => p.kind === 'vehicle-pack');
fillSelect($('countryFilter'), t('allCountries'), [...new Set(packs.map((p) => p.country))], WtoUi.label);
fillSelect($('rankFilter'), t('allRanks'), [...new Set(packs.map((p) => p.rank))].sort((a, b) => a - b), (r) => t('rank', { rank: ROMAN[r] || r }));
fillSelect($('countryFilter'), t('allCountries'), [...new Set(packs.map((p) => p.country).filter(Boolean))], WtoUi.label);
const allRanks = packs.flatMap((p) => p.ranks || (p.rank ? [p.rank] : []));
fillSelect($('rankFilter'), t('allRanks'), [...new Set(allRanks)].sort((a, b) => a - b), (r) => t('rank', { rank: ROMAN[r] || r }));
}
function matchesFilters(product) {
@@ -70,8 +69,11 @@ function matchesFilters(product) {
const rank = $('rankFilter').value;
const query = $('searchInput').value.trim().toLowerCase();
if (country && product.country !== country) return false;
if (rank && String(product.rank) !== rank) return false;
return !query || [product.title.zh, product.title.en, product.unitName].some((s) => (s || '').toLowerCase().includes(query));
if (rank && !(product.ranks || [product.rank]).map(String).includes(rank)) return false;
if (!query) return true;
const searchTerms = [product.title.zh, product.title.en, product.unitName];
for (const v of product.vehicles || []) searchTerms.push(v.unitName, v.title && v.title.zh, v.title && v.title.en);
return searchTerms.some((s) => (s || '').toLowerCase().includes(query));
}
function renderContent() {
@@ -91,6 +93,32 @@ function renderContent() {
function productCard(product) {
const card = document.createElement('div');
card.className = 'card';
card.appendChild(productCardHead(product));
const contents = productContents(product);
if (contents.length) {
const list = document.createElement('ul');
list.className = 'contents';
for (const line of contents) list.appendChild(Object.assign(document.createElement('li'), { textContent: line }));
card.appendChild(list);
}
const foot = document.createElement('div');
foot.className = 'card-foot';
foot.innerHTML = '<span class="price"></span>';
foot.querySelector('.price').textContent = WtoUi.gjn(product.gjnCostCents) + ' GJN';
const btn = Object.assign(document.createElement('button'), {
className: 'buy',
textContent: product.owned ? t('owned') : (state.activeUserId ? t('buy') : t('pickAccount')),
disabled: product.owned || !state.activeUserId,
});
if (!btn.disabled) btn.onclick = () => buy(product.id);
foot.appendChild(btn);
card.appendChild(foot);
return card;
}
function productCardHead(product) {
const head = document.createElement('div');
head.className = 'card-head';
if (product.unitName) head.appendChild(WtoUi.iconImg('vehicle', product.unitName, 'vehicle-icon'));
@@ -103,29 +131,19 @@ function productCard(product) {
sub.appendChild(document.createTextNode(WtoUi.label(product.country) + ' · ' + t('rank', { rank: ROMAN[product.rank] || product.rank })));
}
head.appendChild(titles);
card.appendChild(head);
return head;
}
function productContents(product) {
const contents = [];
if (product.vehicles && product.vehicles.length > 1) {
for (const v of product.vehicles) contents.push(t('includesUnit', { name: WtoUi.text(v.title) }));
}
if (product.kind === 'premium-gjn') contents.push(t('premiumDays', { days: product.premiumDays }));
else if (product.premiumDays) contents.push(t('containsPremium', { days: product.premiumDays }));
if (product.kind === 'vehicle-pack' && product.goldIncome) contents.push(t('containsEagles', { n: WtoUi.num(product.goldIncome) }));
if (contents.length) {
const list = document.createElement('ul');
list.className = 'contents';
for (const line of contents) list.appendChild(Object.assign(document.createElement('li'), { textContent: line }));
card.appendChild(list);
}
const foot = document.createElement('div');
foot.className = 'card-foot';
foot.innerHTML = '<span class="price"></span><button class="buy"></button>';
foot.querySelector('.price').textContent = WtoUi.gjn(product.gjnCostCents) + ' GJN';
const button = foot.querySelector('button');
button.textContent = product.owned ? t('owned') : state.activeUserId ? t('buy') : t('pickAccount');
button.disabled = product.owned || !state.activeUserId;
button.onclick = () => buy(product.id);
card.appendChild(foot);
return card;
if (product.kind === 'vehicle-pack' && product.silverIncome) contents.push(t('containsSilver', { n: WtoUi.num(product.silverIncome) }));
return contents;
}
function renderRedeemHelp() {