Files
owniverse/tests/test_descriptions.gd
T
Kirill 26347fca30 Add comprehensive civilization evolution tests and enhance civilization state management
- Introduced a new test script for civilization evolution (`test_civilization_evolution.gd`) to validate the evolution mechanics, including population dynamics, ethical transitions, and war impacts.
- Updated `README.md` to include instructions for running the new civilization evolution tests.
- Modified `test_civilization_state.gd` to accommodate changes in civilization rules and ensure proper validation of ethical stages.
- Enhanced `test_descriptions.gd` to check for accurate population counters and state validation.
- Adjusted `test_life.gd` to reflect updates in life version management.
- Improved `civilization_state.gd` to include habitat budget calculations and transition management.
- Added `civilization_evolution.gd` to handle the logic for civilization evolution, including population drift, warfare, and colonization mechanics.
- Updated `owniverse.gd` and `owniverse_entity.gd` to integrate new evolution logic and ensure proper initialization of entities.
2026-09-16 19:54:47 +03:00

97 lines
4.8 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends SceneTree
const Clock = preload("res://world/owniverse/simulation_time.gd")
var checks: int = 0
var failures: int = 0
func _initialize() -> void:
call_deferred("run")
func check(condition: bool, message: String) -> void:
checks += 1
if not condition:
failures += 1
push_error(message)
func fixture():
var world = load("res://world/owniverse/owniverse.gd").new()
var global: Node = root.get_node("Global")
for id in global.OwniverseEntities:
var entity = load("res://world/owniverse/owniverse_entity.gd").new(global.OwniverseEntities[id])
world.entities[id] = entity
world.state.amount[id] = 0.0
world.state.stats.total_amount[id] = 0.0
if entity.group_as != "":
world.state.amount[entity.group_as] = 0.0
world.state.stats.total_amount[entity.group_as] = 0.0
world.entities["N"].life_product = {}
world.entities["N"].product_per_year_type = "H"
world.entities["N"].product_per_year_amount = 10.0
world.entities["N"].auto = 0.0
world.state.amount.N = 1.0
return world
func dispose(world) -> void:
for entity in world.entities.values():
entity.free()
world.free()
func run() -> void:
var global: Node = root.get_node("Global")
var description = load("res://world/owniverse/item_description.gd")
var world = fixture()
world.state.amount.H = 8.0
world.state.amount.He = 2.0
for locale in ["en", "ru"]:
global.Locale = locale
var text: String = description.render(world, global, "RD")
check(text.contains("[b]") and not text.contains("%value"), "Localized template resolved: " + locale)
check(text.contains("#40cc40"), "Affordable cost green: " + locale)
check(text.contains("4.0000E+10"), "Lifespan substituted: " + locale)
text = description.render(world, global, "He")
check(text.contains("He: 20.00% / H: 80.00%") and not text.contains("%value"), "Helium metadata and mixture: " + locale)
text = description.render(world, global, "Shovelin", "Force")
check(text.count("]—[/color]") == 4, "Missing force levels use dash: " + locale)
text = description.render(world, global, "YD")
check(text.contains("#ff6060"), "Insufficient cost red: " + locale)
var reordered: Dictionary = {"text": "%value0% / %value1%", "value0": "lifespan", "value1": "amount"}
check(global.render_template(reordered, {"amount": "12", "lifespan": "99"}) == "99 / 12", "Metadata chooses variables, not fixed argument positions")
world.state.amount.RD = 2.0
world.state.binds.G = {"RD": 3.0, "HP": 7.0}
var values: Dictionary = description.variables(world, global, "RD", -2.0)
check(values.amount.contains("2") and values.amount.contains("(5)") and values.amount.contains("#888888"), "Free and total counts with gray binding total")
check(values.amount.contains("#ff6060") and values.amount.contains("−2.0"), "Real-time decrease red")
values = description.variables(world, global, "HP")
check(values.amount == "7", "Planet description includes bound planets")
world.state.amount.EON1 = 2.0
world.state.binds.G.EON2 = 3.0
var saved_state: Dictionary = world.state.duplicate(true)
var counters: Dictionary = world.get_item_amounts()
check(counters.HP == 7.0 and counters.LP == 5.0 and counters.Planet == 12.0, "Planet counters include bound objects and aggregate eons")
check(counters.RD == 2.0, "Star counters retain available quantity")
check(world.state == saved_state, "Reading counters does not mutate simulation")
check(world.get_item_amounts(true).HP == 0.0, "Produced counters remain independent of current population")
values = description.variables(world, global, "RD", 2.0)
check(values.amount.contains("#40cc40") and values.amount.contains("+2.0"), "Increase green")
var stage_script = load("res://stage/stage.gd")
check(stage_script.can_instantiate(), "Stage integration compiles")
var stage = stage_script.new()
stage.owniverse.free()
stage.owniverse = world
var label: RichTextLabel = RichTextLabel.new()
stage.g_item_descriptions = [label]
stage.description_targets[0] = {"id": "RD", "category": "Entity"}
stage._refresh_descriptions()
check(label.bbcode_enabled and label.text.contains("Красный карлик"), "Stage displays localized rich text")
stage._update_descriptions(0.25)
world.state.amount.RD += 1.0
stage._update_descriptions(0.25)
check(label.text.contains("+4.0"), "Selected description refreshes with rate per real second")
global.Locale = "en"
stage._update_descriptions(0.25)
check(label.text.contains("Red Dwarf"), "Selected description follows locale changes")
label.free()
stage.free()
dispose(world)
print("Descriptions: %d checks, %d failures" % [checks, failures])
quit(0 if failures == 0 else 1)