Files
GhostEngine/Ghost.Editor/ViewModels/Pages/Landing/OpenProjectViewModel.cs
Misaki bab3be2508 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.
2025-06-05 21:45:50 +09:00

109 lines
3.2 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using Ghost.Data.Models;
using Ghost.Data.Services;
using Ghost.Editor.Contracts;
using Ghost.Editor.Infrastructures.AppState;
using Ghost.Editor.Services;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
namespace Ghost.Editor.ViewModels.Pages.Landing;
internal partial class OpenProjectViewModel(ProjectService projectService, StackedNotificationService _notificationService, AppStateMachine _stateService) : ObservableObject, INavigationAware
{
public readonly ObservableCollection<ProjectMetadataInfo> projects = new();
[ObservableProperty]
public partial Visibility EmptyVisibility
{
get;
set;
}
[ObservableProperty]
public partial Visibility DragVisibility
{
get;
set;
}
public void UpdateEmptyPlaceHolderVisibility()
{
EmptyVisibility = projects.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
}
public async void OnNavigatedTo(object? 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();
}
public void OnNavigatedFrom()
{
}
public async Task ContentDrop(DataPackageView dataView)
{
var errorMessage = string.Empty;
if (dataView.Contains(StandardDataFormats.StorageItems))
{
var items = await 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);
goto CloseDropPanel;
}
else
{
errorMessage = result.message;
}
}
}
else
{
errorMessage = "Unsupported data format. Please drop a folder containing a project.";
}
_notificationService.ShowNotification(errorMessage, InfoBarSeverity.Error);
CloseDropPanel:
DragVisibility = Visibility.Collapsed;
UpdateEmptyPlaceHolderVisibility();
}
public async Task LoadProject(ProjectMetadataInfo project)
{
try
{
project.Metadata.LastOpened = DateTime.Now;
await ProjectService.CreateMetadataFileAsync(project.Path, project.Metadata);
await _stateService.TransitionToAsync(StateKey.EngineEditor, project);
}
catch (Exception e)
{
_notificationService.ShowNotification($"Failed to load project: {e.Message}", InfoBarSeverity.Error);
}
}
}