Sim objects¶
Overview¶
Objects on the map live in the sim layer (src/sim/core/objects/). They are pure logic – no PixiJS. The client uses ObjectFactory and TextureProvider to create and render them.
Folder structure¶
| Path | Contents |
|---|---|
objects/base/ |
AbstractObject, LandscapeElementObject, ResourceObject, types.ts |
objects/landscape/ |
PineTreeObject, StoneChunkObject |
objects/resources/ |
WoodLogObject, StoneBrickObject |
objects/colonist/ |
ColonistObject |
objects/interfaces/ |
GatherableInterface, StackableInterface, TextureProvider, ActionExecutor |
ObjectManager.ts, index.ts |
Manager and re-exports |
Hierarchy¶
AbstractObject (base/)
├── ColonistObject (colonist/)
├── LandscapeElementObject (base/)
│ ├── PineTreeObject (landscape/) – GatherableInterface
│ └── StoneChunkObject (landscape/) – GatherableInterface
└── ResourceObject (base/)
├── WoodLogObject (resources/)
└── StoneBrickObject (resources/)
AbstractObject¶
Base for all map objects. Defines:
| Method | Purpose |
|---|---|
getPosition(), setPosition() |
Tile (x, y) |
getUUID(), getId() |
Unique id for persistence |
getTexture() |
Textures + relative positions (client-provided) |
getDisplaySize(), getClickableSize(), getClickableOffset() |
Size and click area |
getName(), getType() |
Display name and type id |
getPanelType() |
'object', 'workshop', 'citizen', or null |
getActions() |
Action definitions (id, name, duration, etc.) |
isClickableAt(), isDisplayedAt() |
Hit testing |
serialize(), deserialize() |
Save/load |
Interfaces¶
GatherableInterface¶
Objects that can be gathered (chop, mine):
getDrop(): { type: string; quantity: number }[]– drops when gathereddispatchGatherAction(onComplete)– start gather work (rendering layer handles completion)
Implemented by: PineTreeObject, StoneChunkObject
StackableInterface¶
Objects with quantity:
getQuantity(): numbergetMaxStack(): number
Implemented by: WoodLogObject, StoneBrickObject (via ResourceObject)
TextureProvider¶
Injected by the client. Used for getTexture():
getTextureByPosition(row, col)– sprite sheetgetTextureByAsset(path)– asset pathgetTextureFromSpriteSheet(path, frameCol, frameRow, cols, rows)– sprite sheet frames
ActionExecutor¶
Injected by the client. Used by jobs to run actions (chop, mine):
executeAction(objectId, actionId, onProgress?, onComplete?, options?)canExecuteAction(objectId, actionId)
ColonistObject¶
- Skills – level and XP per skill (e.g. Woodworking, Mining)
- Needs – sleeping, drinking, eating, recreation (0–100, decay over time)
- Job –
currentJobId,allowedJobTypes,canDoJob(),setJobAllowed() - Haul –
carriedObject,setCarriedObject() - Needs logic –
tickNeeds(),fulfillDrinking(),fulfillSleep(),getLowNeedMessages() - Overlay –
getOverlayDescriptor()(Zzz when sleeping, need messages with cooldown);setOverlayCooldownUntil(ts)called by view after bubble display time - XP –
addSkillXp(skillName, xp)– 1 XP per 0.1s of work
See Needs & movement for need decay and job creation.
Object types¶
| Type | Class | Gatherable | Stackable | Drops |
|---|---|---|---|---|
colonist |
ColonistObject | – | – | – |
pine_tree |
PineTreeObject | ✓ | – | 25 wood_log |
stone_chunk |
StoneChunkObject | ✓ | – | 10 stone_brick |
wood_log |
WoodLogObject | – | ✓ (max 100) | – |
stone_brick |
StoneBrickObject | – | ✓ | – |
ObjectManager¶
- Storage:
Map<uuid, AbstractObject>and spatial indexMap<tileKey, Set<uuid>> - Add/remove:
addObject(),removeObject(uuid),removeObjectAt(x, y) - Move:
moveObject(uuid, newX, newY)– updates spatial index - Lookup:
getObjectByUUID(),getObjectAt(x, y)(clickable),getObjectsAt(x, y)(spatial) - Serialization:
serialize(),deserialize(data, objectFactory)
ObjectFactory¶
Client (src/client/ui/utils/ObjectFactory.ts) creates objects from serialized data:
- Uses
TextureProviderImplfor textures - Maps
type→ constructor:pine_tree,stone_chunk,wood_log,stone_brick,colonist - Passes colonist data (name, age, skills, needs, etc.) for
ColonistObject
Adding a new object type¶
- Create class in the appropriate subdir (
objects/landscape/,objects/resources/, orobjects/colonist/) extending AbstractObject, ResourceObject, or LandscapeElementObject from../base/ - Implement
getType(),getName(),getTexture(),getDisplaySize(),getClickableSize(),getActions() - Export from the subdir
index.tsand fromobjects/index.ts - Add case in
ObjectFactory.createObject()(client) for the new type - If gatherable: implement
GatherableInterfaceand register action (e.g. chop) in game data - If stackable: extend
ResourceObjectand implementgetMaxStack()