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,38 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Ghost.App.Infrastructures.AppState;
internal class AppStateMachine
{
private Dictionary<StateKey, Lazy<IAppState>> s_states = new();
private IAppState? s_current;
public void RegisterState(StateKey key, Func<IAppState> stateFactory)
{
s_states[key] = new(stateFactory);
}
public async Task TransitionToAsync(StateKey stateKey, object? parameter = null)
{
var previous = s_current;
var next = s_states[stateKey].Value;
if (previous != null)
{
await previous.OnExitingAsync();
}
await next.OnEnteringAsync(parameter);
if (previous != null)
{
await previous.OnExitedAsync();
}
await next.OnEnteredAsync(parameter);
s_current = next;
}
}

View File

@@ -0,0 +1,65 @@
using Ghost.App.View.Windows;
using Ghost.Data.Models;
using Ghost.Data.Services;
using Ghost.Editor;
using Ghost.Engine;
using Microsoft.UI.Xaml;
using System;
using System.Threading.Tasks;
namespace Ghost.App.Infrastructures.AppState;
internal class EditorState : IAppState
{
private EngineEditorWindow? _window;
private EngineCore? _engineCore;
public Task OnExitingAsync()
{
if (GhostApplication.Window == _window)
{
GhostApplication.Window = null;
}
return Task.CompletedTask;
}
public async Task OnEnteringAsync(object? parameter)
{
if (parameter is not ProjectMetadataInfo metadataInfo)
{
throw new ArgumentException("Parameter must be of type ProjectMetadata.", nameof(parameter));
}
ProjectService.CurrentProject = metadataInfo;
_engineCore = GhostApplication.GetService<EngineCore>();
await _engineCore.StartAsync(new Engine.Models.LaunchArgument());
_window = GhostApplication.GetService<EngineEditorWindow>();
_window.Activate();
GhostApplication.Window = _window;
}
public async Task OnExitedAsync()
{
if (_engineCore != null)
{
await _engineCore.ShutDownAsync();
}
if (GhostApplication.Window == _window)
{
GhostApplication.Window = null;
}
_window?.Close();
_window = null;
}
public Task OnEnteredAsync(object? parameter)
{
EditorApplication.Activate(parameter, ((GhostApplication)(Application.Current)).Host.Services);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,28 @@
using System.Threading.Tasks;
namespace Ghost.App.Infrastructures.AppState;
internal interface IAppState
{
/// <summary>
/// Called when exiting the state.
/// </summary>
public Task OnExitingAsync();
/// <summary>
/// Called when entering the state, right after OnEnteringAsync.
/// <paramref name="parameter">can be used to pass data into the state, such as a project to load.</summary>
/// </summary>
public Task OnEnteringAsync(object? parameter);
/// <summary>
/// Called when exiting the state, specifically for pose transitions.
/// </summary>
public Task OnExitedAsync();
/// <summary>
/// Called when entered the state, specifically after the state has been fully initialized and is ready for interaction.
/// </summary>
/// <param name="parameter">can be used to pass data into the state, such as a project to load.</param>
public Task OnEnteredAsync(object? parameter);
}

View File

@@ -0,0 +1,44 @@
using Ghost.App.View.Windows;
using System.Threading.Tasks;
namespace Ghost.App.Infrastructures.AppState;
internal class LandingState : IAppState
{
private LandingWindow? _window;
public Task OnExitingAsync()
{
if (GhostApplication.Window == _window)
{
GhostApplication.Window = null;
}
return Task.CompletedTask;
}
public Task OnEnteringAsync(object? parameter)
{
_window = GhostApplication.GetService<LandingWindow>();
GhostApplication.Window = _window;
_window.Activate();
return Task.CompletedTask;
}
public Task OnExitedAsync()
{
if (GhostApplication.Window == _window)
{
GhostApplication.Window = null;
}
_window?.Close();
_window = null;
return Task.CompletedTask;
}
public Task OnEnteredAsync(object? parameter)
{
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,8 @@
namespace Ghost.App.Infrastructures.AppState;
internal enum StateKey
{
None,
Landing,
EngineEditor,
}