Biome generation

This commit is contained in:
2026-03-19 13:45:33 -05:00
parent fedb426cfc
commit 6d97e5324c
8 changed files with 376 additions and 36 deletions
+42 -2
View File
@@ -24,6 +24,7 @@ var _tracked_node: Node3D
var _tile_nodes: Dictionary = {}
var _camera_start_offset := Vector3(0.0, 6.0, 10.0)
var _border_material: StandardMaterial3D
var _biome_materials: Dictionary = {}
var _known_locations: Dictionary = {}
var _locations_loaded := false
var _character_id := ""
@@ -111,7 +112,7 @@ func _rebuild_tiles(center: Vector2i) -> void:
wanted_keys[coord] = true
if _tile_nodes.has(coord):
continue
_spawn_tile(coord, _get_location_name(coord))
_spawn_tile(coord, _get_location_name(coord), _get_location_biome_key(coord))
for key in _tile_nodes.keys():
if wanted_keys.has(key):
@@ -122,7 +123,7 @@ func _rebuild_tiles(center: Vector2i) -> void:
_tile_nodes.erase(key)
func _spawn_tile(coord: Vector2i, location_name: String) -> void:
func _spawn_tile(coord: Vector2i, location_name: String, biome_key: String) -> void:
var tile_root := Node3D.new()
tile_root.name = "Tile_%d_%d" % [coord.x, coord.y]
tile_root.position = _coord_to_world(coord)
@@ -141,6 +142,9 @@ func _spawn_tile(coord: Vector2i, location_name: String) -> void:
var tile := _block.duplicate() as MeshInstance3D
tile.name = "TileMesh"
tile.visible = true
var biome_material := _get_biome_material(tile, biome_key)
if biome_material:
tile.material_override = biome_material
tile_body.add_child(tile)
tile.add_child(_create_tile_border())
@@ -206,6 +210,7 @@ func _ensure_selected_location_exists(coord: Vector2i) -> void:
_known_locations[coord] = {
"id": "",
"name": _selected_location_name(coord),
"biomeKey": "plains",
"resources": []
}
@@ -277,6 +282,7 @@ func _load_existing_locations() -> void:
_known_locations[coord] = {
"id": String(location.get("id", "")).strip_edges(),
"name": location_name,
"biomeKey": String(location.get("biomeKey", "plains")).strip_edges(),
"resources": _parse_location_resources(location.get("resources", []))
}
loaded_count += 1
@@ -433,6 +439,11 @@ func _get_location_name(coord: Vector2i) -> String:
return String(location_data.get("name", "Location %d,%d" % [coord.x, coord.y]))
func _get_location_biome_key(coord: Vector2i) -> String:
var location_data := _get_location_data(coord)
return String(location_data.get("biomeKey", "plains")).strip_edges()
func _parse_location_resources(resources_value: Variant) -> Array:
var results: Array = []
if typeof(resources_value) != TYPE_ARRAY:
@@ -465,3 +476,32 @@ func _update_location_resource(coord: Vector2i, resource_key: String, remaining_
updated_resources.append(resource)
location_data["resources"] = updated_resources
_known_locations[coord] = location_data
func _get_biome_material(tile: MeshInstance3D, biome_key: String) -> Material:
var normalized_biome := biome_key if not biome_key.is_empty() else "plains"
if _biome_materials.has(normalized_biome):
return _biome_materials[normalized_biome]
var source_material := tile.get_active_material(0)
if source_material is StandardMaterial3D:
var material := (source_material as StandardMaterial3D).duplicate() as StandardMaterial3D
material.albedo_color = _get_biome_color(normalized_biome)
_biome_materials[normalized_biome] = material
return material
return source_material
func _get_biome_color(biome_key: String) -> Color:
match biome_key:
"forest":
return Color(0.36, 0.62, 0.34, 1.0)
"wetlands":
return Color(0.28, 0.52, 0.44, 1.0)
"rocky":
return Color(0.52, 0.50, 0.44, 1.0)
"desert":
return Color(0.76, 0.67, 0.38, 1.0)
_:
return Color(0.56, 0.72, 0.38, 1.0)