Refactor project structure and enhance functionality

Added `InternalsVisibleTo` attribute for "Ghost.Editor" in `AssemblyInfo.cs`.
Added a binary file `Empty.zip` to the project.
Added a new `ProjectMetadata` class in `ProjectMetadata.cs`.
Added new states and interfaces for managing application states in `EditorState.cs`, `LandingState.cs`, and `IAppState.cs`.
Added a notification service in `INotificationService.cs` and `StackedNotificationService.cs`.
Added new XAML files for UI components, including `InspectorView.xaml` and `InternalControls.xaml`.

Changed the `ProjectInfo` class in `ProjectInfo.cs` to include a `MetadataPath` property instead of `Path` and `EngineVersion`.
Changed the `TemplateInfo` class in `TemplateInfo.cs` to use a struct instead of a class for `TemplateData`.
Changed the `ProjectService` class to use the new `ProjectRepository` for managing project data.

Removed several using directives and the entire `ProjectRepository` class from `ProjectRepository.cs`, replacing it with a new implementation.
Removed old methods and properties in `EntityManager` and `World` classes to improve entity management and component handling.

Updated the `Ghost.Data.csproj` file to include the new `Empty.zip` file as a content item.
Updated the `ProjectRepository` class to manage project data using SQLite.
Updated various XAML files to include new styles and controls, improving the overall UI design.
Updated the `CreateProjectViewModel` to include a notification service and handle project creation logic.
Updated the test project to include references to the new `Ghost.Graphics` project and modified test cases to align with the new structure.
This commit is contained in:
2025-05-31 01:45:34 +09:00
parent 67b6040b5e
commit 61bbb1bc68
66 changed files with 1923 additions and 733 deletions

View File

@@ -0,0 +1,5 @@
namespace Ghost.Editor.ViewModel.Pages.EngineEditor;
internal class ProjectViewModel
{
}

View File

@@ -2,18 +2,20 @@
using CommunityToolkit.Mvvm.Input;
using Ghost.Data.Models;
using Ghost.Data.Services;
using Ghost.Editor.AppStates;
using Ghost.Editor.Contracts;
using Ghost.Editor.Helpers;
using Ghost.Editor.View.Windows;
using Ghost.Editor.Services;
using Ghost.Engine.Resources;
using Microsoft.UI.Xaml.Controls;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel;
namespace Ghost.Editor.ViewModel.Pages.Landing;
internal partial class CreateProjectViewModel(ProjectService projectService) : ObservableRecipient, INavigationAware
internal partial class CreateProjectViewModel(StackedNotificationService notificationService, ProjectService projectService, AppStateService stateService) : ObservableRecipient, INavigationAware
{
public ObservableCollection<TemplateData> templates = new();
@@ -25,14 +27,14 @@ internal partial class CreateProjectViewModel(ProjectService projectService) : O
}
[ObservableProperty]
public partial string ProjectName
public partial string? ProjectName
{
get;
set;
}
[ObservableProperty]
public partial string ProjectLocation
public partial string? ProjectLocation
{
get;
set;
@@ -40,7 +42,8 @@ internal partial class CreateProjectViewModel(ProjectService projectService) : O
public async void OnNavigatedTo(object? parameter)
{
await foreach (var (path, info) in projectService.GetProjectTemplatesAsync())
templates.Clear();
await foreach (var (path, info) in ProjectService.GetProjectTemplatesAsync())
{
templates.Add(new(path, info));
}
@@ -55,25 +58,39 @@ internal partial class CreateProjectViewModel(ProjectService projectService) : O
[RelayCommand]
private async Task SelectionProjectLocation()
{
ProjectLocation = (await SystemUtilities.OpenFolderPickerAsync())?.Path ?? string.Empty;
var folder = await SystemUtilities.OpenFolderPickerAsync();
if (folder != null)
{
ProjectLocation = folder.Path;
}
}
[RelayCommand]
private async Task CreateProject()
{
if (string.IsNullOrWhiteSpace(ProjectName) || !Directory.Exists(ProjectLocation) || SelectedTemplate == null)
if (string.IsNullOrWhiteSpace(ProjectName)
|| !Directory.Exists(ProjectLocation)
|| !SelectedTemplate.HasValue)
{
notificationService.ShowNotification("Incorrect project info", InfoBarSeverity.Error);
return;
}
var projectPath = await projectService.CreateProjectAsync(ProjectName, ProjectLocation, SelectedTemplate.directory);
var packageVersion = Package.Current.Id.Version;
var newProject = await projectService.AddProjectAsync(ProjectName, projectPath, new System.Version(packageVersion.Major, packageVersion.Minor, packageVersion.Build));
if (EngineEditorWindow.TryLoadProject(newProject))
var result = await projectService.CreateProjectAsync(ProjectName, ProjectLocation, EngineData.s_engineVersion, SelectedTemplate.Value.directory);
if (!result.success || result.data == null)
{
App.GetService<LandingWindow>().Close();
notificationService.ShowNotification(result.message, InfoBarSeverity.Error);
return;
}
var metadata = await ProjectService.LoadMetadataAsync(result.data.MetadataPath); // Metadata should not be null here if create project succeeded
try
{
await stateService.TransitionToAsync(StateKey.EngineEditor, metadata);
}
catch (System.Exception e)
{
notificationService.ShowNotification($"Failed to load project: {e.Message}", InfoBarSeverity.Error);
}
}
}

View File

@@ -6,10 +6,10 @@ namespace Ghost.Editor.ViewModel.Windows;
internal partial class EngineEditorViewModel : ObservableRecipient
{
public string engineVersionDescriptor = $"{EngineData.ENGINE_NAME} - {EngineData.ENGINE_VERSION}";
public string engineVersionDescriptor = $"{EngineData.ENGINE_NAME} - {EngineData.s_engineVersion}";
[ObservableProperty]
public partial ProjectInfo CurrentProject
public partial ProjectMetadata CurrentProject
{
get;
set;