feat(bt): Add wait and whilst, rename leaf to action
This commit is contained in:
+13
-12
@@ -3,11 +3,11 @@
|
||||
// Architecture:
|
||||
// Behaviour Tree (buildTree) — controls game flow:
|
||||
// parallel
|
||||
// ├── dealerPlay (leaf) — generator loop, auto-plays dealer hand
|
||||
// ├── dealerPlay (action) — generator loop, auto-plays dealer hand
|
||||
// └── cycle
|
||||
// └── seq (sequential)
|
||||
// ├── handleInput (leaf) — reads queued commands
|
||||
// └── render (leaf) — draws via blessed
|
||||
// ├── handleInput (action) — reads queued commands
|
||||
// └── render (action) — draws via blessed
|
||||
//
|
||||
// CommandQueue — processes input:
|
||||
// Keyboard → spawn command entities → CommandQueue.execute()
|
||||
@@ -25,10 +25,11 @@
|
||||
import { World } from "../../src/index";
|
||||
import {
|
||||
buildTree,
|
||||
leaf,
|
||||
action,
|
||||
parallel,
|
||||
cycle,
|
||||
sequential,
|
||||
whilst,
|
||||
} from "../../src/bt/index";
|
||||
import { CommandQueue } from "../../src/commands/index";
|
||||
|
||||
@@ -72,11 +73,11 @@ registerCommands(world, commands, cards);
|
||||
const runner = buildTree(
|
||||
world,
|
||||
parallel([
|
||||
leaf(function* dealerPlay() {
|
||||
while (true) {
|
||||
yield;
|
||||
whilst(
|
||||
() => true,
|
||||
action(() => {
|
||||
const phase = world.getSingleton(GamePhase);
|
||||
if (phase.phase !== "dealerTurn") continue;
|
||||
if (phase.phase !== "dealerTurn") return;
|
||||
|
||||
if (dealerShouldHit(cards.getHand(InDealerHand))) {
|
||||
const cardEntity = cards.drawCard();
|
||||
@@ -86,14 +87,14 @@ const runner = buildTree(
|
||||
} else {
|
||||
resolveRound(world, cards);
|
||||
}
|
||||
}
|
||||
}),
|
||||
}),
|
||||
),
|
||||
cycle(
|
||||
sequential([
|
||||
leaf(() => {
|
||||
action(() => {
|
||||
commands.execute();
|
||||
}),
|
||||
leaf(() => {
|
||||
action(() => {
|
||||
render(world, ui);
|
||||
}),
|
||||
]),
|
||||
|
||||
+13
-12
@@ -3,11 +3,11 @@
|
||||
// Architecture:
|
||||
// Behaviour Tree (buildTree) — controls game flow:
|
||||
// parallel
|
||||
// ├── gravityTick (leaf) — generator loop, auto-drop piece on timer
|
||||
// ├── gravityTick (action) — generator loop, auto-drop piece on timer
|
||||
// └── cycle
|
||||
// └── seq (sequential)
|
||||
// ├── handleInput (leaf) — reads queued commands
|
||||
// └── render (leaf) — draws via blessed
|
||||
// ├── handleInput (action) — reads queued commands
|
||||
// └── render (action) — draws via blessed
|
||||
//
|
||||
// CommandQueue — processes input:
|
||||
// Keyboard → spawn command entities → CommandQueue.execute()
|
||||
@@ -22,10 +22,11 @@
|
||||
import { World } from "../../src/index";
|
||||
import {
|
||||
buildTree,
|
||||
leaf,
|
||||
action,
|
||||
parallel,
|
||||
cycle,
|
||||
sequential,
|
||||
whilst,
|
||||
} from "../../src/bt/index";
|
||||
import { CommandQueue } from "../../src/commands/index";
|
||||
|
||||
@@ -73,11 +74,11 @@ pieces.spawnPiece();
|
||||
const runner = buildTree(
|
||||
world,
|
||||
parallel([
|
||||
leaf(function* gravityTick() {
|
||||
while (true) {
|
||||
const dt: number = yield;
|
||||
whilst(
|
||||
() => true,
|
||||
action((_world, _entity, dt) => {
|
||||
if (world.hasSingleton(GameOver) || world.hasSingleton(Paused)) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
const timer = world.getSingleton(TickTimer);
|
||||
timer.accumulator += dt;
|
||||
@@ -93,14 +94,14 @@ const runner = buildTree(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
}),
|
||||
),
|
||||
cycle(
|
||||
sequential([
|
||||
leaf(() => {
|
||||
action(() => {
|
||||
commands.execute();
|
||||
}),
|
||||
leaf(() => {
|
||||
action(() => {
|
||||
render(world, ui);
|
||||
}),
|
||||
]),
|
||||
|
||||
Reference in New Issue
Block a user