refactor: make sides/side optional
This commit is contained in:
parent
e78caf481d
commit
e3bc63b088
|
|
@ -58,7 +58,6 @@ export function createGameContextFromModule<TState extends Record<string, unknow
|
||||||
export function createGameCommandRegistry<TState extends Record<string, unknown> = {} >(): CommandRegistry<IGameContext<TState>> {
|
export function createGameCommandRegistry<TState extends Record<string, unknown> = {} >(): CommandRegistry<IGameContext<TState>> {
|
||||||
return createCommandRegistry<IGameContext<TState>>();
|
return createCommandRegistry<IGameContext<TState>>();
|
||||||
}
|
}
|
||||||
</TState>
|
|
||||||
|
|
||||||
export function createGameCommand<TState extends Record<string, unknown> = {} , TResult = unknown>(
|
export function createGameCommand<TState extends Record<string, unknown> = {} , TResult = unknown>(
|
||||||
schema: CommandSchema | string,
|
schema: CommandSchema | string,
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,11 @@ import {RNG} from "../utils/rng";
|
||||||
|
|
||||||
export type Part = {
|
export type Part = {
|
||||||
id: string;
|
id: string;
|
||||||
sides: number;
|
|
||||||
|
sides?: number;
|
||||||
|
side?: number;
|
||||||
|
|
||||||
alignments?: string[];
|
alignments?: string[];
|
||||||
side: number;
|
|
||||||
alignment?: string;
|
alignment?: string;
|
||||||
region: Entity<Region>;
|
region: Entity<Region>;
|
||||||
position: number[];
|
position: number[];
|
||||||
|
|
@ -14,18 +16,21 @@ export type Part = {
|
||||||
|
|
||||||
export function flip(part: Entity<Part>) {
|
export function flip(part: Entity<Part>) {
|
||||||
part.produce(draft => {
|
part.produce(draft => {
|
||||||
draft.side = (draft.side + 1) % draft.sides;
|
if(!draft.sides)return;
|
||||||
|
draft.side = ((draft.side||0) + 1) % draft.sides;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function flipTo(part: Entity<Part>, side: number) {
|
export function flipTo(part: Entity<Part>, side: number) {
|
||||||
part.produce(draft => {
|
part.produce(draft => {
|
||||||
|
if(!draft.sides || side >= draft.sides)return;
|
||||||
draft.side = side;
|
draft.side = side;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function roll(part: Entity<Part>, rng: RNG) {
|
export function roll(part: Entity<Part>, rng: RNG) {
|
||||||
part.produce(draft => {
|
part.produce(draft => {
|
||||||
|
if(!draft.sides)return;
|
||||||
draft.side = rng.nextInt(draft.sides);
|
draft.side = rng.nextInt(draft.sides);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,6 @@ export function placePiece(host: IGameContext<TicTacToeState>, row: number, col:
|
||||||
const board = getBoardRegion(host);
|
const board = getBoardRegion(host);
|
||||||
const piece: Part = {
|
const piece: Part = {
|
||||||
id: `piece-${moveCount}`,
|
id: `piece-${moveCount}`,
|
||||||
sides: 1,
|
|
||||||
side: 0,
|
|
||||||
region: board,
|
region: board,
|
||||||
position: [row, col],
|
position: [row, col],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue