Refactor project structure and enhance functionality
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.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Ghost.Editor")]
|
||||
[assembly: InternalsVisibleTo("Ghost.App")]
|
||||
|
||||
@@ -23,7 +23,7 @@ internal static class ProjectRepository
|
||||
await createCommand.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public static async IAsyncEnumerable<ProjectInfo> LoadProjectsAsync()
|
||||
public static async IAsyncEnumerable<ProjectInfo> GetAllProjectsAsync()
|
||||
{
|
||||
using var connection = new SQLiteConnection(string.Format(Command.CONNECTION_STRING, DataPath.s_applicationDataFolder));
|
||||
connection.Open();
|
||||
@@ -47,6 +47,85 @@ internal static class ProjectRepository
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<ProjectInfo?> GetProjectByIdAsync(int id)
|
||||
{
|
||||
using var connection = new SQLiteConnection(string.Format(Command.CONNECTION_STRING, DataPath.s_applicationDataFolder));
|
||||
connection.Open();
|
||||
|
||||
await EnsureTableCreatedAsync(connection);
|
||||
|
||||
using var command = connection.CreateCommand();
|
||||
command.CommandText = Command.SELECT_PROJECT_STRING + " WHERE ID = @ID;";
|
||||
|
||||
command.Parameters.AddWithValue("@ID", id);
|
||||
|
||||
using var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
if (await reader.ReadAsync())
|
||||
{
|
||||
return new ProjectInfo
|
||||
{
|
||||
ID = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
MetadataPath = reader.GetString(2),
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task<ProjectInfo?> GetProjectByNameAsync(string name)
|
||||
{
|
||||
using var connection = new SQLiteConnection(string.Format(Command.CONNECTION_STRING, DataPath.s_applicationDataFolder));
|
||||
connection.Open();
|
||||
|
||||
await EnsureTableCreatedAsync(connection);
|
||||
|
||||
using var command = connection.CreateCommand();
|
||||
command.CommandText = Command.SELECT_PROJECT_STRING + " WHERE Name = @Name;";
|
||||
|
||||
command.Parameters.AddWithValue("@Name", name);
|
||||
|
||||
using var reader = await command.ExecuteReaderAsync();
|
||||
if (await reader.ReadAsync())
|
||||
{
|
||||
return new ProjectInfo
|
||||
{
|
||||
ID = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
MetadataPath = reader.GetString(2),
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task<ProjectInfo?> GetProjectByMetadataPathAsync(string metadataPath)
|
||||
{
|
||||
using var connection = new SQLiteConnection(string.Format(Command.CONNECTION_STRING, DataPath.s_applicationDataFolder));
|
||||
connection.Open();
|
||||
|
||||
await EnsureTableCreatedAsync(connection);
|
||||
|
||||
using var command = connection.CreateCommand();
|
||||
command.CommandText = Command.SELECT_PROJECT_STRING + " WHERE MetadataPath = @MetadataPath;";
|
||||
|
||||
command.Parameters.AddWithValue("@MetadataPath", metadataPath);
|
||||
|
||||
using var reader = await command.ExecuteReaderAsync();
|
||||
if (await reader.ReadAsync())
|
||||
{
|
||||
return new ProjectInfo
|
||||
{
|
||||
ID = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
MetadataPath = reader.GetString(2),
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task AddProjectAsync(ProjectInfo project)
|
||||
{
|
||||
using var connection = new SQLiteConnection(string.Format(Command.CONNECTION_STRING, DataPath.s_applicationDataFolder));
|
||||
|
||||
@@ -13,6 +13,12 @@ internal partial class ProjectService
|
||||
public const string ASSETS_FOLDER = "Assets";
|
||||
public const string CONFIG_FOLDER = "ProjectConfig";
|
||||
|
||||
public static ProjectMetadataInfo CurrentProject
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public static void EnsureDefaultTemplate()
|
||||
{
|
||||
var templates = Directory.GetFiles(DataPath.s_projectTemplateFolder, "template.json", SearchOption.AllDirectories);
|
||||
@@ -114,12 +120,6 @@ internal partial class ProjectService
|
||||
|
||||
internal partial class ProjectService
|
||||
{
|
||||
public static ProjectMetadataInfo CurrentProject
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Task AddProjectAsync(ProjectInfo project)
|
||||
{
|
||||
return ProjectRepository.AddProjectAsync(project);
|
||||
@@ -147,9 +147,14 @@ internal partial class ProjectService
|
||||
return ProjectRepository.UpdateProjectAsync(project);
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<ProjectInfo> LoadAllProjectAsync()
|
||||
public async Task<bool> HasProjectAsync(string path)
|
||||
{
|
||||
return ProjectRepository.LoadProjectsAsync();
|
||||
return await ProjectRepository.GetProjectByMetadataPathAsync(path) != null;
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<ProjectInfo> GetAllProjectAsync()
|
||||
{
|
||||
return ProjectRepository.GetAllProjectsAsync();
|
||||
}
|
||||
|
||||
public async Task<Result<ProjectMetadataInfo>> CreateProjectAsync(string projectName, string projectDirectory, Version engineVersion, string templatePath)
|
||||
@@ -187,11 +192,18 @@ internal partial class ProjectService
|
||||
public async Task<Result<ProjectMetadataInfo>> AddProjectFromDirectoryAsync(string projectDirectory)
|
||||
{
|
||||
var result = await ValidateProjectDirectoryAsync(projectDirectory);
|
||||
if (result.success)
|
||||
if (!result.success)
|
||||
{
|
||||
await AddProjectAsync(result.data.Metadata.Name, result.data.Path);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (await HasProjectAsync(result.data.Path))
|
||||
{
|
||||
return Result<ProjectMetadataInfo>.Error("Project already exists.");
|
||||
}
|
||||
|
||||
await AddProjectAsync(result.data.Metadata.Name, result.data.Path);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user