feat: derive resource visuals from state
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
class_name HarvestableTreePresentation
|
||||
extends ResourceAmountVisual
|
||||
|
||||
const THINNED_CANOPIES := [&"CanopyLeft", &"CanopyRight"]
|
||||
|
||||
@onready var standing_tree: Node3D = $StandingTree
|
||||
@onready var stump: Node3D = $Stump
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super()
|
||||
|
||||
|
||||
func is_standing_visible() -> bool:
|
||||
return standing_tree.visible
|
||||
|
||||
|
||||
func is_stump_visible() -> bool:
|
||||
return stump.visible
|
||||
|
||||
|
||||
func get_visible_canopy_count() -> int:
|
||||
if not standing_tree.visible:
|
||||
return 0
|
||||
var visible_count := 0
|
||||
for child in standing_tree.get_children():
|
||||
if String(child.name).begins_with("Canopy") and child.visible:
|
||||
visible_count += 1
|
||||
return visible_count
|
||||
|
||||
|
||||
func _apply_resource_amount_visual(
|
||||
_amount_remaining: float, _remaining_ratio: float, tier: AmountTier
|
||||
) -> void:
|
||||
var depleted := tier == AmountTier.DEPLETED
|
||||
standing_tree.visible = not depleted
|
||||
stump.visible = depleted
|
||||
for canopy_name in THINNED_CANOPIES:
|
||||
var canopy := standing_tree.get_node_or_null(NodePath(canopy_name)) as Node3D
|
||||
if canopy != null:
|
||||
canopy.visible = tier == AmountTier.FULL
|
||||
@@ -0,0 +1 @@
|
||||
uid://cpue05wbg6roj
|
||||
@@ -0,0 +1,42 @@
|
||||
[gd_scene load_steps=7 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://world/jajce/HarvestableTreePresentation.gd" id="1_script"]
|
||||
[ext_resource type="PackedScene" path="res://world/jajce/StylizedTree.tscn" id="2_tree"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="Material_stump_bark"]
|
||||
albedo_color = Color(0.29, 0.17, 0.09, 1)
|
||||
roughness = 0.96
|
||||
|
||||
[sub_resource type="CylinderMesh" id="Mesh_stump"]
|
||||
material = SubResource("Material_stump_bark")
|
||||
top_radius = 0.38
|
||||
bottom_radius = 0.48
|
||||
height = 0.82
|
||||
radial_segments = 10
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="Material_stump_cut"]
|
||||
albedo_color = Color(0.69, 0.49, 0.27, 1)
|
||||
roughness = 0.9
|
||||
|
||||
[sub_resource type="CylinderMesh" id="Mesh_stump_cut"]
|
||||
material = SubResource("Material_stump_cut")
|
||||
top_radius = 0.36
|
||||
bottom_radius = 0.37
|
||||
height = 0.055
|
||||
radial_segments = 10
|
||||
|
||||
[node name="HarvestableTreePresentation" type="Node3D"]
|
||||
script = ExtResource("1_script")
|
||||
|
||||
[node name="StandingTree" parent="." instance=ExtResource("2_tree")]
|
||||
|
||||
[node name="Stump" type="Node3D" parent="."]
|
||||
visible = false
|
||||
|
||||
[node name="Bark" type="MeshInstance3D" parent="Stump"]
|
||||
position = Vector3(0, 0.41, 0)
|
||||
mesh = SubResource("Mesh_stump")
|
||||
|
||||
[node name="CutFace" type="MeshInstance3D" parent="Stump"]
|
||||
position = Vector3(0, 0.835, 0)
|
||||
mesh = SubResource("Mesh_stump_cut")
|
||||
@@ -0,0 +1,16 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
|
||||
[ext_resource type="PackedScene" path="res://world/jajce/JajceWorld.tscn" id="1_world"]
|
||||
[ext_resource type="Script" path="res://world/jajce/beauty_camera.gd" id="2_camera"]
|
||||
|
||||
[node name="JajceResourceStateLookdev" type="Node3D"]
|
||||
|
||||
[node name="JajceWorld" parent="." instance=ExtResource("1_world")]
|
||||
|
||||
[node name="ResourceCamera" type="Camera3D" parent="."]
|
||||
position = Vector3(14, 9, 7)
|
||||
current = true
|
||||
fov = 40.0
|
||||
script = ExtResource("2_camera")
|
||||
focus_point = Vector3(34, 3.3, 7)
|
||||
animate_orbit = false
|
||||
@@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=6 format=3]
|
||||
[gd_scene load_steps=7 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://world/jajce/RiverbankResourceCluster.gd" id="1_script"]
|
||||
[ext_resource type="PackedScene" path="res://world/resource_nodes/ResourceNode.tscn" id="2_resource"]
|
||||
[ext_resource type="PackedScene" path="res://world/jajce/StylizedTree.tscn" id="3_tree"]
|
||||
[ext_resource type="PackedScene" path="res://world/jajce/StylizedBerryPatch.tscn" id="4_berry"]
|
||||
[ext_resource type="PackedScene" path="res://assets/foliage/tree.glb" id="5_conifer"]
|
||||
[ext_resource type="PackedScene" path="res://world/jajce/HarvestableTreePresentation.tscn" id="6_harvestable_tree"]
|
||||
|
||||
[node name="RiverbankResourceCluster" type="Node3D"]
|
||||
script = ExtResource("1_script")
|
||||
@@ -66,7 +67,7 @@ discovery_priority = 0.1
|
||||
[node name="MeshInstance3D" parent="ResourceAnchors/Tree_River_Resource_01/Visual"]
|
||||
visible = false
|
||||
|
||||
[node name="TreePresentation" parent="ResourceAnchors/Tree_River_Resource_01/Visual" instance=ExtResource("3_tree")]
|
||||
[node name="TreePresentation" parent="ResourceAnchors/Tree_River_Resource_01/Visual" instance=ExtResource("6_harvestable_tree")]
|
||||
scale = Vector3(1.08, 1.08, 1.08)
|
||||
|
||||
[node name="InteractionPoint" parent="ResourceAnchors/Tree_River_Resource_01"]
|
||||
|
||||
@@ -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