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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user