feat: expand editor scripting asset and viewport flow

This commit is contained in:
2026-04-03 13:22:30 +08:00
parent ed8c27fde2
commit a05d0b80a2
124 changed files with 10397 additions and 1737 deletions

View File

@@ -1,5 +1,7 @@
#include <gtest/gtest.h>
#include <XCEngine/Core/Asset/AssetImportService.h>
#include <XCEngine/Core/Asset/ProjectAssetIndex.h>
#include <XCEngine/Core/Asset/ResourceManager.h>
#include <XCEngine/Core/IO/IResourceLoader.h>
#include <XCEngine/Resources/Mesh/Mesh.h>
@@ -7,6 +9,8 @@
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <filesystem>
#include <fstream>
#include <functional>
#include <mutex>
#include <thread>
@@ -155,4 +159,77 @@ TEST(ResourceManager_Test, ConcurrentAsyncLoadsCoalesceSameMeshPath) {
manager.Shutdown();
}
TEST(ResourceManager_Test, AssetLookupFallbackRefreshesSnapshotForNewProjectAsset) {
namespace fs = std::filesystem;
ResourceManager& manager = ResourceManager::Get();
manager.Initialize();
const fs::path projectRoot = fs::temp_directory_path() / "xc_resource_manager_asset_lookup_test";
const fs::path assetsDir = projectRoot / "Assets";
const fs::path materialPath = assetsDir / "runtime.material";
fs::remove_all(projectRoot);
fs::create_directories(assetsDir);
manager.SetResourceRoot(projectRoot.string().c_str());
{
std::ofstream materialFile(materialPath);
ASSERT_TRUE(materialFile.is_open());
materialFile << "{\n";
materialFile << " \"renderQueue\": \"geometry\"\n";
materialFile << "}\n";
}
AssetRef assetRef;
EXPECT_TRUE(manager.TryGetAssetRef("Assets/runtime.material", ResourceType::Material, assetRef));
EXPECT_TRUE(assetRef.IsValid());
XCEngine::Containers::String resolvedPath;
EXPECT_TRUE(manager.TryResolveAssetPath(assetRef, resolvedPath));
EXPECT_EQ(std::string(resolvedPath.CStr()), "Assets/runtime.material");
manager.SetResourceRoot("");
manager.Shutdown();
fs::remove_all(projectRoot);
}
TEST(ProjectAssetIndex_Test, RefreshesSnapshotThroughImportServiceOnCacheMiss) {
namespace fs = std::filesystem;
AssetImportService importService;
importService.Initialize();
const fs::path projectRoot = fs::temp_directory_path() / "xc_project_asset_index_refresh_test";
const fs::path assetsDir = projectRoot / "Assets";
const fs::path materialPath = assetsDir / "runtime.material";
fs::remove_all(projectRoot);
fs::create_directories(assetsDir);
importService.SetProjectRoot(projectRoot.string().c_str());
ProjectAssetIndex assetIndex;
assetIndex.RefreshFrom(importService);
{
std::ofstream materialFile(materialPath);
ASSERT_TRUE(materialFile.is_open());
materialFile << "{\n";
materialFile << " \"renderQueue\": \"geometry\"\n";
materialFile << "}\n";
}
AssetRef assetRef;
EXPECT_TRUE(assetIndex.TryGetAssetRef(importService, "Assets/runtime.material", ResourceType::Material, assetRef));
EXPECT_TRUE(assetRef.IsValid());
XCEngine::Containers::String resolvedPath;
EXPECT_TRUE(assetIndex.TryResolveAssetPath(importService, assetRef, resolvedPath));
EXPECT_EQ(std::string(resolvedPath.CStr()), "Assets/runtime.material");
importService.Shutdown();
fs::remove_all(projectRoot);
}
} // namespace