Refactor project from Ghost.App to Ghost.Editor
Changed the project structure to reflect a shift from `Ghost.App` to `Ghost.Editor`, updating namespaces and class names throughout. Changed the application class in `App.xaml` and `App.xaml.cs` from `GhostApplication` to `EditorApplication`. Changed several service interfaces to reside under `Ghost.Editor.Services.Contracts`, including `IInspectorService`, `INotificationService`, and `IProgressService`. Added `InspectorView` and `InspectorViewModel` classes to manage inspector functionality. Added `NavigationTabView` and `NavigationTabPage` classes to facilitate navigation within the editor. Enhanced `WorldNode` and `EntityNode` classes to support scene graph functionality, including serialization and entity management. Updated the project file `Ghost.Editor.csproj` to reflect the new structure and removed old references. Modified the solution file `GhostEngine.sln` to remove references to `Ghost.App` and include `Ghost.Editor`. Updated unit tests to align with the new namespaces and project structure.
This commit is contained in:
34
Ghost.App/Core/AppState/AppStateMachine.cs
Normal file
34
Ghost.App/Core/AppState/AppStateMachine.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace Ghost.Editor.Core.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.App/Core/AppState/EditorState.cs
Normal file
62
Ghost.App/Core/AppState/EditorState.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Ghost.Data.Models;
|
||||
using Ghost.Data.Services;
|
||||
using Ghost.Editor.Core.AssetHandle;
|
||||
using Ghost.Editor.View.Windows;
|
||||
using Ghost.Engine;
|
||||
|
||||
namespace Ghost.Editor.Core.AppState;
|
||||
|
||||
internal class EditorState : IAppState
|
||||
{
|
||||
private EngineEditorWindow? _window;
|
||||
private EngineCore? _engineCore;
|
||||
|
||||
public Task OnExitingAsync()
|
||||
{
|
||||
if (EditorApplication.Window == _window)
|
||||
{
|
||||
EditorApplication.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 = EditorApplication.GetService<EngineCore>();
|
||||
await _engineCore.StartAsync(new Engine.Models.LaunchArgument());
|
||||
|
||||
_window = EditorApplication.GetService<EngineEditorWindow>();
|
||||
_window.Activate();
|
||||
|
||||
EditorApplication.Window = _window;
|
||||
}
|
||||
|
||||
public async Task OnExitedAsync()
|
||||
{
|
||||
if (_engineCore != null)
|
||||
{
|
||||
await _engineCore.ShutDownAsync();
|
||||
}
|
||||
|
||||
if (EditorApplication.Window == _window)
|
||||
{
|
||||
EditorApplication.Window = null;
|
||||
}
|
||||
|
||||
_window?.Close();
|
||||
_window = null;
|
||||
}
|
||||
|
||||
public Task OnEnteredAsync(object? parameter)
|
||||
{
|
||||
AssetDatabase.Initialize();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
28
Ghost.App/Core/AppState/IAppState.cs
Normal file
28
Ghost.App/Core/AppState/IAppState.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ghost.Editor.Core.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);
|
||||
}
|
||||
45
Ghost.App/Core/AppState/LandingState.cs
Normal file
45
Ghost.App/Core/AppState/LandingState.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Ghost.Editor;
|
||||
using Ghost.Editor.View.Windows;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ghost.Editor.Core.AppState;
|
||||
|
||||
internal class LandingState : IAppState
|
||||
{
|
||||
private LandingWindow? _window;
|
||||
|
||||
public Task OnExitingAsync()
|
||||
{
|
||||
if (EditorApplication.Window == _window)
|
||||
{
|
||||
EditorApplication.Window = null;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task OnEnteringAsync(object? parameter)
|
||||
{
|
||||
_window = EditorApplication.GetService<LandingWindow>();
|
||||
EditorApplication.Window = _window;
|
||||
|
||||
_window.Activate();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task OnExitedAsync()
|
||||
{
|
||||
if (EditorApplication.Window == _window)
|
||||
{
|
||||
EditorApplication.Window = null;
|
||||
}
|
||||
|
||||
_window?.Close();
|
||||
_window = null;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task OnEnteredAsync(object? parameter)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
8
Ghost.App/Core/AppState/StateKey.cs
Normal file
8
Ghost.App/Core/AppState/StateKey.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Ghost.Editor.Core.AppState;
|
||||
|
||||
internal enum StateKey
|
||||
{
|
||||
None,
|
||||
Landing,
|
||||
EngineEditor,
|
||||
}
|
||||
Reference in New Issue
Block a user