Recompute unlocked ranks, prerequisites, and unit states before serving profiles. Add research target selection, research conversion, vehicle and slot purchases, and the price table. Support editing convertible RP and restrict hidden vehicle visibility to eligible entries. The client still displays zero purchase prices pending price table integration.
72 lines
3.1 KiB
TypeScript
72 lines
3.1 KiB
TypeScript
/**
|
|
* Development entry point for editing a save (the save editor of docs/implementation notes
|
|
* section A; the launcher will call the same profile functions).
|
|
*
|
|
* node packages/local-service/src/save-cli.ts --game <game folder> --data <data folder>
|
|
* --player <login or user id> [--silver <n>] [--gold <n>] [--free-rp <n>]
|
|
*
|
|
* --free-rp sets the free research points. Without any amount it
|
|
* only prints the balance. The edit is written to the save; the
|
|
* game shows it after its next profile update (any action, or signing in again).
|
|
*/
|
|
import { parseArgs } from 'node:util';
|
|
import { AccountStore } from './accounts/account-store.ts';
|
|
import { DatasetCache } from './game-data/datasets/dataset-cache.ts';
|
|
import { GameFiles } from './game-data/game-files.ts';
|
|
import { balanceOf, setGoldenEagles, setSilverLions } from './profile/profile-currency.ts';
|
|
import { freeResearchPoints, setFreeResearchPoints } from './profile/profile-research-points.ts';
|
|
import { setUpProfiles } from './profiles-setup.ts';
|
|
|
|
function main(): number {
|
|
const { values } = parseArgs({
|
|
options: {
|
|
game: { type: 'string' },
|
|
data: { type: 'string' },
|
|
player: { type: 'string' },
|
|
silver: { type: 'string' },
|
|
gold: { type: 'string' },
|
|
'free-rp': { type: 'string' },
|
|
},
|
|
});
|
|
if (!values.game || !values.data || !values.player) {
|
|
console.error('usage: save-cli.ts --game <game folder> --data <data folder> --player <login or user id> [--silver <n>] [--gold <n>] [--free-rp <n>]');
|
|
return 2;
|
|
}
|
|
const silver = optionalAmount(values.silver);
|
|
const gold = optionalAmount(values.gold);
|
|
const freeRp = optionalAmount(values['free-rp']);
|
|
if (silver === null || gold === null || freeRp === null) {
|
|
console.error('--silver, --gold and --free-rp take a whole number of 0 or more');
|
|
return 2;
|
|
}
|
|
|
|
const accounts = new AccountStore(values.data);
|
|
const account = accounts.byLogin(values.player) ?? accounts.byUserId(values.player);
|
|
if (!account) {
|
|
console.error(`no player "${values.player}" in ${values.data}`);
|
|
return 1;
|
|
}
|
|
const gameFiles = new GameFiles(values.game);
|
|
const datasets = new DatasetCache(values.data, gameFiles, () => {});
|
|
const { profiles } = setUpProfiles(values.data, gameFiles, datasets);
|
|
|
|
const profile = silver === undefined && gold === undefined && freeRp === undefined
|
|
? profiles.profileOf(account.userId)
|
|
: profiles.update(account.userId, (saved) => {
|
|
if (silver !== undefined) setSilverLions(saved, silver);
|
|
if (gold !== undefined) setGoldenEagles(saved, gold);
|
|
if (freeRp !== undefined) setFreeResearchPoints(saved, freeRp);
|
|
});
|
|
const balance = balanceOf(profile);
|
|
console.log(`${account.login} (${account.userId}): ${balance.silverLions} silver lions, ${balance.goldenEagles} golden eagles, ${freeResearchPoints(profile)} free research points`);
|
|
return 0;
|
|
}
|
|
|
|
/** undefined when not given, null when not a valid amount. */
|
|
function optionalAmount(text: string | undefined): number | undefined | null {
|
|
if (text === undefined) return undefined;
|
|
return /^\d+$/.test(text) && Number.isSafeInteger(Number(text)) ? Number(text) : null;
|
|
}
|
|
|
|
process.exitCode = main();
|