Files
GhostEngine/Ghost.App/Infrastructures/AppState/AppStateMachine.cs
Misaki ff14c0f49a 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`.
2025-06-10 16:32:32 +09:00

38 lines
885 B
C#

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;
}
}