From 94e4f4b9c22acbaa30dba406aa0a32d8c5df2b81 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 8 Mar 2026 18:38:06 +0000 Subject: [PATCH] fix: restore superlatives methods, fix event update rebuild, remove dead method - Restore subscribeSuperlatives/unsubscribeSuperlatives/onSuperlativesUpdate on SocketClient (lost during Task 5 refactor) - Fix EventsFeed.updateEvent to rebuild entire element when LLM narration arrives (names may be in different positions) - Remove dead setFollowedEntity method from GameLoop (replaced by SocketServer.rebuildFollowedEntityIds) Co-Authored-By: Claude Opus 4.6 --- client/src/network/SocketClient.ts | 15 ++++++++++++++- client/src/ui/EventsFeed.ts | 20 +++++++++----------- server/src/game/GameLoop.ts | 8 -------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/client/src/network/SocketClient.ts b/client/src/network/SocketClient.ts index 51d5acc..6dbbd6d 100644 --- a/client/src/network/SocketClient.ts +++ b/client/src/network/SocketClient.ts @@ -1,5 +1,5 @@ import { io, Socket } from 'socket.io-client'; -import type { ServerEvents, ClientEvents, WorldState, StateUpdate, PlayerJoined, PlayerLeft, PlayerInput, NarrationEvent } from '@dflike/shared'; +import type { ServerEvents, ClientEvents, WorldState, StateUpdate, PlayerJoined, PlayerLeft, PlayerInput, SuperlativesData, NarrationEvent } from '@dflike/shared'; type TypedSocket = Socket; @@ -13,6 +13,7 @@ export class SocketClient { onStateUpdate: ((data: StateUpdate) => void) | null = null; onPlayerJoined: ((data: PlayerJoined) => void) | null = null; onPlayerLeft: ((data: PlayerLeft) => void) | null = null; + onSuperlativesUpdate: ((data: SuperlativesData) => void) | null = null; onNarrationEvent: ((data: NarrationEvent) => void) | null = null; onNarrationUpdate: ((data: { id: number; narration: string }) => void) | null = null; onNarrationHistory: ((data: NarrationEvent[]) => void) | null = null; @@ -40,6 +41,10 @@ export class SocketClient { this.onPlayerLeft?.(data); }); + this.socket.on('superlatives-update', (data) => { + this.onSuperlativesUpdate?.(data); + }); + this.socket.on('narration-event', (data) => this.onNarrationEvent?.(data)); this.socket.on('narration-update', (data) => this.onNarrationUpdate?.(data)); this.socket.on('narration-history', (data) => this.onNarrationHistory?.(data)); @@ -60,6 +65,14 @@ export class SocketClient { this.socket.emit('follow-npc', { entityId }); } + subscribeSuperlatives(): void { + this.socket.emit('superlatives-subscribe'); + } + + unsubscribeSuperlatives(): void { + this.socket.emit('superlatives-unsubscribe'); + } + disconnect(): void { this.socket.disconnect(); } diff --git a/client/src/ui/EventsFeed.ts b/client/src/ui/EventsFeed.ts index dd77049..fbb6eff 100644 --- a/client/src/ui/EventsFeed.ts +++ b/client/src/ui/EventsFeed.ts @@ -46,17 +46,8 @@ export class EventsFeed { } updateEvent(id: number, narration: string): void { - const el = this.eventElements.get(id); - if (!el) return; - - // Update the narration text - const textSpan = el.querySelector('[data-narration]') as HTMLSpanElement; - if (textSpan) { - textSpan.textContent = narration; - } - - // Update styling to LLM-narrated - el.style.color = '#d0d0f0'; + const oldEl = this.eventElements.get(id); + if (!oldEl) return; // Update the stored event const event = this.events.find((e) => e.id === id); @@ -64,6 +55,13 @@ export class EventsFeed { event.narration = narration; event.isLlmGenerated = true; } + + // Rebuild the entire element (LLM narration may have different name positions) + if (event) { + const newEl = this.createEventElement(event); + oldEl.replaceWith(newEl); + this.eventElements.set(id, newEl); + } } loadHistory(events: NarrationEvent[]): void { diff --git a/server/src/game/GameLoop.ts b/server/src/game/GameLoop.ts index febc060..d90fe2a 100644 --- a/server/src/game/GameLoop.ts +++ b/server/src/game/GameLoop.ts @@ -98,14 +98,6 @@ export class GameLoop { return this.tick; } - setFollowedEntity(entityId: EntityId | null): void { - if (entityId === null) { - this.followedEntityIds.clear(); - } else { - this.followedEntityIds.add(entityId); - } - } - getGameTime(): number { const dayTicks = 100 / ENERGY_DECAY_PER_TICK; const nightTicks = dayTicks / DAY_NIGHT_RATIO;