forked from Misaki/GhostEngine
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:
@@ -1,68 +1,47 @@
|
||||
using Ghost.Data.Models;
|
||||
using Ghost.Data.Services;
|
||||
using Ghost.Editor.AppStates;
|
||||
using Ghost.Editor.Services;
|
||||
using Ghost.Editor.ViewModels.Pages.Landing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace Ghost.Editor.View.Pages.Landing;
|
||||
|
||||
internal sealed partial class OpenProjectPage : Page
|
||||
{
|
||||
private readonly ProjectService _projectService;
|
||||
private readonly StackedNotificationService _notificationService;
|
||||
private readonly AppStateService _stateService;
|
||||
|
||||
public readonly ObservableCollection<ProjectMetadataInfo> projects = new();
|
||||
public OpenProjectViewModel ViewModel
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public OpenProjectPage()
|
||||
{
|
||||
_notificationService = App.GetService<StackedNotificationService>();
|
||||
_projectService = App.GetService<ProjectService>();
|
||||
_stateService = App.GetService<AppStateService>();
|
||||
ViewModel = App.GetService<OpenProjectViewModel>();
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void UpdateEmptyPlaceHolderVisibility()
|
||||
{
|
||||
EmptyPlaceHolder.Visibility = projects.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
ViewModel.OnNavigatedTo(e.Parameter);
|
||||
}
|
||||
|
||||
projects.Clear();
|
||||
await foreach (var projectInfo in _projectService.LoadAllProjectAsync())
|
||||
{
|
||||
var metadata = await ProjectService.LoadMetadataAsync(projectInfo.MetadataPath);
|
||||
if (metadata == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
projects.Add(new(projectInfo.MetadataPath, metadata));
|
||||
}
|
||||
|
||||
UpdateEmptyPlaceHolderVisibility();
|
||||
override protected void OnNavigatedFrom(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedFrom(e);
|
||||
ViewModel.OnNavigatedFrom();
|
||||
}
|
||||
|
||||
private void ProjectContainer_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
DragVisual.Visibility = Visibility.Visible;
|
||||
EmptyPlaceHolder.Visibility = Visibility.Collapsed;
|
||||
ViewModel.DragVisibility = Visibility.Visible;
|
||||
ViewModel.EmptyVisibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void ProjectContainer_DragLeave(object sender, DragEventArgs e)
|
||||
{
|
||||
DragVisual.Visibility = Visibility.Collapsed;
|
||||
UpdateEmptyPlaceHolderVisibility();
|
||||
ViewModel.DragVisibility = Visibility.Collapsed;
|
||||
ViewModel.UpdateEmptyPlaceHolderVisibility();
|
||||
}
|
||||
|
||||
private void ProjectContainer_DragOver(object sender, DragEventArgs e)
|
||||
@@ -79,55 +58,14 @@ internal sealed partial class OpenProjectPage : Page
|
||||
|
||||
private async void ProjectContainer_Drop(object sender, DragEventArgs e)
|
||||
{
|
||||
var errorMessage = string.Empty;
|
||||
if (e.DataView.Contains(StandardDataFormats.StorageItems))
|
||||
{
|
||||
var items = await e.DataView.GetStorageItemsAsync();
|
||||
var rootFolder = items.OfType<StorageFolder>().FirstOrDefault();
|
||||
if (rootFolder != null)
|
||||
{
|
||||
var result = await _projectService.AddProjectFromDirectoryAsync(rootFolder.Path);
|
||||
if (result.success)
|
||||
{
|
||||
projects.Add(result.data);
|
||||
DragVisual.Visibility = Visibility.Collapsed;
|
||||
goto CloseDropPanel;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = result.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = "Unsupported data format. Please drop a folder containing a project.";
|
||||
}
|
||||
|
||||
_notificationService.ShowNotification(errorMessage, InfoBarSeverity.Error);
|
||||
|
||||
CloseDropPanel:
|
||||
DragVisual.Visibility = Visibility.Collapsed;
|
||||
UpdateEmptyPlaceHolderVisibility();
|
||||
await ViewModel.ContentDrop(e.DataView);
|
||||
}
|
||||
|
||||
private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
|
||||
{
|
||||
if (e.ClickedItem is not ProjectMetadataInfo project)
|
||||
if (e.ClickedItem is ProjectMetadataInfo project)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
project.Metadata.LastOpened = DateTime.Now;
|
||||
await ProjectService.CreateMetadataFileAsync(project.Path, project.Metadata);
|
||||
|
||||
await _stateService.TransitionToAsync(StateKey.EngineEditor, project.Metadata);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
_notificationService.ShowNotification($"Failed to load project: {exp.Message}", InfoBarSeverity.Error);
|
||||
await ViewModel.LoadProject(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user