|
|
|
@ -7,14 +7,23 @@ import { Container, Graphics, Text, TextStyle } from "pixi.js"; |
|
|
|
const NODE_RADIUS = 18; |
|
|
|
const NODE_GAP = 58; |
|
|
|
|
|
|
|
type ChaseModelLike = Pick<ChaseGameModel, "getState" | "moveThief">; |
|
|
|
type ChaseSceneOptions = { |
|
|
|
model?: ChaseModelLike; |
|
|
|
modelFactory?: () => ChaseModelLike; |
|
|
|
}; |
|
|
|
|
|
|
|
export default class ChaseScene extends BaseScene { |
|
|
|
stage = new Container(); |
|
|
|
private model?: ChaseGameModel; |
|
|
|
private model?: ChaseModelLike; |
|
|
|
private readonly modelFactory?: () => ChaseModelLike; |
|
|
|
private hudText?: Text; |
|
|
|
private graphLayer = new Container(); |
|
|
|
|
|
|
|
constructor() { |
|
|
|
constructor(options: ChaseSceneOptions = {}) { |
|
|
|
super("chase", SceneType.Normal); |
|
|
|
this.model = options.model; |
|
|
|
this.modelFactory = options.modelFactory; |
|
|
|
} |
|
|
|
|
|
|
|
protected async onSceneLayout(): Promise<void> { |
|
|
|
@ -36,14 +45,18 @@ export default class ChaseScene extends BaseScene { |
|
|
|
this.graphLayer.position.set(140, 140); |
|
|
|
this.stage.addChild(this.graphLayer); |
|
|
|
|
|
|
|
this.model = ChaseGameModel.createWithSeed({ |
|
|
|
seed: 20260426, |
|
|
|
difficulty: "normal", |
|
|
|
}); |
|
|
|
this.renderFromModel(); |
|
|
|
if (!this.model) { |
|
|
|
this.model = |
|
|
|
this.modelFactory?.() ?? |
|
|
|
ChaseGameModel.createWithSeed({ |
|
|
|
seed: 20260426, |
|
|
|
difficulty: "normal", |
|
|
|
}); |
|
|
|
} |
|
|
|
this.refreshView(); |
|
|
|
} |
|
|
|
|
|
|
|
private renderFromModel(): void { |
|
|
|
public refreshView(): void { |
|
|
|
if (!this.model || !this.hudText) { |
|
|
|
return; |
|
|
|
} |
|
|
|
@ -51,7 +64,11 @@ export default class ChaseScene extends BaseScene { |
|
|
|
const state = this.model.getState(); |
|
|
|
this.hudText.text = `Turn ${state.turn} | ${state.snapshot.status} | thief=${state.snapshot.thiefNodeId} guard=${state.snapshot.guardNodeId}`; |
|
|
|
|
|
|
|
this.graphLayer.removeChildren(); |
|
|
|
const oldChildren = this.graphLayer.removeChildren(); |
|
|
|
for (const child of oldChildren) { |
|
|
|
child.destroy({ children: true }); |
|
|
|
} |
|
|
|
|
|
|
|
const nodes = Object.values(state.snapshot.graph.nodes); |
|
|
|
for (const node of nodes) { |
|
|
|
const nodeView = new Graphics(); |
|
|
|
@ -79,6 +96,6 @@ export default class ChaseScene extends BaseScene { |
|
|
|
return; |
|
|
|
} |
|
|
|
this.model.moveThief(targetNodeId); |
|
|
|
this.renderFromModel(); |
|
|
|
this.refreshView(); |
|
|
|
} |
|
|
|
} |
|
|
|
|