feat: derive resource visuals from state
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class_name StylizedBerryPatch
|
||||
extends Node3D
|
||||
extends ResourceAmountVisual
|
||||
|
||||
const WIND_SHADER := preload("res://world/jajce/materials/wind.gdshader")
|
||||
const LEAF_POSITIONS := [
|
||||
@@ -31,12 +31,37 @@ const BERRY_POSITIONS := [
|
||||
func _ready() -> void:
|
||||
_build_leaves()
|
||||
_build_berries()
|
||||
super()
|
||||
|
||||
|
||||
func get_presentation_instance_count() -> int:
|
||||
return LEAF_POSITIONS.size() + BERRY_POSITIONS.size()
|
||||
|
||||
|
||||
func get_visible_leaf_count() -> int:
|
||||
return $Leaves.multimesh.visible_instance_count
|
||||
|
||||
|
||||
func get_visible_berry_count() -> int:
|
||||
return $Berries.multimesh.visible_instance_count
|
||||
|
||||
|
||||
func _apply_resource_amount_visual(
|
||||
_amount_remaining: float, remaining_ratio: float, tier: AmountTier
|
||||
) -> void:
|
||||
var visible_leaves := LEAF_POSITIONS.size()
|
||||
if tier == AmountTier.LOW:
|
||||
visible_leaves = 3
|
||||
elif tier == AmountTier.DEPLETED:
|
||||
visible_leaves = 2
|
||||
$Leaves.multimesh.visible_instance_count = visible_leaves
|
||||
|
||||
var visible_berries := ceili(remaining_ratio * BERRY_POSITIONS.size())
|
||||
if tier == AmountTier.DEPLETED:
|
||||
visible_berries = 0
|
||||
$Berries.multimesh.visible_instance_count = visible_berries
|
||||
|
||||
|
||||
func _build_leaves() -> void:
|
||||
var mesh := SphereMesh.new()
|
||||
mesh.radius = 1.0
|
||||
|
||||
Reference in New Issue
Block a user