Refactor application structure and add unit tests

Added:
- New `ProgressService` class for managing progress indicators.
- New `AssetDatabase`, `AssetOpenHandlerAttribute`, and `AsyncAssetOpenHandlerAttribute` classes for asset handling.
- `Ghost.UnitTest` project for unit testing with associated files and configurations.

Changed:
- `ActivationHandler` class to ensure correct handling of `LaunchActivatedEventArgs`.
- `App.xaml.cs` to register `INotificationService` and `IProgressService`, replacing `StackedNotificationService`.
- `OnLaunched` method in `App.xaml.cs` to correctly call `ActivationHandler.Handle(args)` and start the host.
- `INavigationAware` interface from internal to public for broader access.
- `EditorState.cs` to activate `EditorApplication` with the current service provider.
- Property names in `AssetItem` and `ExplorerItem` structs to `Name` and `FullName`.
- `NotificationService` class to implement `INotificationService` and refactor notification handling.
- `AssetPathToGlyphConverter` to handle file extensions consistently.
- Bindings in `ProjectPage.xaml` and `ProjectPage.xaml.cs` to use `FullName` instead of `Path`.
- `EngineEditorWindow` and `LandingWindow` classes to utilize new notification and progress services.
- `Logger` class to include a new method for logging errors with exceptions.

Updated:
- Manifest files and project files to reflect new structure and dependencies.
- Solution file `GhostEngine.sln` to include the new unit test project.
- Added several new test classes and methods in `UnitTests.cs`.
This commit is contained in:
2025-06-10 16:32:32 +09:00
parent 40d333b004
commit ff14c0f49a
149 changed files with 1470 additions and 1901 deletions

View File

@@ -0,0 +1,163 @@
using Ghost.Entities;
using Ghost.Entities.Components;
using Ghost.Entities.Systems;
using Ghost.Test.TestFramework;
using System.Numerics;
namespace Ghost.Test;
public partial class EntityTest : ITest
{
public void Run()
{
var world = World.Create();
var entity1 = world.EntityManager.CreateEntity();
var entity2 = world.EntityManager.CreateEntity();
var entity3 = world.EntityManager.CreateEntity();
world.EntityManager.AddComponent(entity1, new Transform { position = new Vector3(1, 2, 3) });
world.EntityManager.AddComponent(entity1, new Mesh { index = 42 });
world.EntityManager.AddScript<UIManager>(entity1);
world.EntityManager.AddScript<EventManager>(entity1);
world.EntityManager.AddComponent(entity2, new Transform { position = new Vector3(4, 5, 6) });
world.EntityManager.AddComponent(entity2, new Mesh { index = 43 });
world.EntityManager.AddScript<UserScript>(entity2);
world.EntityManager.AddComponent(entity3, new Transform { position = new Vector3(7, 8, 9) });
world.EntityManager.AddScript<EventManager>(entity3);
foreach (var (_, transform) in world.Query<Transform>())
{
transform.ValueRW.position += new Vector3(1, 1, 1);
}
foreach (var (_, mesh) in world.Query<Mesh>())
{
mesh.ValueRW.index += 1;
}
world.EntityManager.RemoveEntity(ref entity2);
var entity4 = world.EntityManager.CreateEntity();
world.EntityManager.AddComponent(entity4, new Transform { position = new Vector3(10, 11, 12) });
world.EntityManager.AddComponent(entity4, new Mesh { index = 44 });
world.EntityManager.AddScript<UserScript>(entity4);
world.SystemStorage.AddSystem<TestSystem2>();
world.SystemStorage.AddSystem<TestSystem>();
world.SystemStorage.CreateSystems();
world.SystemStorage.UpdateSystems();
world.Dispose();
}
}
public class TestSystem : ISystem
{
public void OnCreate(in SystemState state)
{
}
public void OnUpdate(in SystemState state)
{
foreach (var (entity, transform) in state.World.Query<Transform>())
{
Console.WriteLine($"Entity {entity.ID}: Transform Position = {transform.ValueRO.position}");
}
}
public void OnDestroy(in SystemState state)
{
}
}
[DependsOn(typeof(TestSystem))]
public class TestSystem2 : ISystem
{
public void OnCreate(in SystemState state)
{
}
public void OnUpdate(in SystemState state)
{
foreach (var (entity, mesh) in state.World.Query<Mesh>())
{
Console.WriteLine($"Entity {entity.ID}: Mesh Index = {mesh.ValueRO.index}");
}
}
public void OnDestroy(in SystemState state)
{
}
}
public struct Transform : IComponentData
{
public Vector3 position;
public Quaternion rotation;
public Vector3 scale;
}
public struct Mesh : IComponentData
{
public uint index;
}
public class UserScript : ScriptComponent
{
public override int ExecutionOrder => -1;
public override void Start()
{
Console.WriteLine("UserScript started for entity: " + Owner.ID);
}
public override void Update()
{
Console.WriteLine("UserScript updating for entity: " + Owner.ID);
}
public override void OnDestroy()
{
Console.WriteLine("UserScript destroyed for entity: " + Owner.ID);
}
}
public class UIManager : ScriptComponent
{
public override void Start()
{
Console.WriteLine("UIManager started for entity: " + Owner.ID);
}
public override void Update()
{
Console.WriteLine("UIManager updating for entity: " + Owner.ID);
}
public override void OnDestroy()
{
Console.WriteLine("UIManager destroyed for entity: " + Owner.ID);
}
}
public class EventManager : ScriptComponent
{
public override void Start()
{
Console.WriteLine("EventManager started for entity: " + Owner.ID);
}
public override void Update()
{
Console.WriteLine("EventManager updating for entity: " + Owner.ID);
}
public override void OnDestroy()
{
Console.WriteLine("EventManager destroyed for entity: " + Owner.ID);
}
}

View File

@@ -0,0 +1,51 @@
using Ghost.Editor.SceneGraph;
using Ghost.Entities;
using Ghost.Test.TestFramework;
using System.Text.Json;
namespace Ghost.Test;
internal class SerializationTest : ITest
{
private const string _TEST_FILE_PATH = "C:/Users/Misaki/Downloads/testScene.ghostscene";
public void Run()
{
var testWorld = World.Create();
var entity1 = SceneGraphHelpers.CreateEntityNode(testWorld, "entity 1");
var entity2 = SceneGraphHelpers.CreateEntityNode(testWorld, "entity 2");
var entity3 = SceneGraphHelpers.CreateEntityNode(testWorld, "entity 3");
var entity4 = SceneGraphHelpers.CreateEntityNode(testWorld, "entity 4");
var entity5 = SceneGraphHelpers.CreateEntityNode(testWorld, "entity 5");
var testScene = new WorldNode(testWorld, "Test Scene");
testWorld.SystemStorage.AddSystem<TestSystem>();
SceneGraphHelpers.AttachChild(testScene, entity1, entity2);
SceneGraphHelpers.AttachChild(testScene, entity1, entity3);
SceneGraphHelpers.AttachChild(testScene, entity2, entity4);
testScene.AddChild(entity1);
testScene.AddChild(entity5);
var createStream = new FileStream(_TEST_FILE_PATH, FileMode.Create, FileAccess.Write, FileShare.None);
var options = new JsonSerializerOptions
{
WriteIndented = true,
IncludeFields = true,
IgnoreReadOnlyProperties = true,
};
JsonSerializer.Serialize(createStream, testScene, options);
createStream.Dispose();
testWorld.Dispose();
var readStream = new FileStream(_TEST_FILE_PATH, FileMode.Open, FileAccess.Read, FileShare.Read);
var deserializedScene = JsonSerializer.Deserialize<WorldNode>(readStream, options) ?? throw new Exception("Deserialization failed.");
deserializedScene.LoadAsync();
}
}