Skip to content

Commit

Permalink
🧩 Add game schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdodo committed Oct 21, 2024
1 parent f26f468 commit bac798b
Show file tree
Hide file tree
Showing 25 changed files with 204 additions and 21 deletions.
8 changes: 4 additions & 4 deletions core/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@stryker-mutator/core": "^8.6.0",
"@stryker-mutator/vitest-runner": "^8.6.0",
"@types/node": "^22.7.4",
"blockwise": "^2.8.1",
"blockwise": "^2.9.1",
"json-schema-library": "^10.0.0-rc2",
"json-schema-to-ts": "^3.1.1",
"rxjs": "^7.8.1",
Expand Down
2 changes: 0 additions & 2 deletions core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"module": "ESNext",
"moduleResolution": "Bundler",
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"target": "ES2015"
}
Expand Down
10 changes: 10 additions & 0 deletions core/types/appellation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { FromSchema } from "json-schema-to-ts";

export enum Appellation {
Soldier = "Soldier",
Knight = "Knight",
Expand All @@ -20,3 +22,11 @@ export enum Appellation {
GreatswordSkeleton = "Greatsword Skeleton",
SkeletonArcher = "Skeleton Archer",
}

export const appellationSchema = {
type: "string",
enum: Object.values(Appellation),
} as const;

const a: Appellation = {} as FromSchema<typeof appellationSchema>;
const b: FromSchema<typeof appellationSchema> = {} as Appellation;
17 changes: 17 additions & 0 deletions core/types/attributes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import type { FromSchema } from "json-schema-to-ts";

export interface Attributes {
mana: number;
maxMana: number;
health: number;
maxHealth: number;
}

export const attributesSchema = {
type: "object",
properties: {
mana: { type: "number" },
maxMana: { type: "number" },
health: { type: "number" },
maxHealth: { type: "number" },
},
required: ["mana", "maxMana", "health", "maxHealth"],
additionalProperties: false,
} as const;

const a: Attributes = {} as FromSchema<typeof attributesSchema>;
const b: FromSchema<typeof attributesSchema> = {} as Attributes;
4 changes: 4 additions & 0 deletions core/types/client-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { rerollRequestSchema } from "./reroll-request";
import type { RerollRequest } from "./reroll-request";
import { transposeRequestSchema } from "./transpose-request";
import type { TransposeRequest } from "./transpose-request";
import type { FromSchema } from "json-schema-to-ts";

export interface ClientMessage {
initiateGameRequest?: InitiateGameRequest;
Expand All @@ -27,3 +28,6 @@ export const clientMessageSchema = {
},
additionalProperties: false,
} as const;

const a: ClientMessage = {} as FromSchema<typeof clientMessageSchema>;
const b: FromSchema<typeof clientMessageSchema> = {} as ClientMessage;
5 changes: 5 additions & 0 deletions core/types/date-time.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { FromSchema } from "json-schema-to-ts";

export type DateTime = string;

export const dateTimeSchema = {
type: "string",
format: "date-time",
} as const;

const a: DateTime = {} as FromSchema<typeof dateTimeSchema>;
const b: FromSchema<typeof dateTimeSchema> = {} as DateTime;
65 changes: 60 additions & 5 deletions core/types/game.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { publicKeySchema, type PublicKey } from "./public-key";
import type { Hero } from "./hero";
import type { Appellation } from "./appellation";
import { heroSchema, type Hero } from "./hero";
import { appellationSchema, type Appellation } from "./appellation";
import type { Playsig } from "./playsig";
import type { Phase } from "./phase";
import type { Level } from "./level";
import { Phase } from "./phase";
import { levelSchema, type Level } from "./level";
import { playsigSchema } from "./playsig";
import { nicknameSchema } from "./nickname";
import type { FromSchema } from "json-schema-to-ts";

export interface Game {
playsig: Playsig;
Expand Down Expand Up @@ -46,5 +47,59 @@ export const gameSchema = {
minProperties: 2,
maxProperties: 8,
},
playerHeroes: {
type: "object",
propertyNames: publicKeySchema,
additionalProperties: {
type: "array",
items: heroSchema,
minItems: 0,
maxItems: 10,
},
},
playerBenches: {
type: "object",
propertyNames: publicKeySchema,
additionalProperties: {
type: "object",
propertyNames: {
type: "integer",
minimum: 0,
maximum: 5,
},
additionalProperties: heroSchema,
},
},
playerShops: {
type: "object",
propertyNames: publicKeySchema,
additionalProperties: {
type: "array",
items: appellationSchema,
minItems: 0,
maxItems: 3,
},
},
playerMoney: {
type: "object",
propertyNames: publicKeySchema,
additionalProperties: {
type: "integer",
minimum: 0,
},
},
playerLevel: {
type: "object",
propertyNames: publicKeySchema,
additionalProperties: levelSchema,
},
phase: {
type: "string",
enum: Object.values(Phase),
},
},
};
additionalProperties: false,
} as const;

const a: Game = {} as FromSchema<typeof gameSchema>;
const b: FromSchema<typeof gameSchema> = {} as Game;
12 changes: 12 additions & 0 deletions core/types/grade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { FromSchema } from "json-schema-to-ts";

export type Grade = number;

export const gradeSchema = {
type: "integer",
minimum: 0,
maximum: 5,
} as const;

const a: Grade = {} as FromSchema<typeof gradeSchema>;
const b: FromSchema<typeof gradeSchema> = {} as Grade;
26 changes: 23 additions & 3 deletions core/types/hero.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import type { Appellation } from "./appellation";
import { appellationSchema, type Appellation } from "./appellation";
import type { Block } from "blockwise";
import type { Attributes } from "./attributes";
import { attributesSchema, type Attributes } from "./attributes";
import { gradeSchema, type Grade } from "./grade";
import type { FromSchema } from "json-schema-to-ts";
import { blockSchema } from "blockwise";
import { uidSchema } from "./uid";

export interface Hero {
id: string;
appellation: Appellation;
grade: number;
grade: Grade;
position: Block;
attributes: Attributes;
}

export const heroSchema = {
type: "object",
required: ["id", "appellation", "grade", "position", "attributes"],
properties: {
id: uidSchema,
appellation: appellationSchema,
grade: gradeSchema,
position: blockSchema,
attributes: attributesSchema,
},
additionalProperties: false,
} as const;

const a: Hero = {} as FromSchema<typeof heroSchema>;
const b: FromSchema<typeof heroSchema> = {} as Hero;
8 changes: 8 additions & 0 deletions core/types/initiate-game-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Signature } from "./signature";
import { signatureSchema } from "./signature";
import { dateTimeSchema } from "./date-time";
import type { DateTime } from "./date-time";
import type { FromSchema } from "json-schema-to-ts";

export interface InitiateGameRequest {
nickname: Nickname;
Expand All @@ -27,3 +28,10 @@ export const initiateGameRequestSchema = {
},
additionalProperties: false,
} as const;

const a: InitiateGameRequest = {} as FromSchema<
typeof initiateGameRequestSchema
>;

const b: FromSchema<typeof initiateGameRequestSchema> =
{} as InitiateGameRequest;
4 changes: 4 additions & 0 deletions core/types/level-up-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { playsigSchema } from "./playsig";
import type { Playsig } from "./playsig";
import { dateTimeSchema } from "./date-time";
import type { DateTime } from "./date-time";
import type { FromSchema } from "json-schema-to-ts";

export interface LevelUpRequest {
publicKey: PublicKey;
Expand All @@ -27,3 +28,6 @@ export const LevelUpRequestSchema = {
},
additionalProperties: false,
} as const;

const a: LevelUpRequest = {} as FromSchema<typeof LevelUpRequestSchema>;
const b: FromSchema<typeof LevelUpRequestSchema> = {} as LevelUpRequest;
9 changes: 9 additions & 0 deletions core/types/level.ts
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
import type { FromSchema } from "json-schema-to-ts";

export type Level = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;

export const levelSchema = {
enum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
} as const;

const a: FromSchema<typeof levelSchema> = {} as Level;
const b: Level = {} as FromSchema<typeof levelSchema>;
5 changes: 5 additions & 0 deletions core/types/nickname.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { FromSchema } from "json-schema-to-ts";

export type Nickname = string;

export const nicknameSchema = {
Expand All @@ -6,3 +8,6 @@ export const nicknameSchema = {
maxLength: 20,
pattern: "^[\\p{L}]+$",
} as const;

const a: Nickname = {} as FromSchema<typeof nicknameSchema>;
const b: FromSchema<typeof nicknameSchema> = {} as Nickname;
8 changes: 8 additions & 0 deletions core/types/observe-game-subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { DateTime } from "./date-time";
import type { Playsig } from "./playsig";
import type { PublicKey } from "./public-key";
import type { Signature } from "./signature";
import type { FromSchema } from "json-schema-to-ts";

export interface ObserveGameSubscribe {
playsig: Playsig;
Expand All @@ -27,3 +28,10 @@ export const ObserveGameSubscribeSchema = {
},
additionalProperties: false,
} as const;

const a: ObserveGameSubscribe = {} as FromSchema<
typeof ObserveGameSubscribeSchema
>;

const b: FromSchema<typeof ObserveGameSubscribeSchema> =
{} as ObserveGameSubscribe;
5 changes: 5 additions & 0 deletions core/types/piece-slot.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { FromSchema } from "json-schema-to-ts";

export interface PieceSlot {
positionX?: number;
positionY?: number;
Expand Down Expand Up @@ -26,3 +28,6 @@ export const pieceSlotSchema = {
},
additionalProperties: false,
} as const;

const a: PieceSlot = {} as FromSchema<typeof pieceSlotSchema>;
const b: FromSchema<typeof pieceSlotSchema> = {} as PieceSlot;
5 changes: 5 additions & 0 deletions core/types/public-key.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { FromSchema } from "json-schema-to-ts";

export type PublicKey = string;

export const publicKeySchema = {
Expand All @@ -6,3 +8,6 @@ export const publicKeySchema = {
maxLength: 66,
pattern: "^[a-fA-F0-9]+$",
} as const;

const a: PublicKey = {} as FromSchema<typeof publicKeySchema>;
const b: FromSchema<typeof publicKeySchema> = {} as PublicKey;
4 changes: 4 additions & 0 deletions core/types/reroll-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { playsigSchema } from "./playsig";
import type { Playsig } from "./playsig";
import type { DateTime } from "./date-time";
import { dateTimeSchema } from "./date-time";
import type { FromSchema } from "json-schema-to-ts";

export interface RerollRequest {
publicKey: PublicKey;
Expand All @@ -27,3 +28,6 @@ export const rerollRequestSchema = {
},
additionalProperties: false,
} as const;

const a: RerollRequest = {} as FromSchema<typeof rerollRequestSchema>;
const b: FromSchema<typeof rerollRequestSchema> = {} as RerollRequest;
5 changes: 5 additions & 0 deletions core/types/signature.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { FromSchema } from "json-schema-to-ts";

export type Signature = string;

export const signatureSchema = {
Expand All @@ -6,3 +8,6 @@ export const signatureSchema = {
maxLength: 300,
pattern: "^[a-fA-F0-9]+$",
} as const;

const a: Signature = {} as FromSchema<typeof signatureSchema>;
const b: FromSchema<typeof signatureSchema> = {} as Signature;
4 changes: 4 additions & 0 deletions core/types/transpose-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Playsig } from "./playsig";
import type { PieceSlot } from "./piece-slot";
import { pieceSlotSchema } from "./piece-slot";
import { dateTimeSchema, type DateTime } from "./date-time";
import type { FromSchema } from "json-schema-to-ts";

export interface TransposeRequest {
publicKey: PublicKey;
Expand Down Expand Up @@ -40,3 +41,6 @@ export const transposeRequestSchema = {
},
additionalProperties: false,
} as const;

const a: TransposeRequest = {} as FromSchema<typeof transposeRequestSchema>;
const b: FromSchema<typeof transposeRequestSchema> = {} as TransposeRequest;
11 changes: 11 additions & 0 deletions core/types/uid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { FromSchema } from "json-schema-to-ts";

export type Uid = string;

export const uidSchema = {
type: "string",
format: "uuid",
} as const;

const a: Uid = {} as FromSchema<typeof uidSchema>;
const b: FromSchema<typeof uidSchema> = {} as Uid;
Empty file added core/utils/type-check.ts
Empty file.
Loading

0 comments on commit bac798b

Please sign in to comment.