Implements bush and flower spawning on ground tiles based on vegetation density. Adds new assets for bushes and flowers, and introduces multi-mesh rendering for optimized performance. Introduces seasonal color variations for vegetation using a shader for bushes and materials for flowers and grass. Refactors material application into a MaterialManager to handle material assignments over multiple frames. Moves ground tile scripts into a subfolder. Adds floating particles to test scene.
59 lines
1.5 KiB
GDScript
59 lines
1.5 KiB
GDScript
class_name GroundTile
|
|
extends Node3D
|
|
@onready var debug_text: Label = $DebugText/DebugTextViewport/DebugTextLabel
|
|
@onready var tree_spawner = $Trees
|
|
@onready var grass_spawner = $Grass
|
|
@onready var bush_spawner = $Bushes
|
|
@onready var flower_spawner = $Flowers
|
|
@onready var ground = $Ground
|
|
var grid_x: int
|
|
var grid_z: int
|
|
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
|
|
|
|
if cell_info != null:
|
|
spawn_content()
|
|
update_text_label()
|
|
|
|
ground.material_override.albedo_color = ColorData.grass_materials[Season.current]['base']
|
|
|
|
func get_rng() -> RandomClass:
|
|
if cached_rng == null and cell_info:
|
|
cached_rng = RandomClass.get_seeded_instance(cell_info.cell_seed)
|
|
elif cached_rng == null:
|
|
cached_rng = RandomClass.get_shared_instance()
|
|
|
|
return cached_rng
|
|
|
|
func set_grid_location(x, z) -> void:
|
|
grid_x = x
|
|
grid_z = z
|
|
cell_info = MapData.get_map_data(grid_x, grid_z)
|
|
|
|
# Only spawn if spawners are ready
|
|
if spawners_ready and cell_info != null:
|
|
spawn_content()
|
|
|
|
func spawn_content():
|
|
if cell_info == null:
|
|
return
|
|
|
|
if tree_spawner:
|
|
tree_spawner.spawn_trees_for_cell(cell_info)
|
|
if grass_spawner:
|
|
grass_spawner.spawn_grass_for_cell(cell_info)
|
|
if bush_spawner:
|
|
bush_spawner.spawn_bushes_for_cell(cell_info)
|
|
if flower_spawner:
|
|
flower_spawner.spawn_flowers_for_cell(cell_info)
|
|
|
|
|
|
func update_text_label() -> void:
|
|
debug_text.text = str(cell_info.vegetation_density)
|