Zod EVERYWHERE (#2027)

* Zod EVERYWHERE

* Add no-unused-vars rule to eslint in front

* Add no-unused-vars rule to eslint in pusher

* Add no-unused-vars rule to eslint in back

* Remove unused PlayerTexture guards

* Fix data providing on room connection

Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re>
This commit is contained in:
Alexis Faizeau
2022-04-12 14:21:19 +02:00
committed by GitHub
parent 41e62051d4
commit d1e8243c47
161 changed files with 1131 additions and 1248 deletions
+13 -10
View File
@@ -4,14 +4,13 @@ import type { ITiledMapObject } from "../../Map/ITiledMap";
import type { ItemFactoryInterface } from "../ItemFactoryInterface";
import type { GameScene } from "../../Game/GameScene";
import { ActionableItem } from "../ActionableItem";
import * as tg from "generic-type-guard";
import { z } from "zod";
const isComputerState = new tg.IsInterface()
.withProperties({
status: tg.isString,
})
.get();
type ComputerState = tg.GuardedType<typeof isComputerState>;
export const isComputerState = z.object({
status: z.string(),
});
export type ComputerState = z.infer<typeof isComputerState>;
let state: ComputerState = {
status: "off",
@@ -55,10 +54,14 @@ export default {
},
factory: (scene: GameScene, object: ITiledMapObject, initState: unknown): ActionableItem => {
if (initState !== undefined) {
if (!isComputerState(initState)) {
throw new Error("Invalid state received for computer object");
try {
state = isComputerState.parse(initState);
} catch (err) {
if (err instanceof z.ZodError) {
console.error(err.issues);
}
throw new Error(`Invalid state received for computer object`);
}
state = initState;
}
const computer = new Sprite(scene, object.x, object.y, "computer");