Sheltered Replica
Overview
The Sheltered component controls the visual shading transition of an entity between SHELTERED_SHADE (.6) and EXPOSED_SHADE (1.0). It responds to changes in the sheltered state—synchronized via a net_bool—and smoothly interpolates the shade value over time using either a sheltering or exposing speed. The final shade is applied to the entity’s AnimState. This component is typically used for entities like replicas or shades that should visually dim when sheltered (e.g., behind cover) and brighten when exposed.
Dependencies & Tags
- Components used:
inst.AnimState(assumed present on the entity),inst:DoTaskInTime,inst:StartUpdatingComponent,inst:StopUpdatingComponent,inst:ListenForEvent - Networked property:
net_bool("sheltered._issheltered")named"issheltereddirty"on client - Tags added/removed: None
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
_updating | boolean | false | Indicates whether the component is actively updating the shade each frame. |
_shade | number | 1.0 (EXPOSED_SHADE) | Current interpolated shade value applied to AnimState. |
_targetshade | number | 1.0 (EXPOSED_SHADE) | Target shade value based on _issheltered status. |
_shelterspeed | number | (1.0 - 0.6) / 0.2 = 2.0 | Rate of decrease per second when transitioning from exposed to sheltered. |
_exposespeed | number | (1.0 - 0.6) / 0.1 = 4.0 | Rate of increase per second when transitioning from sheltered to exposed. |
_issheltered | net_bool | nil | Networked boolean flag representing whether the entity is in a sheltered state. |
Main Functions
StartSheltered(level)
- Description: Marks the entity as sheltered (sets
_isshelteredtotrue) and triggers a shade check to initiate transition to sheltered shading. - Parameters:
level— Unused in current implementation (appears to be for future/extensibility compatibility).
StopSheltered()
- Description: Marks the entity as not sheltered (sets
_isshelteredtofalse) and triggers a shade check to initiate transition to exposed shading.
IsSheltered()
- Description: Returns
trueif the entity is currently considered sheltered, i.e.,_isshelteredistrueand the current_shadeis at or belowSHELTERED_SHADE. - Returns:
boolean
CheckShade()
- Description: Updates
_targetshadebased on_issheltered’s current value and starts/stops the animation update loop if the current shade (_shade) does/does not match the target. Ensures the shade interpolation loop is active only when needed. - Parameters: None
OnUpdate(dt)
- Description: Interpolates
_shadetoward_targetshadeusing_shelterspeed(decrease) or_exposespeed(increase), clamping betweenSHELTERED_SHADEandEXPOSED_SHADE. Updates theAnimStateoverride with the new_shade. Stops the update loop when the target is reached. - Parameters:
dt— Delta time in seconds (passed automatically by the entity update loop).
Events & Listeners
- Listens for
"issheltereddirty"event (client-side only) to triggerCheckShade()when the networked_isshelteredvalue changes. - Triggers:
"issheltereddirty"internally vianet_boolsynchronization (not explicitlyPushEvent-based, but implied by thenet_boolsetter).