boardgame-core/src/core/rule.ts

32 lines
775 B
TypeScript
Raw Normal View History

2026-04-01 13:36:16 +08:00
import {Context} from "./context";
import {Command} from "../utils/command";
import {effect} from "@preact/signals-core";
export type RuleContext<T> = Context & {
actions: Command[];
handledActions: number;
invocations: RuleContext<unknown>[];
resolution?: T;
}
function invokeRuleContext<T>(pushContext: (context: Context) => void, type: string, rule: Generator<string, T, Command>){
const ctx: RuleContext<T> = {
type,
actions: [],
handledActions: 0,
invocations: [],
resolution: undefined,
}
const dispose = effect(() => {
if(ctx.resolution) {
dispose();
return;
}
});
pushContext(rule);
}
function* rule(){
const play: Command = yield 'play';
}