Tests cleanup.

main
Martin Felis 2024-12-01 21:57:39 +01:00
parent 44083114ba
commit 9a829c30b0
3 changed files with 10 additions and 11 deletions

View File

@ -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

View File

@ -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.

View File

@ -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)