feat: wire socialSystem into game loop, spawner, and state serializer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import { GameMap } from '../map/GameMap.js';
|
||||
import { needsDecaySystem } from '../systems/needsDecaySystem.js';
|
||||
import { npcBrainSystem } from '../systems/npcBrainSystem.js';
|
||||
import { movementSystem } from '../systems/movementSystem.js';
|
||||
import { socialSystem } from '../systems/socialSystem.js';
|
||||
import { spawnNPC } from './spawner.js';
|
||||
|
||||
export class GameLoop {
|
||||
@@ -62,6 +63,7 @@ export class GameLoop {
|
||||
// Run systems in order
|
||||
needsDecaySystem(this.world);
|
||||
npcBrainSystem(this.world, this.map);
|
||||
socialSystem(this.world);
|
||||
movementSystem(this.world);
|
||||
|
||||
// Broadcast state periodically
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { World } from '../ecs/World.js';
|
||||
import type { GameMap } from '../map/GameMap.js';
|
||||
import { generateRandomAppearance } from '../spawner/appearanceGenerator.js';
|
||||
import { generateName } from '../spawner/nameGenerator.js';
|
||||
import type { EntityId, Position, Needs, Movement, NPCBrain, Appearance } from '@dflike/shared';
|
||||
import type { EntityId, Position, Needs, Movement, NPCBrain, Appearance, SocialState } from '@dflike/shared';
|
||||
|
||||
export function spawnNPC(world: World, map: GameMap): EntityId {
|
||||
const entity = world.createEntity();
|
||||
@@ -26,6 +26,14 @@ export function spawnNPC(world: World, map: GameMap): EntityId {
|
||||
});
|
||||
world.addComponent<Appearance>(entity, 'appearance', generateRandomAppearance());
|
||||
world.addComponent<string>(entity, 'name', generateName());
|
||||
world.addComponent<SocialState>(entity, 'socialState', {
|
||||
phase: 'none',
|
||||
partnerId: null,
|
||||
phaseTimer: 0,
|
||||
outcome: null,
|
||||
globalCooldown: 0,
|
||||
pairCooldowns: new Map(),
|
||||
});
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import type {
|
||||
EntityState, WorldState, StateUpdate,
|
||||
Position, Movement, Appearance, Needs, NPCBrain, PlayerControlled,
|
||||
Position, Movement, Appearance, Needs, NPCBrain, PlayerControlled, SocialState,
|
||||
} from '@dflike/shared';
|
||||
import { TILE_SIZE } from '@dflike/shared';
|
||||
import type { World } from '../ecs/World.js';
|
||||
import type { GameMap } from '../map/GameMap.js';
|
||||
|
||||
export function serializeEntity(world: World, entityId: number): EntityState {
|
||||
const socialState = world.getComponent<SocialState>(entityId, 'socialState');
|
||||
return {
|
||||
id: entityId,
|
||||
position: world.getComponent<Position>(entityId, 'position')!,
|
||||
@@ -16,6 +17,11 @@ export function serializeEntity(world: World, entityId: number): EntityState {
|
||||
npcBrain: world.getComponent<NPCBrain>(entityId, 'npcBrain'),
|
||||
playerControlled: world.getComponent<PlayerControlled>(entityId, 'playerControlled'),
|
||||
name: world.getComponent<string>(entityId, 'name'),
|
||||
socialState: socialState ? {
|
||||
phase: socialState.phase,
|
||||
partnerId: socialState.partnerId,
|
||||
outcome: socialState.outcome,
|
||||
} : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user