From 9a829c30b04eef2e20ff87c06551dcb5b42aa67c Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 1 Dec 2024 21:57:39 +0100 Subject: [PATCH] Tests cleanup. --- root_ui.gd | 8 -------- scenes/game.gd | 2 ++ tests/scenes/game_tests.gd | 11 ++++++++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/root_ui.gd b/root_ui.gd index 86bc96b..43adfda 100644 --- a/root_ui.gd +++ b/root_ui.gd @@ -14,12 +14,9 @@ const GAME_PROFILE_FOLDER:String = "game_profiles" enum ROOT_UI_STATE { UNDEFINED, MENU, GAME } var _root_ui_state:ROOT_UI_STATE = ROOT_UI_STATE.UNDEFINED -var current_level_resource:String var current_game_profile:GameProfileResource = null var current_game_profile_directory:String = "" -var _game_build_system:BuildSystem = null - func _ready(): var autostart_load_success = false if not autostart_game_profile.is_empty(): @@ -40,7 +37,6 @@ func activate_ui_panel(ui_panel:Control): active_ui_panel = ui_panel - func load_scene(scene_resource:PackedScene): for scene_child in scene.get_children(): scene_child.queue_free() @@ -48,10 +44,6 @@ func load_scene(scene_resource:PackedScene): print("Loading level '" + scene_resource.resource_path + "'") scene.add_child(scene_resource .instantiate()) - current_level_resource = scene_resource.resource_path - - _game_build_system = scene.find_child("BuildSystem", true, false) as BuildSystem - InteractionSystem.player = scene.find_child("Player", true, false) as Player func save_game(): var game:Game = %Scene.get_child(0) as Game diff --git a/scenes/game.gd b/scenes/game.gd index 0a1f8b1..d659b05 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -25,6 +25,8 @@ func _ready(): level = get_node("Level") + InteractionSystem.player = player + register_item_pickups() # Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/tests/scenes/game_tests.gd b/tests/scenes/game_tests.gd index 9f70745..8067b75 100644 --- a/tests/scenes/game_tests.gd +++ b/tests/scenes/game_tests.gd @@ -8,21 +8,26 @@ extends GdUnitTestSuite const __source = 'res://scenes/game.gd' var game_scene:PackedScene = preload("res://scenes/game.tscn") -var _unittest_game_profile_path:String = "user://game_profiles/unittest" +var _unittest_game_profile_path:String = "user://unittest/game_tests/" func test_save_game() -> void: + # Output folder must exist + DirAccess.make_dir_recursive_absolute(_unittest_game_profile_path) + + # Create game var game:Game = game_scene.instantiate() add_child(game) + # Build stuff var floor_resource = load("res://data/structures/floor.tres") - game.build_system.build_structure(floor_resource, Transform3D.IDENTITY) game.build_system.build_structure(floor_resource, Transform3D.IDENTITY.translated(Vector3(1, 0, 0))) + # Save game.save_game(_unittest_game_profile_path) + # Load and check whether the built stuff can be found. var save_data:SaveGameResource = load(_unittest_game_profile_path + "/savegame.tres") as SaveGameResource assert_that(len(save_data.built_structures.keys())).is_equal(1) assert_that(save_data.built_structures.has(floor_resource)).is_equal(true) - assert_that(len(save_data.built_structures[floor_resource])).is_equal(2)