feat(slay-the-spire-like): implement CombatGameHost
Introduce CombatGameHost to manage the combat lifecycle and integrate ContentModule triggers with the combat run context.
This commit is contained in:
parent
2e2ddebec4
commit
bbab3cc43b
|
|
@ -2,6 +2,7 @@ import { LoadResult as YarnDialogues } from "yarn-spinner-loader";
|
|||
import { Triggers } from "../system/combat/triggers";
|
||||
|
||||
import type * as desert from "./desert";
|
||||
import { IRunContext } from "../system/combat";
|
||||
|
||||
export type ContentModule = {
|
||||
getCards: () => desert.Card[];
|
||||
|
|
@ -13,5 +14,5 @@ export type ContentModule = {
|
|||
getStartingItems: () => desert.Item[];
|
||||
|
||||
dialogues: YarnDialogues;
|
||||
addTriggers: (triggers: Triggers) => void;
|
||||
addTriggers: (triggers: Triggers, run: IRunContext) => void;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,3 +3,27 @@ export * from "./factory";
|
|||
export * from "./prompts";
|
||||
export * from "./triggers";
|
||||
export * from "./types";
|
||||
|
||||
import { GameHost } from "@/core/game-host";
|
||||
import { ContentModule } from "../types";
|
||||
import { createCommandRegistry } from "@/utils/command";
|
||||
import { createStart, createTriggers, Triggers } from "./triggers";
|
||||
import { CombatState, IRunContext } from "./types";
|
||||
|
||||
export class CombatGameHost extends GameHost<CombatState> {
|
||||
public readonly triggers: Triggers;
|
||||
constructor(
|
||||
private module: ContentModule,
|
||||
private runContext: IRunContext,
|
||||
private initialState: CombatState,
|
||||
) {
|
||||
let triggers: Triggers;
|
||||
super(
|
||||
createCommandRegistry(),
|
||||
() => initialState,
|
||||
createStart((triggers = createTriggers(runContext)), runContext),
|
||||
);
|
||||
module.addTriggers(triggers, runContext);
|
||||
this.triggers = triggers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,12 +287,7 @@ export function createTriggers(run: IRunContext) {
|
|||
return triggers;
|
||||
}
|
||||
export type Triggers = ReturnType<typeof createTriggers>;
|
||||
export function createStartWith(
|
||||
build: (triggers: Triggers, run: IRunContext) => void,
|
||||
run: IRunContext,
|
||||
) {
|
||||
const triggers = createTriggers(run);
|
||||
build(triggers, run);
|
||||
export function createStart(triggers: Triggers, run: IRunContext) {
|
||||
return async function (game: CombatGameContext) {
|
||||
await triggers.onCombatStart.execute(game, {});
|
||||
|
||||
|
|
|
|||
|
|
@ -21,3 +21,5 @@ export {
|
|||
CardEffectTarget,
|
||||
IntentEffectTarget,
|
||||
} from "../data/desert";
|
||||
|
||||
export { ContentModule } from "../data";
|
||||
|
|
|
|||
Loading…
Reference in New Issue