feat(memory): wire EventMemoryService into GameLoop and SocketServer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,12 +16,14 @@ import { createNarrationService, type NarrationService } from '../llm/narrationS
|
||||
import { narrationEmitter } from '../systems/narrationEmitter.js';
|
||||
import type { EntityId } from '@dflike/shared';
|
||||
import { createThoughtSystem, type ThoughtSystem } from '../systems/thoughtSystem.js';
|
||||
import { createEventMemoryService, type EventMemoryService } from '../llm/eventMemoryService.js';
|
||||
|
||||
export class GameLoop {
|
||||
readonly world: World;
|
||||
readonly map: GameMap;
|
||||
readonly llmService: LlmService;
|
||||
readonly narrationService: NarrationService;
|
||||
readonly eventMemoryService: EventMemoryService;
|
||||
readonly thoughtSystem: ThoughtSystem;
|
||||
public followedEntityIds: Set<EntityId> = new Set();
|
||||
private tick = 0;
|
||||
@@ -34,6 +36,7 @@ export class GameLoop {
|
||||
this.map = new GameMap();
|
||||
this.llmService = createLlmService();
|
||||
this.narrationService = createNarrationService(this.llmService);
|
||||
this.eventMemoryService = createEventMemoryService();
|
||||
this.thoughtSystem = createThoughtSystem(this.llmService, this.narrationService);
|
||||
this.setupMap();
|
||||
this.spawnInitialNPCs(8);
|
||||
|
||||
@@ -45,6 +45,16 @@ export class SocketServer {
|
||||
this.gameLoop.thoughtSystem.onThought = (data) => {
|
||||
this.io.emit('npc-thought', data);
|
||||
};
|
||||
|
||||
this.gameLoop.eventMemoryService.onEventRecorded = (entityId, event) => {
|
||||
// Only send to clients following this NPC
|
||||
for (const [socketId, followedId] of this.followedEntities) {
|
||||
if (followedId === entityId) {
|
||||
const sock = this.io.sockets.sockets.get(socketId);
|
||||
sock?.emit('memory-event', { entityId, event });
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private setupConnections(): void {
|
||||
@@ -118,6 +128,14 @@ export class SocketServer {
|
||||
socket.on('follow-npc', (data: { entityId: EntityId | null }) => {
|
||||
this.followedEntities.set(socket.id, data.entityId);
|
||||
this.rebuildFollowedEntityIds();
|
||||
|
||||
// Send memory history when following a new NPC
|
||||
if (data.entityId !== null) {
|
||||
const events = this.gameLoop.eventMemoryService.getEvents(data.entityId);
|
||||
if (events.length > 0) {
|
||||
socket.emit('memory-history', { entityId: data.entityId, events });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Handle disconnect
|
||||
|
||||
Reference in New Issue
Block a user