Vase
Overview
This component manages the vase's interaction with flowers—including accepting, placing, wilting, and clearing them—while also handling dynamic lighting updates based on flower freshness and time-to-wilt. It integrates with the Entity Component System to provide state persistence, periodic light updates, and event-driven behavior (e.g., entering/exiting limbo).
Dependencies & Tags
- Adds/Removes Tag:
"vase"(viaonenabledhook andOnRemoveFromEntity) - Listens For Events:
"exitlimbo","enterlimbo" - Uses Tuning Values:
TUNING.ENDTABLE_FLOWER_WILTTIME,TUNING.ENDTABLE_LIGHT_UPDATE,TUNING.VASE_FLOWER_SWAPS,TUNING.VASE_FLOWER_MAP - Component Dependencies (implicitly):
instmust supportDoTaskInTime,DoPeriodicTask,RemoveEventCallback,ListenForEvent,IsInLimbo, and have components likestackable,perishable,inventoryitemwhen accepting items.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | (assigned in _ctor) | Reference to the owning entity. |
deleteitemonaccept | boolean | true | If true, the accepted flower item is removed from the world after placement. |
enabled | boolean | true | Whether the vase accepts new flowers. |
fresh | boolean | false | Indicates if the current flower is fresh (non-wilted). |
light | boolean | false | Indicates if the vase emits light. |
flowerid | string? | nil | Identifier for the currently placed flower. |
wilttask | Task? | nil | Task scheduled to wilt the flower after a time delay. |
lighttask | Task? | nil | Periodic task updating light parameters. |
onupdateflowerfn | function? | nil | Callback invoked when flower state changes (flowerid, fresh). |
onupdatelightfn | function? | nil | Callback invoked when light properties (radius, intensity, falloff) change. |
ondecorate | function? | nil | Backward-compatible callback after successful decoration (includes giver, item, flowerid). |
Main Functions
SetFlower(flowerid, wilt_time)
- Description: Places a flower in the vase, initializes wilting and lighting behavior based on flower type and
wilt_time. Handles fresh vs. wilted states, light emission, and task scheduling. - Parameters:
flowerid(string): Identifier for the flower (e.g.,"flower_red").wilt_time(number?): Time in seconds until the flower wilts. If0, flower is wilted immediately. Ifnil, usesTUNING.ENDTABLE_FLOWER_WILTTIME. Non-lightsource flowers ignorewilt_timeand remain fresh without lighting.
WiltFlower()
- Description: Forces the current flower to wilt, canceling tasks and disabling light emission if it was fresh. Triggers a flower update event.
ClearFlower()
- Description: Removes the current flower, resetting state (
flowerid,fresh,light) and canceling all associated tasks and event listeners.
Decorate(giver, item)
- Description: Accepts a placed flower item, validates it, and calls
SetFlower. Handles item removal and calculates wilt time based on perishability. Returnstrueon success. - Parameters:
giver(Entity?): The entity that placed the flower (optional).item(GameItem?): The flower item being placed. Must have a validprefabmapped inTUNING.VASE_FLOWER_MAP.
PushFlower(flowerid, fresh)
- Description: Invokes the
onupdateflowerfncallback (if set) with the current flower state. - Parameters:
flowerid(string?): Current flower ID (ornilif empty).fresh(boolean): Whether the flower is fresh.
PushLight(radius, intensity, falloff)
- Description: Invokes the
onupdatelightfncallback (if set) with dynamic light parameters. - Parameters:
radius(number): Light radius (0–3.0).intensity(number): Light brightness (0–0.8).falloff(number): Light falloff factor (0–1.0).
Enable(), Disable()
- Description: Sets the
enabledstate. Affects whetherDecorateaccepts new items.
HasFlower(), HasFreshFlower()
- Description: Returns
trueif a flower is present (flowerid ~= nil) or fresh (fresh == true), respectively.
GetTimeToWilt()
- Description: Returns remaining time (in seconds) until the current flower wilts, or
nilif no wilt task is active.
LongUpdate(dt)
- Description: Adjusts the wilting task when game time is advanced (e.g., during fast-forward or pause). Maintains accurate remaining time.
OnSave(), OnLoad(data)
- Description: Handles serialization (
OnSave) and deserialization (OnLoad) of flower and wilt state.
GetDebugString()
- Description: Returns a debug string showing the
enabledstate.
Events & Listeners
- Listens For:
"exitlimbo"→ triggersOnExitLimbo"enterlimbo"→ triggersOnEnterLimbo(only when light-emitting flower is present)
- Pushes Events:
- None (uses callbacks instead of event pushing for notifications).