Refactor project structure and enhance functionality
Changed the project namespace from `Ghost.Editor` to `Ghost.App` across multiple files. Changed the `InternalsVisibleTo` attribute in `AssemblyInfo.cs` to include `Ghost.App`. Changed the `ProjectRepository` class to add new asynchronous methods for retrieving projects by ID, name, and metadata path. Changed the `ProjectService` class to utilize the new asynchronous project loading methods. Changed the `SceneGraph` classes to improve node management and serialization. Changed the `EntityManager` class to enhance entity management with new component handling methods. Added new test classes, `EntityTest` and `SerializationTest`, to ensure reliability in entity and serialization systems. Added the `Ghost.App` project file to establish a modular project structure. Added the `Ghost.Generator` project for automated component serialization code generation. Updated UI components to reflect the new namespace for proper functionality.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
62
Ghost.InternalEditor/Infrastructures/AppState/EditorState.cs
Normal file
62
Ghost.InternalEditor/Infrastructures/AppState/EditorState.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Ghost.App.View.Windows;
|
||||
using Ghost.Data.Models;
|
||||
using Ghost.Data.Services;
|
||||
using Ghost.Engine;
|
||||
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)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
28
Ghost.InternalEditor/Infrastructures/AppState/IAppState.cs
Normal file
28
Ghost.InternalEditor/Infrastructures/AppState/IAppState.cs
Normal 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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Ghost.App.Infrastructures.AppState;
|
||||
|
||||
internal enum StateKey
|
||||
{
|
||||
None,
|
||||
Landing,
|
||||
EngineEditor,
|
||||
}
|
||||
Reference in New Issue
Block a user