Refactor project management and enhance architecture

Added a new static class `AssetsPath` for asset management.
Added a new icon file (`icon-256.ico`) for UI representation.
Added new package references to enhance functionality.
Added internals visibility attributes for better testing.
Added a new `EngineEditorViewModel` class for MVVM support.
Added a new `GameObject` class for component management.
Added a new `BitSet` class for efficient bit manipulation.
Added various utility classes to support the new entity system.

Changed the `ID` property in `ProjectInfo` to internal.
Changed the `AddProjectAsync` method to return the created `ProjectInfo`.
Changed the connection string retrieval method to use the new `Command` constant.
Changed the `DataPath` class to use `readonly` fields for folder paths.
Changed the `ActivationHandler` class to use new `DataPath` constants.
Changed the `OpenProjectPage` layout and interaction for better UI.

Updated the target framework to a newer version for compatibility.
Updated the `ProjectService` to use new constants from `DataPath`.
Updated the `World` class to improve entity management.

Refactored the `ProjectRepository` class to encapsulate SQL commands.
Refactored the `Transform` class to use properties for better encapsulation.
This commit is contained in:
2025-04-05 16:07:53 +09:00
parent 62fe30ff2b
commit 7cd881b7d4
44 changed files with 1672 additions and 247 deletions

View File

@@ -1,22 +0,0 @@
using Ghost.Editor.View.Pages.Landing;
using Ghost.Editor.View.Windows;
using Ghost.Editor.ViewModel.Pages.Landing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Ghost.Editor.View.Pages;
internal static partial class HostHelper
{
public static void SetupPageService(HostBuilderContext context, IServiceCollection services)
{
services.AddTransient<LandingWindow>();
services.AddTransient<CreateProjectPage>();
services.AddTransient<CreateProjectViewModel>();
services.AddTransient<OpenProjectPage>();
services.AddSingleton<EngineEditorWindow>();
}
}

View File

@@ -15,7 +15,7 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="16,8">
<Grid Grid.Row="0" Margin="16,8,16,16">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="200" />
@@ -40,12 +40,13 @@
<ListView
x:Name="ProjectListView"
Grid.Row="1"
Padding="16"
Padding="8"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
CornerRadius="{StaticResource OverlayCornerRadius}"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick"
ItemsSource="{x:Bind projects}"
SelectionMode="None"
Visibility="Visible">
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:ProjectInfo">

View File

@@ -1,5 +1,6 @@
using Ghost.Data.Models;
using Ghost.Data.Services;
using Ghost.Editor.View.Windows;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
@@ -25,7 +26,7 @@ internal sealed partial class OpenProjectPage : Page
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
await foreach (var project in _projectService.LoadProjectAsync())
await foreach (var project in _projectService.LoadAllProjectAsync())
{
projects.Add(project);
}
@@ -37,13 +38,19 @@ internal sealed partial class OpenProjectPage : Page
}
}
private void ListView_ItemClick(object sender, ItemClickEventArgs e)
private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
{
if (e.ClickedItem is not ProjectInfo project)
{
return;
}
//TODO: Load project
if (EngineEditorWindow.TryLoadProject(project))
{
App.GetService<LandingWindow>().Close();
project.LastOpened = System.DateTime.Now;
await _projectService.UpdateProjectAsync(project);
}
}
}

View File

@@ -3,12 +3,164 @@
x:Class="Ghost.Editor.View.Windows.EngineEditorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Ghost.Editor.View.Windows"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:winex="using:WinUIEx"
Title="EngineEditorWindow"
mc:Ignorable="d">
<Grid />
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Titlebar -->
<StackPanel
Grid.Row="0"
Padding="8"
Orientation="Horizontal">
<ImageIcon
Width="24"
Height="24"
VerticalAlignment="Center"
Source="ms-appx:///Assets/Icon.targetsize-32.png" />
<TextBlock
Margin="8,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind ViewModel.engineVersionDescriptor}" />
<TextBlock
Margin="8,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind ViewModel.CurrentProject.Name}" />
</StackPanel>
<!-- Toolbar -->
<Grid Grid.Row="1">
<controls:TabbedCommandBar>
<controls:TabbedCommandBar.MenuItems>
<controls:TabbedCommandBarItem Header="Home">
<AppBarButton Label="Undo" />
<AppBarButton Label="Redo" />
<AppBarButton Label="Paste" />
</controls:TabbedCommandBarItem>
<controls:TabbedCommandBarItem Header="Home">
<AppBarButton Label="Undo" />
<AppBarButton Label="Redo" />
<AppBarButton Label="Paste" />
</controls:TabbedCommandBarItem>
<controls:TabbedCommandBarItem Header="Home">
<AppBarButton Label="Undo" />
<AppBarButton Label="Redo" />
<AppBarButton Label="Paste" />
</controls:TabbedCommandBarItem>
</controls:TabbedCommandBar.MenuItems>
</controls:TabbedCommandBar>
</Grid>
<!-- Editor -->
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid
Grid.Column="0"
Width="350"
Background="Aquamarine" />
<Grid Grid.Column="1" />
<Grid
Grid.Column="2"
Width="350"
Background="Bisque" />
</Grid>
<Grid Grid.Row="1" Height="350">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Background="AliceBlue" />
<Grid
Grid.Column="1"
Width="500"
Background="HotPink" />
</Grid>
</Grid>
<!-- Status Bar -->
<Grid
Grid.Row="3"
Height="25"
Background="{ThemeResource SmokeFillColorDefaultBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<FontIcon
Margin="8,0,0,0"
FontSize="16"
Foreground="{ThemeResource SystemFillColorSuccessBrush}"
Glyph="&#xE930;"
Visibility="Visible" />
<Grid Visibility="Collapsed">
<FontIcon
Margin="8,0,0,0"
VerticalAlignment="Center"
FontSize="16"
Foreground="{ThemeResource SystemFillColorAttentionBrush}"
Glyph="&#xE946;" />
<TextBlock
Margin="4,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Text="0" />
<FontIcon
Margin="8,0,0,0"
VerticalAlignment="Center"
FontSize="16"
Foreground="{ThemeResource SystemFillColorCautionBrush}"
Glyph="&#xE7BA;" />
<TextBlock
Margin="4,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Text="0" />
<FontIcon
Margin="8,0,0,0"
VerticalAlignment="Center"
FontSize="16"
Foreground="{ThemeResource SystemFillColorCriticalBrush}"
Glyph="&#xE783;" />
<TextBlock
Margin="4,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Text="0" />
</Grid>
</StackPanel>
</Grid>
</Grid>
</winex:WindowEx>

View File

@@ -1,4 +1,8 @@
using WinUIEx;
using Ghost.Data.Models;
using Ghost.Data.Resources;
using Ghost.Editor.ViewModel.Windows;
using Ghost.Engine.Resources;
using WinUIEx;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
@@ -7,10 +11,43 @@ namespace Ghost.Editor.View.Windows;
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class EngineEditorWindow : WindowEx
internal sealed partial class EngineEditorWindow : WindowEx
{
public EngineEditorViewModel ViewModel
{
get;
}
public EngineEditorWindow()
{
ViewModel = App.GetService<EngineEditorViewModel>();
AppWindow.SetIcon(AssetsPath.AppIconPath);
Title = EngineData.ENGINE_NAME;
ExtendsContentIntoTitleBar = true;
InitializeComponent();
this.CenterOnScreen();
}
public static bool TryLoadProject(ProjectInfo project)
{
try
{
var window = App.GetService<EngineEditorWindow>();
window.ViewModel.CurrentProject = project;
window.Activate();
window.Bindings.Update();
App.SetWindow(window);
return true;
}
catch (System.Exception)
{
return false;
}
}
}

View File

@@ -7,7 +7,6 @@
xmlns:local="using:Ghost.Editor.View.Windows"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:winex="using:WinUIEx"
Title="Landing"
IsResizable="False"
mc:Ignorable="d">
@@ -15,7 +14,7 @@
<MicaBackdrop />
</Window.SystemBackdrop>
<Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="*" />
@@ -55,6 +54,8 @@
x:Name="ContentFrame"
Grid.Row="1"
Padding="8"
CacheMode="BitmapCache"
CacheSize="10"
IsNavigationStackEnabled="False" />
</Grid>
</Grid>

View File

@@ -1,4 +1,6 @@
using Ghost.Editor.View.Pages.Landing;
using Ghost.Data.Resources;
using Ghost.Editor.View.Pages.Landing;
using Ghost.Engine.Resources;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Animation;
using WinUIEx;
@@ -11,6 +13,9 @@ internal sealed partial class LandingWindow : WindowEx
public LandingWindow()
{
AppWindow.SetIcon(AssetsPath.AppIconPath);
Title = EngineData.ENGINE_NAME;
InitializeComponent();
this.SetWindowSize(1000, 750);