forked from Misaki/GhostEngine
Changed the project namespace from `Ghost.Editor` to `Ghost.App` across multiple files. Changed the `InternalsVisibleTo` attribute in `AssemblyInfo.cs` to include `Ghost.App`. Changed the `ProjectRepository` class to add new asynchronous methods for retrieving projects by ID, name, and metadata path. Changed the `ProjectService` class to utilize the new asynchronous project loading methods. Changed the `SceneGraph` classes to improve node management and serialization. Changed the `EntityManager` class to enhance entity management with new component handling methods. Added new test classes, `EntityTest` and `SerializationTest`, to ensure reliability in entity and serialization systems. Added the `Ghost.App` project file to establish a modular project structure. Added the `Ghost.Generator` project for automated component serialization code generation. Updated UI components to reflect the new namespace for proper functionality.
95 lines
2.5 KiB
C#
95 lines
2.5 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Ghost.App.Contracts;
|
|
using Ghost.App.Infrastructures.AppState;
|
|
using Ghost.App.Services;
|
|
using Ghost.App.Utilities;
|
|
using Ghost.Data.Models;
|
|
using Ghost.Data.Services;
|
|
using Ghost.Engine.Resources;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ghost.Editor.ViewModels.Pages.Landing;
|
|
|
|
internal partial class CreateProjectViewModel(StackedNotificationService notificationService, ProjectService projectService, AppStateMachine stateService) : ObservableObject, INavigationAware
|
|
{
|
|
public ObservableCollection<TemplateData> templates = new();
|
|
|
|
[ObservableProperty]
|
|
public partial TemplateData? SelectedTemplate
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public partial string? ProjectName
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public partial string? ProjectLocation
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
public async void OnNavigatedTo(object? parameter)
|
|
{
|
|
templates.Clear();
|
|
await foreach (var (path, info) in ProjectService.GetProjectTemplatesAsync())
|
|
{
|
|
templates.Add(new(path, info));
|
|
}
|
|
|
|
SelectedTemplate = templates.FirstOrDefault();
|
|
}
|
|
|
|
public void OnNavigatedFrom()
|
|
{
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task SelectionProjectLocation()
|
|
{
|
|
var folder = await SystemUtilities.OpenFolderPickerAsync();
|
|
if (folder != null)
|
|
{
|
|
ProjectLocation = folder.Path;
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task CreateProject()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(ProjectName)
|
|
|| !Directory.Exists(ProjectLocation)
|
|
|| !SelectedTemplate.HasValue)
|
|
{
|
|
notificationService.ShowNotification("Incorrect project info", InfoBarSeverity.Error);
|
|
return;
|
|
}
|
|
|
|
var result = await projectService.CreateProjectAsync(ProjectName, ProjectLocation, EngineData.s_engineVersion, SelectedTemplate.Value.directory);
|
|
if (!result.success)
|
|
{
|
|
notificationService.ShowNotification(result.message, InfoBarSeverity.Error);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
await stateService.TransitionToAsync(StateKey.EngineEditor, result.data);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
notificationService.ShowNotification($"Failed to load project: {e.Message}", InfoBarSeverity.Error);
|
|
}
|
|
}
|
|
} |