feat: use bond-aware classification in state serializer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user