Files
WT-Offline/packages/local-service/src/profile/player-profiles.ts
T
N0VAN0M4LY ac2c185d4c feat(accounts): persist EULA acceptance
Persist the accepted EULA version before responding and return both
agreement fields in the profile. Respond to matching heartbeats.
2026-11-24 09:05:31 +08:00

35 lines
1.1 KiB
TypeScript

/**
* The one way services get a player's profile: the saved one, or a new one that is written
* to the save before it is handed out.
*/
import type { BlkBlock } from '@wto/blk';
import type { GameFiles } from '../game-data/game-files.ts';
import type { SaveStore } from '../saves/save-store.ts';
import { newProfile } from './new-profile.ts';
export class PlayerProfiles {
readonly #saves: SaveStore;
readonly #gameFiles: GameFiles;
constructor(saves: SaveStore, gameFiles: GameFiles) {
this.#saves = saves;
this.#gameFiles = gameFiles;
}
profileOf(userId: string): BlkBlock {
const saved = this.#saves.loadProfile(userId);
if (saved) return saved;
const created = newProfile(this.#gameFiles.newAccountTemplate());
this.#saves.saveProfile(userId, created);
return created;
}
/** Change the player's profile and write it to the save before returning it. */
update(userId: string, change: (profile: BlkBlock) => void): BlkBlock {
const profile = this.profileOf(userId);
change(profile);
this.#saves.saveProfile(userId, profile);
return profile;
}
}