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 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-08 18:38:06 +00:00
parent 6514dde42e
commit 94e4f4b9c2
3 changed files with 23 additions and 20 deletions
+14 -1
View File
@@ -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<ServerEvents, ClientEvents>;
@@ -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();
}
+9 -11
View File
@@ -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 {
-8
View File
@@ -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;