style: apply gdformat formatting across the entire project

Auto-format all GDScript files using gdformat from gdtoolkit.
This is a baseline formatting pass to ensure consistent style:

- Normalizes indentation and spacing
- Wraps long lines to 100 characters
- Removes trailing whitespace
- Standardizes blank lines between functions

68 files reformatted, 8 files left unchanged (3rd-party addon files
with parse errors excluded).
This commit is contained in:
2026-07-05 23:06:23 +02:00
parent 28a2e42c41
commit 4463e524aa
69 changed files with 2253 additions and 1647 deletions
+29 -15
View File
@@ -5,9 +5,11 @@ const SCHEMA_VERSION := 1
var data: Dictionary
func _init(record_data: Dictionary = {}) -> void:
data = record_data.duplicate(true)
static func create(
event_id: int,
event_type: StringName,
@@ -18,25 +20,36 @@ static func create(
item_id: StringName,
amount: float
) -> EconomicEventRecord:
return EconomicEventRecord.new({
"schema_version": SCHEMA_VERSION,
"event_id": event_id,
"event_type": String(event_type),
"tick": tick,
"actor_id": actor_id,
"source_id": String(source_id),
"destination_id": String(destination_id),
"item_id": String(item_id),
"amount": amount
})
return EconomicEventRecord.new(
{
"schema_version": SCHEMA_VERSION,
"event_id": event_id,
"event_type": String(event_type),
"tick": tick,
"actor_id": actor_id,
"source_id": String(source_id),
"destination_id": String(destination_id),
"item_id": String(item_id),
"amount": amount
}
)
static func from_dictionary(record_data: Dictionary) -> EconomicEventRecord:
if int(record_data.get("schema_version", -1)) != SCHEMA_VERSION:
return null
if not record_data.has_all([
"event_id", "event_type", "tick", "actor_id", "source_id",
"destination_id", "item_id", "amount"
]):
if not record_data.has_all(
[
"event_id",
"event_type",
"tick",
"actor_id",
"source_id",
"destination_id",
"item_id",
"amount"
]
):
return null
var normalized := record_data.duplicate(true)
normalized["schema_version"] = SCHEMA_VERSION
@@ -60,5 +73,6 @@ static func from_dictionary(record_data: Dictionary) -> EconomicEventRecord:
return null
return EconomicEventRecord.new(normalized)
func to_dictionary() -> Dictionary:
return data.duplicate(true)
+74 -62
View File
@@ -7,41 +7,47 @@ const PREVIOUS_SCHEMA_VERSION := 2
var data: Dictionary
func _init(record_data: Dictionary = {}) -> void:
data = record_data.duplicate(true)
static func capture(npc: SimNPC) -> NPCStateRecord:
return NPCStateRecord.new({
"schema_version": SCHEMA_VERSION,
"id": npc.id,
"name": npc.npc_name,
"profession": String(npc.profession),
"hunger": npc.hunger,
"energy": npc.energy,
"strength": npc.strength,
"intelligence": npc.intelligence,
"current_task": String(npc.current_task),
"task_state": String(npc.task_state),
"position": [npc.position.x, npc.position.y, npc.position.z],
"is_starving": npc.is_starving,
"starvation_ticks": npc.starvation_ticks,
"starvation_death_threshold": npc.starvation_death_threshold,
"is_dead": npc.is_dead,
"task_duration": npc.task_duration,
"task_progress": npc.task_progress,
"task_complete": npc.task_complete,
"target_id": String(npc.target_id),
"travel_target_position": [
npc.travel_target_position.x,
npc.travel_target_position.y,
npc.travel_target_position.z
],
"has_travel_target": npc.has_travel_target,
"inventory": npc.inventory.duplicate(true),
"last_task": String(npc.last_task),
"random_seed": str(npc.random_source.seed),
"random_state": str(npc.random_source.state)
})
return NPCStateRecord.new(
{
"schema_version": SCHEMA_VERSION,
"id": npc.id,
"name": npc.npc_name,
"profession": String(npc.profession),
"hunger": npc.hunger,
"energy": npc.energy,
"strength": npc.strength,
"intelligence": npc.intelligence,
"current_task": String(npc.current_task),
"task_state": String(npc.task_state),
"position": [npc.position.x, npc.position.y, npc.position.z],
"is_starving": npc.is_starving,
"starvation_ticks": npc.starvation_ticks,
"starvation_death_threshold": npc.starvation_death_threshold,
"is_dead": npc.is_dead,
"task_duration": npc.task_duration,
"task_progress": npc.task_progress,
"task_complete": npc.task_complete,
"target_id": String(npc.target_id),
"travel_target_position":
[
npc.travel_target_position.x,
npc.travel_target_position.y,
npc.travel_target_position.z
],
"has_travel_target": npc.has_travel_target,
"inventory": npc.inventory.duplicate(true),
"last_task": String(npc.last_task),
"random_seed": str(npc.random_source.seed),
"random_state": str(npc.random_source.state)
}
)
static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
var version := int(record_data.get("schema_version", -1))
@@ -49,23 +55,40 @@ static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
record_data = _migrate_legacy(record_data, version)
elif version != SCHEMA_VERSION:
return null
if not record_data.has_all([
"id", "name", "profession", "hunger", "energy", "strength",
"intelligence", "current_task", "task_state", "position",
"is_starving", "starvation_ticks", "starvation_death_threshold",
"is_dead", "task_duration", "task_progress", "task_complete",
"target_id", "travel_target_position", "has_travel_target", "inventory",
"last_task", "random_seed", "random_state"
]):
if not record_data.has_all(
[
"id",
"name",
"profession",
"hunger",
"energy",
"strength",
"intelligence",
"current_task",
"task_state",
"position",
"is_starving",
"starvation_ticks",
"starvation_death_threshold",
"is_dead",
"task_duration",
"task_progress",
"task_complete",
"target_id",
"travel_target_position",
"has_travel_target",
"inventory",
"last_task",
"random_seed",
"random_state"
]
):
return null
var saved_position = record_data["position"]
if not saved_position is Array or saved_position.size() != 3:
return null
var saved_target_position = record_data["travel_target_position"]
if (
not saved_target_position is Array
or saved_target_position.size() != 3
):
if not saved_target_position is Array or saved_target_position.size() != 3:
return null
if not record_data["inventory"] is Dictionary:
return null
@@ -74,36 +97,26 @@ static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
return null
var action_id := StringName(record_data["current_task"])
if (
action_id not in [
SimulationIds.ACTION_IDLE,
SimulationIds.ACTION_DEAD
]
action_id not in [SimulationIds.ACTION_IDLE, SimulationIds.ACTION_DEAD]
and SimulationDefinitions.get_action(action_id) == null
):
return null
var last_action_id := StringName(record_data["last_task"])
if (
not last_action_id.is_empty()
and SimulationDefinitions.get_action(last_action_id) == null
):
if not last_action_id.is_empty() and SimulationDefinitions.get_action(last_action_id) == null:
return null
return NPCStateRecord.new(record_data)
static func _migrate_legacy(
legacy_data: Dictionary,
version: int
) -> Dictionary:
static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary:
var migrated := legacy_data.duplicate(true)
migrated["schema_version"] = SCHEMA_VERSION
if version == LEGACY_SCHEMA_VERSION:
migrated["travel_target_position"] = legacy_data.get(
"position",
[0.0, 0.0, 0.0]
)
migrated["travel_target_position"] = legacy_data.get("position", [0.0, 0.0, 0.0])
migrated["has_travel_target"] = false
migrated["inventory"] = {}
return migrated
func restore(debug_logs: bool) -> SimNPC:
var random_source := RandomNumberGenerator.new()
random_source.seed = String(data["random_seed"]).to_int()
@@ -122,9 +135,7 @@ func restore(debug_logs: bool) -> SimNPC:
npc.current_task = StringName(data["current_task"])
npc.task_state = StringName(data["task_state"])
npc.position = Vector3(
float(saved_position[0]),
float(saved_position[1]),
float(saved_position[2])
float(saved_position[0]), float(saved_position[1]), float(saved_position[2])
)
npc.is_starving = bool(data["is_starving"])
npc.starvation_ticks = int(data["starvation_ticks"])
@@ -146,5 +157,6 @@ func restore(debug_logs: bool) -> SimNPC:
npc.debug_logs = debug_logs
return npc
func to_dictionary() -> Dictionary:
return data.duplicate(true)
+53 -28
View File
@@ -9,22 +9,27 @@ const LEGACY_SCHEMA_VERSION := 1
var data: Dictionary
func _init(record_data: Dictionary = {}) -> void:
data = record_data.duplicate(true)
static func create_from_node(node: ResourceNode) -> ResourceStateRecord:
return ResourceStateRecord.new({
"schema_version": SCHEMA_VERSION,
"node_id": String(node.node_id),
"action_id": String(node.action_id),
"resource_id": String(node.resource_id),
"amount_remaining": node.initial_amount,
"yield_per_action": node.yield_per_action,
"reserved_by": -1,
"enabled": node.initial_enabled,
"can_npcs_use": node.can_npcs_use,
"can_player_use": node.can_player_use
})
return ResourceStateRecord.new(
{
"schema_version": SCHEMA_VERSION,
"node_id": String(node.node_id),
"action_id": String(node.action_id),
"resource_id": String(node.resource_id),
"amount_remaining": node.initial_amount,
"yield_per_action": node.yield_per_action,
"reserved_by": -1,
"enabled": node.initial_enabled,
"can_npcs_use": node.can_npcs_use,
"can_player_use": node.can_player_use
}
)
static func from_dictionary(record_data: Dictionary) -> ResourceStateRecord:
var version := int(record_data.get("schema_version", -1))
@@ -33,26 +38,30 @@ static func from_dictionary(record_data: Dictionary) -> ResourceStateRecord:
elif version != SCHEMA_VERSION:
return null
if not record_data.has_all([
"node_id", "action_id", "resource_id", "amount_remaining",
"yield_per_action", "reserved_by", "enabled", "can_npcs_use",
"can_player_use"
]):
if not record_data.has_all(
[
"node_id",
"action_id",
"resource_id",
"amount_remaining",
"yield_per_action",
"reserved_by",
"enabled",
"can_npcs_use",
"can_player_use"
]
):
return null
if String(record_data["node_id"]).is_empty():
return null
var action_id := StringName(record_data["action_id"])
if (
not action_id.is_empty()
and SimulationDefinitions.get_action(action_id) == null
):
if not action_id.is_empty() and SimulationDefinitions.get_action(action_id) == null:
return null
return ResourceStateRecord.new(record_data)
static func _migrate_v1(legacy_data: Dictionary) -> Dictionary:
if not legacy_data.has_all([
"node_id", "amount_remaining", "reserved_by", "enabled"
]):
if not legacy_data.has_all(["node_id", "amount_remaining", "reserved_by", "enabled"]):
return {}
var migrated := legacy_data.duplicate(true)
migrated["schema_version"] = SCHEMA_VERSION
@@ -63,6 +72,7 @@ static func _migrate_v1(legacy_data: Dictionary) -> Dictionary:
migrated["can_player_use"] = false
return migrated
func apply_definition(node: ResourceNode) -> bool:
if node == null or node.node_id != get_node_id():
return false
@@ -85,44 +95,54 @@ func apply_definition(node: ResourceNode) -> bool:
and can_player_use_resource() == node.can_player_use
)
func get_node_id() -> StringName:
return StringName(data["node_id"])
func get_action_id() -> StringName:
return StringName(data["action_id"])
func get_resource_id() -> StringName:
return StringName(data["resource_id"])
func get_amount_remaining() -> float:
return float(data["amount_remaining"])
func get_yield_per_action() -> float:
return float(data["yield_per_action"])
func get_reserved_by() -> int:
return int(data["reserved_by"])
func is_enabled() -> bool:
return bool(data["enabled"])
func can_npc_use() -> bool:
return bool(data["can_npcs_use"])
func can_player_use_resource() -> bool:
return bool(data["can_player_use"])
func is_depleted() -> bool:
return get_amount_remaining() <= 0.0
func can_extract() -> bool:
return is_enabled() and not is_depleted()
func is_available_for(agent_id: int) -> bool:
return (
can_extract()
and (get_reserved_by() == -1 or get_reserved_by() == agent_id)
)
return can_extract() and (get_reserved_by() == -1 or get_reserved_by() == agent_id)
func reserve(agent_id: int) -> bool:
if not is_available_for(agent_id):
@@ -131,12 +151,14 @@ func reserve(agent_id: int) -> bool:
changed.emit(self)
return true
func release(agent_id: int) -> void:
if get_reserved_by() != agent_id:
return
data["reserved_by"] = -1
changed.emit(self)
func extract(requested_amount: float = -1.0) -> float:
if not can_extract():
return 0.0
@@ -152,6 +174,7 @@ func extract(requested_amount: float = -1.0) -> float:
depleted.emit(self)
return extracted
func set_amount_remaining(amount: float) -> void:
var was_depleted := is_depleted()
data["amount_remaining"] = maxf(amount, 0.0)
@@ -161,9 +184,11 @@ func set_amount_remaining(amount: float) -> void:
if not was_depleted and is_depleted():
depleted.emit(self)
func set_enabled(value: bool) -> void:
data["enabled"] = value
changed.emit(self)
func to_dictionary() -> Dictionary:
return data.duplicate(true)
+28 -16
View File
@@ -13,6 +13,7 @@ var resources: Array[ResourceStateRecord] = []
var storages: Array[StorageStateRecord] = []
var economic_events: Array[EconomicEventRecord] = []
func to_dictionary() -> Dictionary:
var npc_data: Array[Dictionary] = []
for npc_record in npcs:
@@ -39,15 +40,18 @@ func to_dictionary() -> Dictionary:
"economic_events": event_data
}
func to_json() -> String:
return JSON.stringify(to_dictionary())
static func from_json(json_text: String) -> SimulationStateRecord:
var parsed = JSON.parse_string(json_text)
if not parsed is Dictionary:
return null
return from_dictionary(parsed)
static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
if record_data.get("schema", "") != SCHEMA_NAME:
return null
@@ -56,19 +60,25 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
record_data = _migrate_legacy(record_data, version)
elif version != SCHEMA_VERSION:
return null
if not record_data.has_all([
"simulation", "village", "npcs", "resources", "storages",
"economic_events"
]):
if not record_data.has_all(
["simulation", "village", "npcs", "resources", "storages", "economic_events"]
):
return null
var simulation_data = record_data["simulation"]
if not simulation_data is Dictionary:
return null
if not simulation_data.has_all([
"seed", "tick_interval", "tick_count", "clock_accumulator",
"clock_elapsed_ticks", "wander_random_streams", "next_event_id"
]):
if not simulation_data.has_all(
[
"seed",
"tick_interval",
"tick_count",
"clock_accumulator",
"clock_elapsed_ticks",
"wander_random_streams",
"next_event_id"
]
):
return null
var wander_streams = simulation_data["wander_random_streams"]
if not wander_streams is Array:
@@ -160,20 +170,22 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
return record
static func _migrate_legacy(
legacy_data: Dictionary,
version: int
) -> Dictionary:
static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary:
var migrated := legacy_data.duplicate(true)
migrated["schema_version"] = SCHEMA_VERSION
if version == LEGACY_SCHEMA_VERSION:
var village_data: Dictionary = legacy_data.get("village", {})
var initial_food := float(village_data.get("food", 0.0))
migrated["storages"] = [
StorageStateRecord.create(
SimulationIds.STORAGE_VILLAGE_PANTRY,
{String(SimulationIds.RESOURCE_FOOD): initial_food}
).to_dictionary()
(
StorageStateRecord
. create(
SimulationIds.STORAGE_VILLAGE_PANTRY,
{String(SimulationIds.RESOURCE_FOOD): initial_food}
)
. to_dictionary()
)
]
migrated["economic_events"] = []
var simulation_data: Dictionary = migrated.get("simulation", {})
+20 -14
View File
@@ -5,20 +5,23 @@ const SCHEMA_VERSION := 1
var data: Dictionary
func _init(record_data: Dictionary = {}) -> void:
data = record_data.duplicate(true)
static func create(
storage_id: StringName,
initial_amounts: Dictionary,
capacity: float = 100.0
storage_id: StringName, initial_amounts: Dictionary, capacity: float = 100.0
) -> StorageStateRecord:
return StorageStateRecord.new({
"schema_version": SCHEMA_VERSION,
"storage_id": String(storage_id),
"amounts": initial_amounts.duplicate(true),
"capacity": capacity
})
return StorageStateRecord.new(
{
"schema_version": SCHEMA_VERSION,
"storage_id": String(storage_id),
"amounts": initial_amounts.duplicate(true),
"capacity": capacity
}
)
static func from_dictionary(record_data: Dictionary) -> StorageStateRecord:
if int(record_data.get("schema_version", -1)) != SCHEMA_VERSION:
@@ -34,34 +37,36 @@ static func from_dictionary(record_data: Dictionary) -> StorageStateRecord:
normalized["capacity"] = float(record_data["capacity"])
var normalized_amounts := {}
for item_id in record_data["amounts"]:
normalized_amounts[String(item_id)] = float(
record_data["amounts"][item_id]
)
normalized_amounts[String(item_id)] = float(record_data["amounts"][item_id])
normalized["amounts"] = normalized_amounts
return StorageStateRecord.new(normalized)
func get_storage_id() -> StringName:
return StringName(data["storage_id"])
func get_amount(item_id: StringName) -> float:
return float(data["amounts"].get(String(item_id), 0.0))
func get_total_amount() -> float:
var total := 0.0
for amount in data["amounts"].values():
total += float(amount)
return total
func deposit(item_id: StringName, requested_amount: float) -> float:
var accepted := minf(
maxf(requested_amount, 0.0),
maxf(float(data["capacity"]) - get_total_amount(), 0.0)
maxf(requested_amount, 0.0), maxf(float(data["capacity"]) - get_total_amount(), 0.0)
)
if accepted <= 0.0:
return 0.0
data["amounts"][String(item_id)] = get_amount(item_id) + accepted
return accepted
func withdraw(item_id: StringName, requested_amount: float) -> float:
var removed := minf(maxf(requested_amount, 0.0), get_amount(item_id))
if removed <= 0.0:
@@ -69,5 +74,6 @@ func withdraw(item_id: StringName, requested_amount: float) -> float:
data["amounts"][String(item_id)] = get_amount(item_id) - removed
return removed
func to_dictionary() -> Dictionary:
return data.duplicate(true)
+14 -7
View File
@@ -5,17 +5,22 @@ const SCHEMA_VERSION := 1
var data: Dictionary
func _init(record_data: Dictionary = {}) -> void:
data = record_data.duplicate(true)
static func capture(village: SimVillage) -> VillageStateRecord:
return VillageStateRecord.new({
"schema_version": SCHEMA_VERSION,
"food": village.food,
"wood": village.wood,
"safety": village.safety,
"knowledge": village.knowledge
})
return VillageStateRecord.new(
{
"schema_version": SCHEMA_VERSION,
"food": village.food,
"wood": village.wood,
"safety": village.safety,
"knowledge": village.knowledge
}
)
static func from_dictionary(record_data: Dictionary) -> VillageStateRecord:
if int(record_data.get("schema_version", -1)) != SCHEMA_VERSION:
@@ -24,6 +29,7 @@ static func from_dictionary(record_data: Dictionary) -> VillageStateRecord:
return null
return VillageStateRecord.new(record_data)
func restore(debug_logs: bool) -> SimVillage:
var village := SimVillage.new()
village.debug_logs = debug_logs
@@ -35,5 +41,6 @@ func restore(debug_logs: bool) -> SimVillage:
village.update_priorities()
return village
func to_dictionary() -> Dictionary:
return data.duplicate(true)