feat: initialize thirst on NPC spawn, handle old saves missing thirst

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-10 20:45:50 +00:00
parent 5c81893001
commit 07b9b2193d
2 changed files with 6 additions and 0 deletions
+1
View File
@@ -15,6 +15,7 @@ export function spawnNPC(world: World, map: GameMap, positionHint?: Position, ev
world.addComponent<Position>(entity, 'position', pos);
world.addComponent<Needs>(entity, 'needs', {
hunger: 40 + Math.random() * 40, // 40-80
thirst: 40 + Math.random() * 40, // 40-80
energy: 40 + Math.random() * 40,
productivity: 60 + Math.random() * 40, // 60-100
});
@@ -109,6 +109,11 @@ function deserializeComponent(name: string, json: string): unknown {
}
return parsed;
}
case 'needs': {
const needs = parsed as any;
if (needs.thirst === undefined) needs.thirst = 80;
return needs;
}
case 'name':
// These are strings directly
return parsed;