feat(store): open store pages in-game and centralize economy tuning
Use the native embedded browser and pass the game language through auto_local. Share web assets and extract vehicle icons, flags, and localized names from the installed client. Load and validate per-domain JSONC tuning and merge local overrides by field. Use official store USD prices for GJN products, keep GJN balances in integer cents, and split the native and web store handlers by protocol. Multi-vehicle packs are still listed as single vehicles at this point. Type checking, patch checks, and configuration loading passed. In-game acceptance is pending.
This commit is contained in:
1 parent
8d9cca9d05
commit
9cf7df5299
74 files changed
+2904
-1455
No files matched your search
@@ -14,13 +14,15 @@ import type { ItemDefinition } from './game-data/datasets/item-catalogue.ts';
|
||||
import { GameFiles } from './game-data/game-files.ts';
|
||||
import { grantItem } from './items/item-grants.ts';
|
||||
import { availableSquadronRp, clanMembershipOf, setAvailableSquadronRp } from './profile/profile-clan.ts';
|
||||
import { balanceOf, setGjn, setGoldenEagles, setSilverLions } from './profile/profile-currency.ts';
|
||||
import { balanceOf, setGjnCents, setGoldenEagles, setSilverLions } from './profile/profile-currency.ts';
|
||||
import { remainingPremiumDays } from './profile/profile-entitlements.ts';
|
||||
import { externalInventoryItems, grantExternalItem } from './profile/profile-external-inventory.ts';
|
||||
import { ownedItems } from './profile/profile-items.ts';
|
||||
import { freeResearchPoints, setFreeResearchPoints } from './profile/profile-research-points.ts';
|
||||
import { serverTimeNow } from './profile/server-time.ts';
|
||||
import { setUpProfiles } from './profiles-setup.ts';
|
||||
import { gjnText } from './store/redeem-codes.ts';
|
||||
import { loadTuning } from './tuning/tuning.ts';
|
||||
import type { ResearchRules } from './research/research-rules.ts';
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
|
||||
@@ -66,10 +68,11 @@ function main(): number {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const clans = new ClanStore(values.data);
|
||||
const tuning = loadTuning(values.data, console.log);
|
||||
const clans = new ClanStore(values.data, tuning.clans);
|
||||
const gameFiles = new GameFiles(values.game);
|
||||
const datasets = new DatasetCache(values.data, gameFiles, () => {});
|
||||
const { profiles, research } = setUpProfiles(values.data, gameFiles, datasets, { accounts, clans });
|
||||
const { profiles, research } = setUpProfiles(values.data, gameFiles, datasets, tuning, { accounts, clans });
|
||||
|
||||
const edits = parseRequestedEdits(values, research);
|
||||
if (!edits) return 2;
|
||||
@@ -90,11 +93,11 @@ function parseRequestedEdits(
|
||||
): ParsedEdits | undefined {
|
||||
const silver = optionalAmount(values.silver as string | undefined);
|
||||
const gold = optionalAmount(values.gold as string | undefined);
|
||||
const gjn = optionalAmount(values.gjn as string | undefined);
|
||||
const gjn = optionalGjnCents(values.gjn as string | undefined);
|
||||
const freeRp = optionalAmount(values['free-rp'] as string | undefined);
|
||||
const squadronRp = optionalAmount(values['squadron-rp'] as string | undefined);
|
||||
if (silver === null || gold === null || gjn === null || freeRp === null || squadronRp === null) {
|
||||
console.error('--silver, --gold, --gjn, --free-rp and --squadron-rp take a whole number of 0 or more');
|
||||
console.error('--silver, --gold, --free-rp and --squadron-rp take a whole number of 0 or more; --gjn an amount of 0 or more with at most two decimals');
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -129,7 +132,7 @@ function parseRequestedEdits(
|
||||
function applyEdits(saved: BlkBlock, edits: ParsedEdits, clanEarned: number, now: bigint): void {
|
||||
if (edits.silver !== undefined) setSilverLions(saved, edits.silver);
|
||||
if (edits.gold !== undefined) setGoldenEagles(saved, edits.gold);
|
||||
if (edits.gjn !== undefined) setGjn(saved, edits.gjn);
|
||||
if (edits.gjn !== undefined) setGjnCents(saved, edits.gjn);
|
||||
if (edits.freeRp !== undefined) setFreeResearchPoints(saved, edits.freeRp);
|
||||
if (edits.squadronRp !== undefined) setAvailableSquadronRp(saved, edits.squadronRp, clanEarned);
|
||||
for (const gift of edits.gifts) grantItem(saved, gift.item, gift.pieces, now);
|
||||
@@ -143,13 +146,20 @@ function printSaveSummary(account: Account, profile: BlkBlock, clanEarned: numbe
|
||||
const sqRp = availableSquadronRp(profile, clanEarned);
|
||||
const clanInfo = clanMembershipOf(profile);
|
||||
const clanNote = clanInfo.clanId !== '-1' ? `, clan: ${clanInfo.clanTag} ${clanInfo.clanName}` : '';
|
||||
console.log(`${account.login} (${account.userId}): ${balance.silverLions} silver lions, ${balance.goldenEagles} golden eagles, ${balance.gjn} GJN, ${freeResearchPoints(profile)} free research points, ${sqRp} squadron RP${premiumNote}${clanNote}`);
|
||||
console.log(`${account.login} (${account.userId}): ${balance.silverLions} silver lions, ${balance.goldenEagles} golden eagles, ${gjnText(balance.gjnCents)} GJN, ${freeResearchPoints(profile)} free research points, ${sqRp} squadron RP${premiumNote}${clanNote}`);
|
||||
const items = ownedItems(profile);
|
||||
if (items.length) console.log(`items: ${items.map((item) => `${item.id} x${item.count}`).join(', ')}`);
|
||||
const extItems = externalInventoryItems(profile);
|
||||
if (extItems.length) console.log(`extInventory: ${extItems.map((item) => `#${item.itemDefId} x${item.quantity}`).join(', ')}`);
|
||||
}
|
||||
|
||||
/** --gjn: GJN with at most two decimals, returned in hundredths. */
|
||||
function optionalGjnCents(text: string | undefined): number | undefined | null {
|
||||
if (text === undefined) return undefined;
|
||||
const match = /^(\d+)(?:\.(\d{1,2}))?$/.exec(text);
|
||||
return match ? Number(match[1]) * 100 + Number((match[2] ?? '').padEnd(2, '0')) : null;
|
||||
}
|
||||
|
||||
function optionalAmount(text: string | undefined): number | undefined | null {
|
||||
if (text === undefined) return undefined;
|
||||
return /^\d+$/.test(text) && Number.isSafeInteger(Number(text)) ? Number(text) : null;
|
||||
|
||||
Reference in new issue
Block a user