Bloomness
Based on game build 714014 | Last updated: 2026-03-03
Overview
Bloomness tracks and controls the developmental lifecycle of a plant entity through discrete growth stages, culminating in a final "bloom" state. It uses a timer-based system with configurable durations per stage, supports fertilization to extend bloom duration or accelerate progression, and integrates with the entity's update loop. The component calculates and maintains a dynamic bloom rate via optional callback functions and persists state across saves/load cycles.
Usage example
local inst = CreateEntity()
inst:AddComponent("bloomness")
inst.components.bloomness:SetDurations(15, 30) -- stage = 15s, full bloom = 30s
inst.components.bloomness.onlevelchangedfn = function(inst, level) print("Stage:", level) end
inst.components.bloomness:Fertilize(5) -- extends timer based on current stage
inst.components.bloomness:SetLevel(1) -- start growing
Dependencies & tags
Components used: None identified
Tags: Adds blooming tag when is_blooming is true (via inst:HasTag("blooming") — inferred by pattern, not directly used in this component).
The component is self-contained and does not require or directly interact with other components.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
max | number | 3 | Maximum growth stage index (inclusive), defining total stages (0 = seed, 1..max = progressive, max = bloom). |
level | number | 0 | Current growth stage (integer ≥ 0, ≤ max). |
is_blooming | boolean | false | Whether the plant is currently in bloom progression (moving toward next stage). |
timer | number | 0 | Remaining time (scaled by rate) until next stage change. |
rate | number | 1 | Multiplier affecting how fast timer decreases (dt * rate). |
stage_duration | number | 0 | Duration (seconds) to spend at each intermediate stage. |
full_bloom_duration | number | 0 | Duration (seconds) to spend at the final (bloom) stage. |
fertilizer | number | 0 | Accumulated fertilizer value applied (used in rate calculations). |
calcratefn | function | nil | Optional callback (inst, level, is_blooming, fertilizer) → number to compute rate. |
calcfullbloomdurationfn | function | nil | Optional callback (inst, value, timer, base_duration) → number to compute extended bloom time on fertilize. |
onlevelchangedfn | function | nil | Callback (inst, level) triggered after each SetLevel call. |
Main functions
SetLevel(level)
- Description: Sets the growth stage to
level, resetting timers and update behavior accordingly. Stages progress sequentially (0 → 1 → … →max); fertilization has no effect atlevel = 0. - Parameters:
level(number) - Target growth stage index (clamped to≤ max). Passing the currentlevelhas no effect. - Returns: Nothing.
- Error states: Returns early without changes if
levelequalsself.level. When setting tomax,timeris incremented (not reset). For any transition fromlevel = 0, the component begins updating viainst:StartUpdatingComponent(self).
SetDurations(stage, full)
- Description: Configures the base durations (in seconds) for intermediate and final bloom stages.
- Parameters:
stage(number) - Duration to remain at each non-bloom stage (e.g.,10).full(number) - Duration to remain at the final bloom stage (e.g.,20).
- Returns: Nothing.
Fertilize(value)
- Description: Applies fertilizer to extend the current timer or advance progression. At full bloom, it extends
timerby a calculated amount. Otherwise, it may start growth (level = 1), enter bloom (is_blooming = true), and accumulate fertilizer. - Parameters:
value(number, optional) - Fertilizer amount to apply (defaults to0). Ignored if≤ 0in some contexts, but no explicit validation. - Returns: Nothing.
- Error states:
- If
level = max,timeris extended by the optionalcalcfullbloomdurationfncallback. - If
level = 0, calling this implicitly callsSetLevel(1). - No failure paths — always updates
fertilizerandrate.
- If
UpdateRate()
- Description: Recomputes
ratebased on current state and optional callbacks. Always setsrate = 1if no callback is defined. Active only whenlevel > 0. - Parameters: None.
- Returns: Nothing.
OnUpdate(dt)
- Description: Called each frame during active update (when
level > 0). Decrementstimerbydt * rate. Whentimer ≤ 0, advances or regresses the stage. - Parameters:
dt(number) - Delta time in seconds. - Returns: Nothing.
- Error states: When regressing to
level = 0, stops updating and resetstimer = 0.
OnLoad(data)
- Description: Restores component state from saved data. Starts/continues updating if
level > 0. - Parameters:
data(table | nil) - Saved state table (containslevel,timer,rate,is_blooming,fertilizer). - Returns: Nothing.
- Error states: If
data = nil, no state is applied. Missing keys default to0/1/falseas indicated.
GetDebugString()
- Description: Returns a formatted string for debugging/logs.
- Parameters: None.
- Returns: (string) - Example:
"L: 2, B: true, T: 5.30 (x1.25)".
OnSave()
- Description: Returns the component’s state for persistence, or
nilif inactive (level = 0). - Parameters: None.
- Returns: (table | nil) - Save table
{ level, timer, rate, is_blooming, fertilizer }ornil.
LongUpdate(dt)
- Description: Wrapper for
OnUpdatethat only calls it iftimer > 0. May be used for throttled updates. - Parameters:
dt(number). - Returns: Nothing.
Events & listeners
- Listens to: None identified
- Pushes: None identified
(No inst:ListenForEvent or inst:PushEvent calls are present in the component.)