- game/npc-logic.js → reference/npc-logic.js (added REFERENCE PROTOTYPE header) - scripts/guardrails.js → reference/guardrails.js (added REFERENCE PROTOTYPE header) - New reference/README.md with integration instructions Closes #196
28 lines
841 B
JavaScript
28 lines
841 B
JavaScript
/**
|
|
* REFERENCE PROTOTYPE — NOT LOADED BY RUNTIME
|
|
*
|
|
* This file is dormant. It uses ES module syntax (export default),
|
|
* which is incompatible with <script> tag loading.
|
|
*
|
|
* To integrate: remove the default export, add <script src="reference/npc-logic.js">
|
|
* to index.html, and wire NPCStateMachine into the game engine lifecycle.
|
|
*/
|
|
|
|
class NPCStateMachine {
|
|
constructor(states) {
|
|
this.states = states;
|
|
this.current = 'idle';
|
|
}
|
|
update(context) {
|
|
const state = this.states[this.current];
|
|
for (const transition of state.transitions) {
|
|
if (transition.condition(context)) {
|
|
this.current = transition.target;
|
|
console.log(`NPC transitioned to ${this.current}`);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
export default NPCStateMachine;
|