mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Start of project system
+ added Directory.IsEmpty
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Bon;
|
||||
using GlitchyEngine;
|
||||
|
||||
namespace GlitchyEditor;
|
||||
|
||||
[BonTarget]
|
||||
class Project
|
||||
{
|
||||
[BonInclude]
|
||||
private String _projectName ~ delete _;
|
||||
|
||||
[BonIgnore]
|
||||
private String _workspacePath ~ delete _;
|
||||
|
||||
[BonIgnore]
|
||||
private String _assetsFolder ~ delete _;
|
||||
|
||||
[BonIgnore]
|
||||
private String _scriptFolder ~ delete _;
|
||||
|
||||
public StringView ProjectName => _projectName;
|
||||
public StringView WorkspacePath => _workspacePath;
|
||||
|
||||
public StringView AssetsFolder => _assetsFolder;
|
||||
|
||||
[AllowAppend]
|
||||
private this(StringView workspacePath)
|
||||
{
|
||||
_workspacePath = new String(workspacePath);
|
||||
|
||||
_assetsFolder = new String();
|
||||
PathInProject(_assetsFolder, "Assets");
|
||||
}
|
||||
|
||||
public void PathInProject(String target, StringView relativePath)
|
||||
{
|
||||
Path.Combine(target, WorkspacePath, relativePath);
|
||||
}
|
||||
|
||||
public void GetRelativePath()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static Project CreateNew(StringView projectDirectory, StringView projectName)
|
||||
{
|
||||
Project project = new Project(projectDirectory);
|
||||
project._projectName = new String(projectName);
|
||||
|
||||
String settingsFile = scope .();
|
||||
project.PathInProject(settingsFile, "project.gep");
|
||||
|
||||
Result<void> result = Bon.SerializeIntoFile(project, settingsFile);
|
||||
|
||||
if (result case .Err)
|
||||
Log.EngineLogger.Warning($"Failed to save project file \"{settingsFile}\".");
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
public static Result<Project> Load(StringView projectDirectory)
|
||||
{
|
||||
Project project = new Project(projectDirectory);
|
||||
|
||||
String settingsFile = scope .();
|
||||
project.PathInProject(settingsFile, "project.gep");
|
||||
|
||||
if (File.Exists(settingsFile))
|
||||
{
|
||||
Result<void> result = Bon.DeserializeFromFile(ref project, settingsFile);
|
||||
|
||||
if (result case .Err)
|
||||
Log.EngineLogger.Warning($"Failed to deserialize project file \"{settingsFile}\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.Warning($"Project file \"{settingsFile}\" doesn't exist.");
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user