feat: add play / editor mode

This commit is contained in:
2026-10-22 01:25:53 +02:00
parent 3df0f89343
commit e5d37965a1
13 changed files with 304 additions and 22 deletions
+35
View File
@@ -334,6 +334,40 @@ namespace {
SceneManager::GetInstance().Destroy();
}
void testPlayModeSnapshotRestore()
{
Scene& scene = SceneManager::GetInstance().CreateScene("snapshot");
GameObject* box = scene.CreateGameObject("box");
box->GetTransform().SetLocalPosition({1.f, 2.f, 3.f});
scene.CreateGameObject("other");
scene.CommitPendingAdditions();
scene.SetSelectedObject(box->GetId());
auto snapshot = SceneSerializer::Capture(scene);
check(snapshot.has_value(), "a scene must be capturable without a file");
(*snapshot)["selected"] = box->GetId();
// What play mode does to the scene before Stop restores it
box->GetTransform().SetLocalPosition({9.f, 9.f, 9.f});
scene.CreateGameObject("spawned during play");
scene.CommitPendingAdditions();
check(SceneSerializer::LoadFromJson(scene, *snapshot), "restoring a snapshot must succeed");
scene.CommitPendingAdditions();
check(scene.GetObjects().size() == 2 && findByName(scene, "spawned during play") == nullptr,
"restoring must drop objects created after the snapshot");
const GameObject* restored = findByName(scene, "box");
check(restored != nullptr && close(restored->GetTransform().GetLocalPosition().x, 1.f),
"restoring must bring back the captured transforms");
check(scene.GetSelectedObject() == restored, "the selection must follow the restored object");
check(!SceneSerializer::LoadFromJson(scene, nlohmann::json{{"objects", 5}}),
"an invalid snapshot must be rejected");
check(scene.GetObjects().size() == 2, "a rejected snapshot must leave the scene alone");
SceneManager::GetInstance().Destroy();
}
}
void RunSerializationTests()
@@ -350,4 +384,5 @@ void RunSerializationTests()
testSceneFileIdsAreLocal();
testMaterialJsonRoundTrip();
testSceneValidatesEmbeddedMaterials();
testPlayModeSnapshotRestore();
}