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