mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 17:53:29 +00:00
Enable @total-typescript/ts-reset (#1761)
## Description: Enable `@total-typescript/ts-reset` Fixes #1760 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [ ] I have read and accepted the CLA agreement (only required once).
This commit is contained in:
@@ -1,19 +1,34 @@
|
||||
import { GameConfig, GameID, GameRecord } from "../core/Schemas";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
GameConfig,
|
||||
GameConfigSchema,
|
||||
GameID,
|
||||
GameRecord,
|
||||
GameRecordSchema,
|
||||
ID,
|
||||
} from "../core/Schemas";
|
||||
import { replacer } from "../core/Util";
|
||||
|
||||
export interface LocalStatsData {
|
||||
[key: GameID]: {
|
||||
lobby: Partial<GameConfig>;
|
||||
const LocalStatsDataSchema = z.record(
|
||||
ID,
|
||||
z.object({
|
||||
lobby: GameConfigSchema.partial(),
|
||||
// Only once the game is over
|
||||
gameRecord?: GameRecord;
|
||||
};
|
||||
}
|
||||
gameRecord: GameRecordSchema.optional(),
|
||||
}),
|
||||
);
|
||||
type LocalStatsData = z.infer<typeof LocalStatsDataSchema>;
|
||||
|
||||
let _startTime: number;
|
||||
let _startTime: number | undefined;
|
||||
|
||||
function getStats(): LocalStatsData {
|
||||
const statsStr = localStorage.getItem("game-records");
|
||||
return statsStr ? JSON.parse(statsStr) : {};
|
||||
try {
|
||||
return LocalStatsDataSchema.parse(
|
||||
JSON.parse(localStorage.getItem("game-records") ?? "{}"),
|
||||
);
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function save(stats: LocalStatsData) {
|
||||
|
||||
Reference in New Issue
Block a user