Grant reserve vehicles and support crew presets
Derive reserve vehicles from the stock economy data. Grant all reserves and mark the basic takeoff and landing tutorials complete in new saves. Apply the same grants through the format 2 migration. Use shared crew slot rules for first-run selection, presets, training, assignment, and removal.
This commit is contained in:
1 parent
40af06edad
commit
2fc28dd7a5
16 files changed
+366
-57
No files matched your search
@@ -12,7 +12,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { decodeBlk, encodeBlk, type BlkBlock } from '@wto/blk';
|
||||
import { writeFileAtomic } from '../storage/atomic-file.ts';
|
||||
import { CURRENT_SAVE_FORMAT, upgradeSave } from './save-upgrades.ts';
|
||||
import type { SaveUpgrades } from './save-upgrades.ts';
|
||||
|
||||
interface SaveInfo {
|
||||
formatVersion: number;
|
||||
@@ -22,9 +22,11 @@ interface SaveInfo {
|
||||
|
||||
export class SaveStore {
|
||||
readonly #folder: string;
|
||||
readonly #upgrades: SaveUpgrades;
|
||||
|
||||
constructor(dataFolder: string) {
|
||||
constructor(dataFolder: string, upgrades: SaveUpgrades) {
|
||||
this.#folder = join(dataFolder, 'saves');
|
||||
this.#upgrades = upgrades;
|
||||
}
|
||||
|
||||
/** The account's profile, or undefined when the account has no save yet. */
|
||||
@@ -33,8 +35,8 @@ export class SaveStore {
|
||||
if (!existsSync(infoPath)) return undefined;
|
||||
const info = JSON.parse(readFileSync(infoPath, 'utf8')) as SaveInfo;
|
||||
const profile = decodeBlk(readFileSync(this.#profilePath(userId)));
|
||||
if (info.formatVersion === CURRENT_SAVE_FORMAT) return profile;
|
||||
const upgraded = upgradeSave(profile, info.formatVersion);
|
||||
if (info.formatVersion === this.#upgrades.currentFormat) return profile;
|
||||
const upgraded = this.#upgrades.upgrade(profile, info.formatVersion);
|
||||
this.saveProfile(userId, upgraded);
|
||||
return upgraded;
|
||||
}
|
||||
@@ -43,7 +45,7 @@ export class SaveStore {
|
||||
const now = new Date().toISOString();
|
||||
const previous = existsSync(this.#infoPath(userId)) ? (JSON.parse(readFileSync(this.#infoPath(userId), 'utf8')) as SaveInfo) : undefined;
|
||||
writeFileAtomic(this.#profilePath(userId), encodeBlk(profile));
|
||||
const info: SaveInfo = { formatVersion: CURRENT_SAVE_FORMAT, created: previous?.created ?? now, updated: now };
|
||||
const info: SaveInfo = { formatVersion: this.#upgrades.currentFormat, created: previous?.created ?? now, updated: now };
|
||||
writeFileAtomic(this.#infoPath(userId), JSON.stringify(info, null, 2));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user