forked from Misaki/GhostEngine
- Updated dependencies, including `Misaki.HighPerformance` and `TerraFX.Interop`. - Refactored `Result` struct for better error handling and chaining. - Removed `Ptr<T>` struct as it was no longer necessary. - Enhanced `Win32Utility` with `Attach` and `Dispose` methods. - Improved `ProjectService` and `AppStateMachine` with `Result` integration. - Refactored `IShaderCompiler` to support SPIR-V cross-compilation and pass-level compilation. - Standardized Direct3D12 resource management with `UniquePtr` and added `D3D12Object` base class. - Improved shader reflection validation and pipeline creation in `D3D12PipelineLibrary`. - Updated `SDLCompiler` for better error handling during shader generation. - Enhanced logging, debugging, and code readability across the codebase. - Performed general code cleanup, including unused namespace removal and naming consistency.
91 lines
2.4 KiB
C#
91 lines
2.4 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Ghost.Data.Models;
|
|
using Ghost.Data.Services;
|
|
using Ghost.Editor.Core.AppState;
|
|
using Ghost.Editor.Core.Contracts;
|
|
using Ghost.Editor.Core.Notifications;
|
|
using Ghost.Editor.Utilities;
|
|
using Ghost.Engine.Resources;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace Ghost.Editor.ViewModels.Pages.Landing;
|
|
|
|
internal partial class CreateProjectViewModel(INotificationService 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", MessageType.Error);
|
|
return;
|
|
}
|
|
|
|
var result = await projectService.CreateProjectAsync(ProjectName, ProjectLocation, EngineData.s_engineVersion, SelectedTemplate.Value.directory);
|
|
if (result.IsFailure)
|
|
{
|
|
notificationService.ShowNotification(result.Message, MessageType.Error);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
await stateService.TransitionToAsync(StateKey.EngineEditor, result.Value);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
notificationService.ShowNotification($"Failed to load project: {e.Message}", MessageType.Error);
|
|
}
|
|
}
|
|
} |