feat(thought): integrate ThoughtSystem into game loop and socket broadcast
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,12 +15,14 @@ import { generateBackstory } from '../llm/backstoryGenerator.js';
|
||||
import { createNarrationService, type NarrationService } from '../llm/narrationService.js';
|
||||
import { narrationEmitter } from '../systems/narrationEmitter.js';
|
||||
import type { EntityId } from '@dflike/shared';
|
||||
import { createThoughtSystem, type ThoughtSystem } from '../systems/thoughtSystem.js';
|
||||
|
||||
export class GameLoop {
|
||||
readonly world: World;
|
||||
readonly map: GameMap;
|
||||
readonly llmService: LlmService;
|
||||
readonly narrationService: NarrationService;
|
||||
readonly thoughtSystem: ThoughtSystem;
|
||||
public followedEntityIds: Set<EntityId> = new Set();
|
||||
private tick = 0;
|
||||
private interval: ReturnType<typeof setInterval> | null = null;
|
||||
@@ -32,6 +34,7 @@ export class GameLoop {
|
||||
this.map = new GameMap();
|
||||
this.llmService = createLlmService();
|
||||
this.narrationService = createNarrationService(this.llmService);
|
||||
this.thoughtSystem = createThoughtSystem(this.llmService, this.narrationService);
|
||||
this.setupMap();
|
||||
this.spawnInitialNPCs(8);
|
||||
}
|
||||
@@ -93,6 +96,7 @@ export class GameLoop {
|
||||
narrationEmitter(this.world, this.narrationService, this.followedEntityIds);
|
||||
relationshipSystem(this.world);
|
||||
movementSystem(this.world);
|
||||
this.thoughtSystem.update(this.world, this.followedEntityIds, this.tick);
|
||||
|
||||
// Broadcast state periodically
|
||||
if (this.tick % BROADCAST_EVERY_N_TICKS === 0 && this.onBroadcast) {
|
||||
|
||||
@@ -41,6 +41,10 @@ export class SocketServer {
|
||||
narrationService.onEventUpdated = (event) => {
|
||||
this.io.emit('narration-update', { id: event.id, narration: event.narration });
|
||||
};
|
||||
|
||||
this.gameLoop.thoughtSystem.onThought = (data) => {
|
||||
this.io.emit('npc-thought', data);
|
||||
};
|
||||
}
|
||||
|
||||
private setupConnections(): void {
|
||||
|
||||
Reference in New Issue
Block a user