Refactor project structure and improve performance

Changed the `ProjectRepository` class to be static for easier usage.
Changed `ProjectService` constants to public properties for accessibility.
Changed `App.xaml` to consolidate theme resources into `Override.xaml`.
Changed `App.xaml.cs` to implement an `AppStateMachine` for better state management.
Changed `ConsolePage` and `HierarchyPage` to utilize the new ViewModel structure.
Changed `ProjectPage` to use the `ExplorerItem` model for asset display.
Changed `Entity` and `EntityManager` to enhance component management with a new `IComponentData` interface.
Changed the `Logger` class to introduce structured logging functionality.
Changed the system architecture to support dependency management for better organization.
Changed the `QueryEnumerable` class to allow for more flexible entity queries.
Changed the `TypeHandle` class to improve efficiency in retrieving type handles.
Changed the `World` class to support robust world management and multiple worlds.
Updated the `Test` class to demonstrate the new entity and component management system.
This commit is contained in:
2025-06-05 21:45:50 +09:00
parent 61bbb1bc68
commit bab3be2508
69 changed files with 2184 additions and 1582 deletions

View File

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

View File

@@ -0,0 +1,28 @@
using System.Threading.Tasks;
namespace Ghost.Editor.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.Editor.View.Windows;
using System.Threading.Tasks;
namespace Ghost.Editor.Infrastructures.AppState;
internal class LandingState : IAppState
{
private LandingWindow? _window;
public Task OnExitingAsync()
{
if (App.Window == _window)
{
App.Window = null;
}
return Task.CompletedTask;
}
public Task OnEnteringAsync(object? parameter)
{
_window = App.GetService<LandingWindow>();
App.Window = _window;
_window.Activate();
return Task.CompletedTask;
}
public Task OnExitedAsync()
{
if (App.Window == _window)
{
App.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.Editor.Infrastructures.AppState;
internal enum StateKey
{
None,
Landing,
EngineEditor,
}