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

@@ -22,6 +22,7 @@ internal interface IComponentPool : IDisposable
public bool Remove(Entity entity);
public bool Has(Entity entity);
public IComponentData Get(Entity entity);
public void Set(Entity entity, in IComponentData component);
public IEnumerable<(Entity entity, IComponentData component)> Enumerate();
}
@@ -30,6 +31,7 @@ internal interface IComponentPool<T> : IComponentPool
where T : IComponentData
{
public void Add(Entity entity, T Component);
public void Set(Entity entity, in T component);
}
internal class ComponentPool<T> : IComponentPool<T>
@@ -151,17 +153,6 @@ internal class ComponentPool<T> : IComponentPool<T>
return ref _components[index].data;
}
public IEnumerable<(Entity entity, IComponentData component)> Enumerate()
{
for (var i = 0; i < _nextId; i++)
{
if (_components[i].owner.IsValid)
{
yield return (_components[i].owner, _components[i].data);
}
}
}
public bool Has(Entity entity)
{
if (entity.ID >= _lookup.Length)
@@ -173,6 +164,15 @@ internal class ComponentPool<T> : IComponentPool<T>
return index != Entity.INVALID_ID && _components[index].owner.Generation == entity.Generation;
}
public void Set(Entity entity, in IComponentData component)
{
if (component is not T typedComponent)
{
throw new ArgumentException($"Component type mismatch. Expected {typeof(T)}, but got {component.GetType()}.");
}
Set(entity, typedComponent);
}
public void Set(Entity entity, in T component)
{
if (!entity.IsValid || entity.ID >= _lookup.Length || GetComponentIndex(entity) == Entity.INVALID_ID)
@@ -185,6 +185,17 @@ internal class ComponentPool<T> : IComponentPool<T>
_components[index].owner = entity;
}
public IEnumerable<(Entity entity, IComponentData component)> Enumerate()
{
for (var i = 0; i < _nextId; i++)
{
if (_components[i].owner.IsValid)
{
yield return (_components[i].owner, _components[i].data);
}
}
}
public void Dispose()
{
_components = Array.Empty<ComponentData>();
@@ -327,11 +338,37 @@ internal class ScriptComponentPool : IComponentPool<ScriptComponent>
return _scriptComponents?.ContainsKey(entity) ?? false;
}
[Obsolete("Use GetAll instead of Get for ScriptComponentPool.")]
public IComponentData Get(Entity entity)
{
throw new NotSupportedException("Use GetAll instead of Get for ScriptComponentPool.");
}
public void Set(Entity entity, in IComponentData component)
{
if (component is not ScriptComponent scriptComponent)
{
throw new ArgumentException($"Component type mismatch. Expected {typeof(ScriptComponent)}, but got {component.GetType()}.");
}
Set(entity, scriptComponent);
}
public void Set(Entity entity, in ScriptComponent component)
{
if (!Has(entity)
|| !_scriptComponents!.TryGetValue(entity, out var scriptList)
|| scriptList == null)
{
return;
}
var index = scriptList.IndexOf(component);
if (index >= 0)
{
scriptList[index] = component;
component.Owner = entity;
}
}
public IEnumerable<(Entity entity, IComponentData component)> Enumerate()
{
if (_scriptComponents == null)