Refactor save manager validation and update state structure
- Updated the save manager to enforce a new format version (2) and improved validation checks for the save data structure. - Enhanced the `validate_data` function to ensure all required fields are present and valid. - Adjusted the handling of legacy saves and introduced new checks for various state fields. - Improved number formatting in the global script for better readability of large numbers. - Updated tests to reflect changes in the save manager and validation logic, ensuring compatibility with the new state structure. - Added new tests for group indexing and production transactions to ensure correctness of entity management and resource production.
This commit is contained in:
+17
-2
@@ -59,8 +59,23 @@ func get_description(item_id: String, items: Array = []) -> String:
|
||||
|
||||
func format_number(value: float, digits: int = 0) -> String:
|
||||
if value == 0: return ""
|
||||
if value < 10_000:
|
||||
return "%.*f" % [digits, value]
|
||||
# Keep ordinary quantities readable, grouping thousands with spaces.
|
||||
# Scientific notation is reserved for values whose fixed form would be
|
||||
# unwieldy in the UI.
|
||||
if absf(value) < 1_000_000_000.0:
|
||||
var fixed: String = "%.*f" % [digits, value]
|
||||
var parts: PackedStringArray = fixed.split(".", true)
|
||||
var integer: String = parts[0]
|
||||
var sign: String = ""
|
||||
if integer.begins_with("-") or integer.begins_with("+"):
|
||||
sign = integer.left(1)
|
||||
integer = integer.substr(1)
|
||||
var grouped: String = ""
|
||||
while integer.length() > 3:
|
||||
grouped = " " + integer.right(3) + grouped
|
||||
integer = integer.left(integer.length() - 3)
|
||||
grouped = sign + integer + grouped
|
||||
return grouped + ("." + parts[1] if parts.size() > 1 else "")
|
||||
|
||||
var exp_value = int(floor(log(abs(value)) / log(10.0)))
|
||||
var mantissa = value / pow(10.0, exp_value)
|
||||
|
||||
Reference in New Issue
Block a user