Refactor activation handling and introduce entity system
Added new `ActivationHandler` class for folder initialization. Added `ProjectService` class for project-related operations. Added `Ghost.Entities` project with entity management classes. Added `EngineEditorWindow` for enhanced user interface. Changed project files to restructure dependencies and remove unused references. Changed `ProjectRepository` to use asynchronous methods for improved performance. Changed data binding in `CreateProjectPage.xaml` and `OpenProjectPage.xaml` to use new data models. Changed `App.xaml.cs` to utilize the new `ActivationHandler` and include additional services. Removed `IActivationHandler` interface and integrated its functionality into `ActivationHandler`. Removed `EditorActivationHandler` as its functionality was merged into `ActivationHandler`. Updated `AssemblyInfo.cs` to include global using directives for entity types. Updated image assets to reflect visual resource changes.
This commit is contained in:
88
Ghost.Data/Services/ProjectService.cs
Normal file
88
Ghost.Data/Services/ProjectService.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using Ghost.Data.DataContext;
|
||||
using Ghost.Data.Models;
|
||||
using Ghost.Data.Resources;
|
||||
using System.IO.Compression;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Ghost.Data.Services;
|
||||
|
||||
public class ProjectService
|
||||
{
|
||||
private const string _TEMPLATE_CONTENT_FILE = "content.zip";
|
||||
|
||||
private const string _ASSETS_FOLDER = "Assets";
|
||||
|
||||
public async IAsyncEnumerable<(string path, TemplateInfo info)> GetProjectTemplatesAsync()
|
||||
{
|
||||
var templatesFolder = DataPath.ProjectTemplatesFolder;
|
||||
if (!Directory.Exists(templatesFolder))
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
var templates = Directory.GetFiles(DataPath.ProjectTemplatesFolder, "template.json", SearchOption.AllDirectories);
|
||||
foreach (var templatePath in templates)
|
||||
{
|
||||
var fileStream = File.OpenRead(templatePath);
|
||||
var templateInfo = await JsonSerializer.DeserializeAsync<TemplateInfo>(fileStream, JsonContext.Default.TemplateInfo);
|
||||
if (templateInfo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return (templatePath, templateInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private Task SetupAssetsFolder(string projectPath, string templatePath)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var templateContentPath = Path.Combine(templatePath, _TEMPLATE_CONTENT_FILE);
|
||||
var projectAssetsPath = Path.Combine(projectPath, _ASSETS_FOLDER);
|
||||
|
||||
Directory.CreateDirectory(projectAssetsPath);
|
||||
|
||||
if (!File.Exists(templateContentPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ZipFile.ExtractToDirectory(templateContentPath, projectAssetsPath);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<string> CreateProjectAsync(string projectName, string projectDirectory, string templatePath)
|
||||
{
|
||||
var projectPath = Path.Combine(projectDirectory, projectName);
|
||||
if (!Directory.Exists(projectPath))
|
||||
{
|
||||
Directory.CreateDirectory(projectPath);
|
||||
}
|
||||
|
||||
await SetupAssetsFolder(projectPath, templatePath);
|
||||
|
||||
return projectPath;
|
||||
}
|
||||
|
||||
public Task AddProjectAsync(ProjectInfo project)
|
||||
{
|
||||
return ProjectRepository.AddProjectAsync(project);
|
||||
}
|
||||
|
||||
public Task AddProjectAsync(string name, string path, Version version)
|
||||
{
|
||||
return ProjectRepository.AddProjectAsync(new ProjectInfo
|
||||
{
|
||||
Name = name,
|
||||
Path = path,
|
||||
EngineVersion = version,
|
||||
LastOpened = DateTime.Now
|
||||
});
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<ProjectInfo> LoadProjectAsync()
|
||||
{
|
||||
return ProjectRepository.LoadProjectsAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user