Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435import { mkdirSync, readFileSync, writeFileSync, renameSync } from 'node:fs';import path from 'node:path';import { AvatarState } from './dist/avatar-state.mjs';
export class AvatarSettingsStore extends AvatarState { constructor(file, legacyGhost) { let data, warning; try { data = JSON.parse(readFileSync(file, 'utf8')); if (data?.version !== 1 || !data.values || typeof data.values !== 'object') throw Error(); } catch (error) { data = undefined; if (error.code !== 'ENOENT') warning = 'Saved avatar settings could not be read. Defaults are active.'; } super(data, legacyGhost); this.file = file; this.warning = warning ?? null; // Preserve old ghost tuning before a tracking-only save drops legacy fields. if (!data && legacyGhost && Object.keys(legacyGhost).length) { try { this.save(); } catch { this.warning = 'Could not save migrated avatar settings. Save avatar to retry.'; } } } save() { mkdirSync(path.dirname(this.file), { recursive: true }); writeFileSync(this.file + '.tmp', JSON.stringify(this.serialize(), null, 2) + '\n', 'utf8'); renameSync(this.file + '.tmp', this.file); this.markSaved(); }}