Shaveable
Overview
The Shaveable component enables an entity to be shaved, tracking whether it has a beard via the bearded tag and handling the procedural generation of prize items upon shaving. It integrates with the Entity Component System to support conditional logic for shaving (via can_shave_test), reward distribution (via prize_prefab and prize_count), and state persistence.
Dependencies & Tags
- Adds/removes the
"bearded"tag on the entity based onprize_count. - Relies on the
SpawnPrefabglobal function to generate prize items. - Requires that prize prefabs have an
inventoryitemcomponent if wetness inheritance is needed. - Assumes entities involved may have
inventory,position, orwetnesscomponents for item transfer and environment handling.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
prize_prefab | string? | nil | Prefab name of the item(s) dropped when the entity is shaved. |
prize_count | number? | nil | Number of prize_prefab items to drop on shaving. Also controls whether the "bearded" tag is present. |
can_shave_test | function? | nil | Optional callback (inst, shaver, implement) → (boolean, reason?) that determines if shaving is allowed. Returns true, nil if no test is set. |
on_shaved | function? | nil | Optional callback (inst, shaver, implement) invoked after successful shaving, before returning. |
Main Functions
SetPrize(prize_prefab, prize_count)
- Description: Configures the prefab and quantity of items dropped upon shaving. Also triggers evaluation of the
"bearded"tag viaon_prize_count. - Parameters:
prize_prefab(string?): Prefab name of items to drop. Usenilto disable prize drops.prize_count(number?): Number of items to drop. Non-positive values remove the"bearded"tag.
CanShave(shaver, shaving_implement)
- Description: Validates whether the entity can be shaved by the given actor using the specified tool. Delegates to
can_shave_testif defined. - Parameters:
shaver(Entity?): The entity performing the shave.shaving_implement(Entity?): The tool used (e.g., razor, scissors).
- Returns:
(boolean, reason?)—trueif allowed; otherwisefalseand an optional reason.
Shave(shaver, shaving_implement)
- Description: Executes the shaving action: validates permission, spawns prize items, optionally drops them into the shaver’s inventory or world, and invokes
on_shaved. - Parameters:
shaver(Entity?): The entity performing the shave.shaving_implement(Entity?): The tool used.
- Returns:
trueon success; otherwise(false, reason)fromCanShave.
OnSave()
- Description: Serializes component state for save/load persistence.
- Returns:
{ prize_count = number? }
OnLoad(data)
- Description: Restores component state from saved data.
- Parameters:
data(table): Containsprize_countas restored state.
GetDebugString()
- Description: Returns a debug-friendly string representation (e.g.,
"2 beard_fluff"). - Returns:
string
Events & Listeners
- Listens to
"prize_count"event via theprize_countproperty:self.prize_count = on_prize_countassigns a handler that adds/removes the"bearded"tag whenprize_countis modified externally (e.g., via property sync). - On removal from entity (
OnRemoveFromEntity), it unconditionally removes the"bearded"tag.