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