feat: use bond-aware classification in state serializer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-07 19:34:22 +00:00
parent 0bfeef7fa1
commit 03f837f95f
+25 -8
View File
@@ -6,7 +6,9 @@ import { TILE_SIZE } from '@dflike/shared';
import type { World } from '../ecs/World.js';
import type { GameMap } from '../map/GameMap.js';
import { getEffectiveStat } from '../systems/statHelpers.js';
import { classify } from '../systems/relationshipHelpers.js';
import { getEffectiveClassification } from '../systems/relationshipHelpers.js';
import type { BondRegistry } from '../systems/bondRegistry.js';
import { hasBond } from '../systems/bondRegistry.js';
export function serializeEntity(world: World, entityId: number): EntityState {
const socialState = world.getComponent<SocialState>(entityId, 'socialState');
@@ -24,14 +26,29 @@ export function serializeEntity(world: World, entityId: number): EntityState {
temperament: getEffectiveStat(world, entityId, 'temperament'),
} : undefined;
const relationshipsComponent = world.getComponent<Relationships>(entityId, 'relationships');
const registry = world.getSingleton<BondRegistry>('bondRegistry');
const relationships = relationshipsComponent && relationshipsComponent.size > 0
? [...relationshipsComponent.entries()].map(([otherId, rel]) => ({
entityId: otherId,
name: world.getComponent<string>(otherId, 'name') ?? `NPC #${otherId}`,
value: Math.round(rel.value * 10) / 10,
classification: classify(rel.value),
status: rel.status,
}))
? [...relationshipsComponent.entries()].map(([otherId, rel]) => {
const sociability = statsComponent ? getEffectiveStat(world, entityId, 'sociability') : 10;
const empathy = statsComponent ? getEffectiveStat(world, entityId, 'empathy') : 10;
const classification = getEffectiveClassification(
otherId, rel.value, relationshipsComponent, sociability, empathy,
registry, entityId,
);
let bond: string | null = null;
if (registry) {
if (hasBond(registry, entityId, otherId, 'partner')) bond = 'partner';
else if (hasBond(registry, entityId, otherId, 'partner', 'former')) bond = 'former_partner';
}
return {
entityId: otherId,
name: world.getComponent<string>(otherId, 'name') ?? `NPC #${otherId}`,
value: Math.round(rel.value * 10) / 10,
classification,
status: rel.status,
bond,
};
})
: undefined;
return {
id: entityId,