fix(climate): 🐛 Prevent crashes in ecological event spawning by adding null/absent checks for resource configurations
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
0c734578e0
commit
5e3624eb29
1 changed files with 7 additions and 1 deletions
|
|
@ -91,7 +91,13 @@ static func spawn_resource(tile: Variant, cfg: Dictionary) -> void:
|
|||
spawn_resource_weighted(tile, table)
|
||||
return
|
||||
|
||||
var resource_id: String = cfg.get("spawns_resource", "")
|
||||
# `Dictionary.get(key, default)` only returns `default` when the key is
|
||||
# ABSENT — a config with an explicit `"spawns_resource": null` returns
|
||||
# `null` (Nil), which crashes a direct assignment to a typed `String`.
|
||||
# Guard the null/absent case → no-spawn, matching `resource_terrain` below.
|
||||
var resource_id: String = ""
|
||||
if cfg.get("spawns_resource") != null:
|
||||
resource_id = str(cfg["spawns_resource"])
|
||||
if resource_id == "" or resource_id == "null":
|
||||
return
|
||||
var resource_terrain: Variant = cfg.get("resource_terrain", null)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue