Dryer
Overview
The Dryer component enables an entity (like a Drying Rack) to process and dry specific items over time. It manages the item's drying progress, handles spoilage, and reacts to environmental conditions such as rain, pausing the drying process if the entity is exposed. It tracks the ingredient, the eventual product, and allows for custom callbacks at different stages of the drying process.
Dependencies & Tags
Dependencies:
- The entity itself may optionally have a
rainimmunitycomponent to determine if it's affected by rain. - Items placed on the dryer must have a
dryablecomponent. - Items placed on the dryer may optionally have
perishableandediblecomponents, which theDryercomponent interacts with for spoilage and food type tracking. - Relies on
TheWorld.state.israiningfor environmental rain checks. - Utilizes global
SpawnPrefabandLaunchAtfunctions.
Tags:
- Adds:
"dried","drying","candry" - Removes:
"dried","drying","candry"
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | - | A reference to the entity this component is attached to. |
ingredient | string / nil | nil | The prefab name of the item currently being dried. |
product | string / nil | nil | The prefab name of the item after it has been dried. |
buildfile | string / nil | nil | The build file associated with the ingredient's visual representation. |
dried_buildfile | string / nil | nil | The build file associated with the dried product's visual representation. |
foodtype | FOODTYPE / nil | nil | The FOODTYPE of the product, typically inherited from the ingredient. |
remainingtime | number / nil | nil | The remaining duration for the current drying or spoilage task. |
tasktotime | number / nil | nil | The absolute game time when the current drying or spoilage task is expected to complete. |
task | TimedTask / nil | nil | The TimedTask object currently managing the drying or spoilage timer. |
onstartdrying | function / nil | nil | A callback function invoked when an item begins the drying process. |
ondonedrying | function / nil | nil | A callback function invoked when an item finishes drying. |
onharvest | function / nil | nil | A callback function invoked when an item is harvested or removed from the dryer. |
protectedfromrain | boolean / nil | nil | A flag indicating if the dryer is internally considered protected from rain, overriding IsExposedToRain. |
watchingrain | boolean / nil | nil | Internal flag indicating whether the component is currently listening for israining world state changes. |
ingredientperish | number / nil | nil | The percentage of perishability remaining on the ingredient when it was placed. |
Main Functions
ondried(self)
- Description: This local function is bound to the
ingredientandproductproperties. It's automatically called when eitheringredientorproductis set, updating the entity's tags ("dried","drying","candry") to reflect its current state. - Parameters:
self: A reference to theDryercomponent instance.
OnRemoveFromEntity()
- Description: Performs cleanup operations when the
Dryercomponent is removed from its entity. This includes cancelling any active drying tasks and removing all drying-related tags from the entity. - Parameters: None.
SetStartDryingFn(fn)
- Description: Sets a custom callback function to be executed when an item starts drying.
- Parameters:
fn: The function to call, which will receive(inst, ingredient_prefab_name, buildfile_name)as arguments.
SetDoneDryingFn(fn)
- Description: Sets a custom callback function to be executed when an item finishes drying.
- Parameters:
fn: The function to call, which will receive(inst, product_prefab_name, dried_buildfile_name)as arguments.
SetOnHarvestFn(fn)
- Description: Sets a custom callback function to be executed when an item is harvested or otherwise removed from the dryer.
- Parameters:
fn: The function to call, which will receive(inst)as an argument.
CanDry(dryable)
- Description: Checks if the dryer is currently empty and if the provided
dryableentity is a valid item to be dried (i.e., has adryablecomponent). - Parameters:
dryable: The entity to check for suitability for drying.
- Returns:
trueif the item can be dried,falseotherwise.
IsDrying()
- Description: Indicates whether an item is currently in the process of drying on the entity.
- Parameters: None.
- Returns:
trueif aningredientis present (drying),falseotherwise.
IsDone()
- Description: Indicates whether an item has completed the drying process and is ready for harvest.
- Parameters: None.
- Returns:
trueif aproductis present and noingredientis pending,falseotherwise.
GetTimeToDry()
- Description: Returns the remaining time until the current drying process is complete. If not drying, returns 0.
- Parameters: None.
- Returns: The remaining drying time in seconds.
GetTimeToSpoil()
- Description: Returns the remaining time until the dried item spoils. If not dried, returns 0.
- Parameters: None.
- Returns: The remaining spoilage time in seconds.
IsPaused()
- Description: Checks if the current drying or spoilage timer is paused.
- Parameters: None.
- Returns:
trueifremainingtimehas a value (indicating a paused state),falseotherwise.
StartDrying(dryable)
- Description: Initiates the drying process for the specified
dryableitem. It consumes thedryableitem, sets up the drying timer, and starts watching for rain if not protected. - Parameters:
dryable: The entity with adryablecomponent to be processed.
- Returns:
trueif drying successfully started,falseotherwise.
StopDrying(reason)
- Description: Halts the current drying or spoilage process. Depending on the
reasonand current state, it might spawn the product, or spoil the item. - Parameters:
reason: A string indicating why the drying process is stopping (e.g.,"fire").
Pause()
- Description: Pauses the current drying or spoilage timer, storing the remaining time and canceling the active task.
- Parameters: None.
Resume()
- Description: Resumes a paused drying or spoilage timer, creating a new
TimedTaskwith the storedremainingtime. - Parameters: None.
DropItem()
- Description: Removes the item from the dryer and spawns it in the world at the dryer's position. It attempts to preserve perishability relative to its current state.
- Parameters: None.
- Returns:
trueif an item was dropped,falseotherwise.
Harvest(harvester)
- Description: Transfers the completed dried item to the inventory of the specified
harvester. - Parameters:
harvester: The entity attempting to harvest the item, expected to have aninventorycomponent.
- Returns:
trueif the item was successfully harvested,falseotherwise.
LongUpdate(dt)
- Description: Handles periodic updates for the drying/spoilage process, primarily used for offline progress or when a long update is explicitly triggered. It accounts for elapsed time
dtand manages pausing/resuming based on rain exposure. - Parameters:
dt: The delta time (time elapsed since the last update) in seconds.
OnSave()
- Description: Serializes the component's current state (ingredient, product, remaining time, etc.) for saving game progress.
- Parameters: None.
- Returns: A table containing the relevant state data if a product is present, otherwise
nil.
OnLoad(data)
- Description: Deserializes and restores the component's state from saved game data. It re-establishes the drying/spoilage process based on the loaded information.
- Parameters:
data: The table containing the saved component state.
GetDebugString()
- Description: Provides a human-readable string representing the dryer's current status, including whether it's drying, dried, or empty, its product, food type, and remaining times.
- Parameters: None.
- Returns: A formatted debug string.
Events & Listeners
inst:ListenForEvent("gainrainimmunity", OnRainImmunity): Listens for the entity gaining immunity to rain, which causes the dryer to resume if paused.inst:ListenForEvent("loserainimmunity", OnRainVulnerable): Listens for the entity losing rain immunity, which may cause the dryer to pause if exposed to rain.self:WatchWorldState("israining", OnIsRaining): Listens for changes inTheWorld.state.israining, pausing or resuming the dryer based on rain exposure.