2026-09-15 22:01:45 +03:00
extends SceneTree
2026-09-30 08:08:27 +03:00
const E = preload ( "res://world/owniverse/math/exact.gd" )
2026-09-15 22:01:45 +03:00
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 :
2026-09-30 08:08:27 +03:00
checks = E . add ( checks , 1 )
if ( not condition ):
failures = E . add ( failures , 1 )
2026-09-15 22:01:45 +03:00
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 ])
2026-09-29 20:23:20 +03:00
world . catalog . entities [ id ] = entity
2026-09-30 08:08:27 +03:00
world . state . amount [ id ] = 0
world . state . stats . total_amount [ id ] = 0
if E . ne ( entity . group_as , "" ):
world . state . amount [ entity . group_as ] = 0
world . state . stats . total_amount [ entity . group_as ] = 0
2026-09-29 20:23:20 +03:00
world . catalog . entities [ "N" ] . life_product = {}
world . catalog . entities [ "N" ] . product_per_year_type = "H"
2026-09-30 08:08:27 +03:00
world . catalog . entities [ "N" ] . product_per_year_amount = 10
world . catalog . entities [ "N" ] . auto = 0
world . state . amount . N = 1
2026-09-15 22:01:45 +03:00
return world
func dispose ( world ) -> void :
2026-09-29 20:23:20 +03:00
for entity in world . catalog . entities . values ():
2026-09-15 22:01:45 +03:00
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 ()
2026-09-30 08:08:27 +03:00
world . state . amount . H = 8
world . state . amount . He = 2
2026-09-15 22:01:45 +03:00
for locale in [ "en" , "ru" ]:
global . Locale = locale
var text : String = description . render ( world , global , "RD" )
2026-09-30 08:08:27 +03:00
check (( text . contains ( "[b]" ) and ( not text . contains ( "%value" ))), E . add ( "Localized template resolved: " , locale ))
check ( text . contains ( "#40cc40" ), E . add ( "Affordable cost green: " , locale ))
check ( text . contains ( "4.0000E+10" ), E . add ( "Lifespan substituted: " , locale ))
2026-09-15 22:01:45 +03:00
text = description . render ( world , global , "He" )
2026-09-30 08:08:27 +03:00
check (( text . contains ( "He: 20.00% / H: 80.00%" ) and ( not text . contains ( "%value" ))), E . add ( "Helium metadata and mixture: " , locale ))
2026-09-15 22:01:45 +03:00
text = description . render ( world , global , "Shovelin" , "Force" )
2026-09-30 08:08:27 +03:00
check ( E . eq ( text . count ( "]—[/color]" ), 4 ), E . add ( "Missing force levels use dash: " , locale ))
2026-09-15 22:01:45 +03:00
text = description . render ( world , global , "YD" )
2026-09-30 08:08:27 +03:00
check ( text . contains ( "#ff6060" ), E . add ( "Insufficient cost red: " , locale ))
2026-09-15 22:01:45 +03:00
var reordered : Dictionary = { "text" : "%value0% / %value1%" , "value0" : "lifespan" , "value1" : "amount" }
2026-09-30 08:08:27 +03:00
check ( E . eq ( global . render_template ( reordered , { "amount" : "12" , "lifespan" : "99" }), "99 / 12" ), "Metadata chooses variables, not fixed argument positions" )
world . state . amount . RD = 2
world . state . binds . G = { "RD" : 3 , "HP" : 7 }
var values : Dictionary = description . variables ( world , global , "RD" , E . neg ( 2 ))
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" )
2026-09-15 22:01:45 +03:00
values = description . variables ( world , global , "HP" )
2026-09-30 08:08:27 +03:00
check ( E . eq ( values . amount , "7" ), "Planet description includes bound planets" )
world . state . amount . EON1 = 2
world . state . binds . G . EON2 = 3
2026-09-16 19:54:47 +03:00
var saved_state : Dictionary = world . state . duplicate ( true )
2026-09-29 20:23:20 +03:00
var counters : Dictionary = world . presentation . amounts ( world . state , world . catalog )
2026-09-30 08:08:27 +03:00
check ((( E . eq ( counters . HP , 7 ) and E . eq ( counters . LP , 5 )) and E . eq ( counters . Planet , 12 )), "Planet counters include bound objects and aggregate eons" )
check ( E . eq ( counters . RD , 2 ), "Star counters retain available quantity" )
check ( E . eq ( world . state , saved_state ), "Reading counters does not mutate simulation" )
check ( E . eq ( world . presentation . amounts ( world . state , world . catalog , true ) . HP , 0 ), "Produced counters remain independent of current population" )
values = description . variables ( world , global , "RD" , 2 )
check (( values . amount . contains ( "#40cc40" ) and values . amount . contains ( "+2.0" )), "Increase green" )
2026-09-15 22:01:45 +03:00
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 ()
2026-09-30 08:08:27 +03:00
check (( label . bbcode_enabled and label . text . contains ( "Красный карлик" )), "Stage displays localized rich text" )
2026-09-15 22:01:45 +03:00
stage . _update_descriptions ( 0.25 )
2026-09-30 08:08:27 +03:00
world . state . amount . RD = E . add ( world . state . amount . RD , 1 )
2026-09-15 22:01:45 +03:00
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 )
2026-09-30 08:08:27 +03:00
print (( "Descriptions: %d checks, %d failures" % [ checks , failures ]))
quit (( 0 if E . eq ( failures , 0 ) else 1 ))