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:
parent
734730beee
commit
ea5006e8a2
28 changed files with 454 additions and 63 deletions
|
|
@ -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()])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue