Add life rules and implement tests for civilization and life states
- Introduced a new file `life_rules.txt` to define life progression and degradation rules. - Created `test_civilization_state.gd` to validate the functionality of civilization rules and ethics. - Added `test_life.gd` to test life evolution, including initialization, batch processing, and state validation. - Implemented `civilization_state.gd` to manage civilization ethics and space civilization detachment logic. - Ensured all tests check for expected outcomes and validate state integrity after operations.
This commit is contained in:
@@ -19,6 +19,8 @@ var Locale = "en"
|
||||
var OwniverseEntities: Dictionary = {}
|
||||
var OwniverseItems: Dictionary = {}
|
||||
var Templates: Dictionary = {}
|
||||
var LifeRules: Dictionary = {}
|
||||
var CivilizationRules: Dictionary = {}
|
||||
|
||||
var batch_count: float = 40.0 # must be even not odd
|
||||
|
||||
@@ -67,6 +69,11 @@ func format_number(value: float, digits: int = 0) -> String:
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
for row: Dictionary in _read_from_csv("res://data/civilization_rules.txt").values():
|
||||
if not CivilizationRules.has(row.stage):
|
||||
CivilizationRules[row.stage] = {"home": row.home, "span": float(row.span), "stars": float(row.stars), "ethics": {}}
|
||||
CivilizationRules[row.stage].ethics[row.ethic] = row
|
||||
LifeRules = _read_from_csv("res://data/life_rules.txt")
|
||||
OwniverseEntities = _read_from_csv("res://data/owniverse_entities.txt")
|
||||
OwniverseItems = _read_from_csv("res://data/owniverse_items.txt")
|
||||
|
||||
|
||||
@@ -181,6 +181,19 @@ func validate_data(data: Variant) -> String:
|
||||
for field in ["batch_origins", "distribution", "auto_resources", "production_remainders", "auto_star_deficits", "evolution_remainders", "planet_remainders", "blast_remainders", "destruction_remainders"]:
|
||||
if saved.has(field) and not _number_map(saved[field], field == "auto_resources", field != "auto_star_deficits"):
|
||||
return "invalid state." + field
|
||||
if saved.has("ethics"):
|
||||
if not saved.ethics is Dictionary:
|
||||
return "invalid state.ethics"
|
||||
for id in saved.ethics:
|
||||
if not Global.CivilizationRules.has(id) or not _number_map(saved.ethics[id], true):
|
||||
return "invalid state.ethics." + str(id)
|
||||
for ethic in saved.ethics[id]:
|
||||
if ethic not in ["m", "l", "w", "d", "c", "b"]:
|
||||
return "invalid ethic " + str(ethic)
|
||||
if saved.has("life_version") and saved.life_version not in [1, 2]:
|
||||
return "invalid state.life_version"
|
||||
if saved.has("life_remainders") and not _number_map(saved.life_remainders, false, false):
|
||||
return "invalid state.life_remainders"
|
||||
if saved.has("resource_remainders"):
|
||||
if not saved.resource_remainders is Dictionary:
|
||||
return "invalid state.resource_remainders"
|
||||
|
||||
Reference in New Issue
Block a user