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:
root
2026-03-08 21:10:00 +00:00
parent fb19f6cf8d
commit b515f7195f
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -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) {
+4
View File
@@ -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 {