Improves tree and ground tile appearance

Refactors tree spawning and rendering:
- Adds seasonal color variations for trees via scripts.
- Introduces `ColorStorage` to manage tree and grass colors
- Removes unused code from tree spawning logic.
- Adjusts ground tile color for better visual appeal.
- Hides debug text on ground tiles.
This commit is contained in:
Dan Baker 2025-06-28 17:21:50 +01:00
parent 734730beee
commit ea5006e8a2
28 changed files with 454 additions and 63 deletions

View file

@ -11,8 +11,7 @@
viewport_path = NodePath("DebugText/DebugTextViewport")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_f37ob"]
albedo_color = Color(0.133333, 0.576471, 0.47451, 1)
metallic = 1.0
albedo_color = Color(0.196078, 0.392157, 0.196078, 1)
[sub_resource type="PlaneMesh" id="PlaneMesh_oqd8f"]
@ -30,6 +29,7 @@ flip_faces = true
script = ExtResource("1_uwxqs")
[node name="DebugText" type="Node3D" parent="."]
visible = false
[node name="DebugTextViewport" type="SubViewport" parent="DebugText"]
size = Vector2i(50, 50)

View file

@ -9,6 +9,9 @@ var cell_info: CellDataResource = null
var spawners_ready: bool = false
var cached_rng: RandomClass = null
# 326432 229379
# Grass - 1a7761 1f6051
func _ready() -> void:
spawners_ready = true

View file

@ -65,50 +65,11 @@ func spawn_tree_at_position(pos: Vector3, tree_resource: TreeDataResource):
# Pass the TreeDataResource to the Tree instance
if tree_instance.has_method("set_tree_data"):
tree_instance.set_tree_data(tree_resource)
elif tree_instance.has_method("setup_tree"):
tree_instance.setup_tree(tree_resource)
else:
Log.pr("Tree instance doesn't have set_tree_data() or setup_tree() method")
Log.pr("Tree instance doesn't have set_tree_data() method")
func is_position_valid(pos: Vector3) -> bool:
for existing_pos in spawned_positions:
if pos.distance_to(existing_pos) < min_distance:
return false
return true
# Alternative method that shuffles trees for more random placement
func spawn_trees_shuffled(cell_info: CellDataResource):
if not cell_info:
return
if not parent_ground_tile:
return
# Clear existing trees
for child in get_children():
child.free()
spawned_positions.clear()
# Create a copy and shuffle for random placement order
var trees_to_spawn = cell_info.trees.duplicate()
trees_to_spawn.shuffle()
var spawned_count = 0
var attempts = 0
var max_attempts = trees_to_spawn.size() * 10
for tree_resource in trees_to_spawn:
if attempts >= max_attempts:
Log.pr("Reached max attempts, could only spawn %d of %d trees" % [spawned_count, trees_to_spawn.size()])
break
var pos = get_random_position()
if is_position_valid(pos):
spawn_tree_at_position(pos, tree_resource as TreeDataResource)
spawned_positions.append(pos)
spawned_count += 1
attempts += 1
Log.pr("Spawned %d of %d trees in cell (shuffled)" % [spawned_count, trees_to_spawn.size()])