Implement asynchronous save manager with UI update optimizations and add tests for save functionality
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
extends SceneTree
|
||||
|
||||
var checks: int = 0
|
||||
var failures: int = 0
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("run")
|
||||
|
||||
func check(value: bool, message: String) -> void:
|
||||
checks += 1
|
||||
if not value:
|
||||
failures += 1
|
||||
push_error(message)
|
||||
|
||||
func run() -> void:
|
||||
var scene = load("res://world/world.tscn").instantiate()
|
||||
var stage = scene.get_node("Stage")
|
||||
stage.owniverse.free()
|
||||
stage.set_script(load("res://tests/fixtures/ui_stage.gd"))
|
||||
root.add_child(scene)
|
||||
await process_frame
|
||||
await process_frame
|
||||
stage.stage_page_scroller.scroll_horizontal = stage.PAGE_WIDTH
|
||||
await process_frame
|
||||
stage.owniverse.state.amount.H = 1000.0
|
||||
stage.owniverse.state.amount.RD = 2.0
|
||||
stage.owniverse.refresh_item_amounts()
|
||||
stage._update_ui(0.0)
|
||||
var hydrogen = stage.owniverse_items.H
|
||||
var dwarf = stage.owniverse_items.RD
|
||||
check(hydrogen.description.text == "1 000", "Visible page updates immediately on navigation")
|
||||
check(dwarf.description.text == "", "Offscreen counters are not rendered")
|
||||
stage.owniverse.state.amount.H = 2000.0
|
||||
stage.owniverse.refresh_item_amounts()
|
||||
check(stage.owniverse.item_amounts_dirty and stage.owniverse.items_to_update.H == 1000.0, "Simulation invalidates without recalculating display sums")
|
||||
stage._update_ui(0.05)
|
||||
check(hydrogen.description.text == "1 000", "No refresh before interval")
|
||||
stage._update_ui(0.051)
|
||||
check(hydrogen.description.text == "2 000" and not stage.owniverse.item_amounts_dirty, "Latest state appears at interval")
|
||||
stage.item_activated(hydrogen)
|
||||
check(hydrogen.description.text == root.get_node("Global").format_number(stage.owniverse.state.amount.H), "Player production updates counter immediately")
|
||||
check(stage.owniverse.state.amount.H > 2000.0, "Production action actually executed")
|
||||
dwarf.visible = true
|
||||
stage.stage_page_scroller.scroll_horizontal = 2 * stage.PAGE_WIDTH
|
||||
await process_frame
|
||||
stage._update_ui(0.0)
|
||||
check(dwarf.description.text == "2", "Newly visible page receives cached latest values")
|
||||
stage.owniverse.state.time.year = 1234.5
|
||||
stage._update_ui(0.1)
|
||||
check(stage.date_time.text == "1 234.5", "Time uses throttled display with tenths")
|
||||
for entity in stage.owniverse.entities.values(): entity.free()
|
||||
stage.owniverse.free()
|
||||
scene.free()
|
||||
print("UI updates: %d checks, %d failures" % [checks, failures])
|
||||
quit(0 if failures == 0 else 1)
|
||||
Reference in New Issue
Block a user