Nerfed/Nerfed.Editor/Project/Project.cs

122 lines
3.1 KiB
C#
Raw Normal View History

2024-07-19 15:24:50 +02:00
using Nerfed.Runtime;
namespace Nerfed.Editor.Project;
2024-07-21 14:03:40 +02:00
internal static class EditorProject
2024-07-19 15:24:50 +02:00
{
2024-07-21 14:03:40 +02:00
internal static Compiler.Project Project { get; private set; }
internal static string ProjectFilePath { get; private set; }
internal static string ProjectSolutionFilePath { get; private set; }
internal static string ProjectPath { get; private set; }
internal static string ProjectContentPath { get; private set; }
internal static string ProjectTempPath { get; private set; }
internal static bool Create(string projectFilePath, string projectName)
2024-07-19 15:24:50 +02:00
{
2024-07-21 14:03:40 +02:00
Close();
2024-07-19 15:24:50 +02:00
2024-07-21 14:03:40 +02:00
if (!Compiler.Project.Create(projectFilePath, projectName, out Compiler.Project project))
2024-07-19 15:24:50 +02:00
{
return false;
}
Open(projectFilePath);
Log.Info($"Succesfully created project.");
return true;
}
internal static bool Open(string path)
{
2024-07-21 14:03:40 +02:00
Close();
2024-07-19 15:24:50 +02:00
2024-07-21 14:03:40 +02:00
if(!Compiler.Project.Open(path, out Compiler.Project project))
2024-07-19 15:24:50 +02:00
{
return false;
}
2024-07-21 14:03:40 +02:00
Project = project;
ProjectFilePath = path;
ProjectPath = Path.GetDirectoryName(path);
SetupDefaultFolders();
Compile();
Log.Info($"Opened project: {project.Name}");
2024-07-19 15:24:50 +02:00
return true;
}
2024-07-21 14:03:40 +02:00
internal static void Close()
2024-07-19 15:24:50 +02:00
{
2024-07-21 14:03:40 +02:00
Project = null;
ProjectFilePath = string.Empty;
ProjectSolutionFilePath = string.Empty;
ProjectPath = string.Empty;
ProjectContentPath = string.Empty;
ProjectTempPath = string.Empty;
2024-07-19 15:24:50 +02:00
}
2024-07-21 14:03:40 +02:00
internal static bool Save()
2024-07-19 15:24:50 +02:00
{
2024-07-21 14:03:40 +02:00
if(Project == null)
{
return false;
}
2024-07-20 00:46:08 +02:00
2024-07-21 14:03:40 +02:00
return Compiler.Project.Save(Project, ProjectFilePath);
2024-07-19 15:24:50 +02:00
}
2024-07-21 14:03:40 +02:00
internal static void Compile()
2024-07-20 00:46:08 +02:00
{
2024-07-21 14:03:40 +02:00
if(Project == null)
{
return;
}
Nerfed.Compiler.Compiler.Compile(ProjectFilePath, "Debug");
2024-07-20 00:46:08 +02:00
}
2024-07-21 14:03:40 +02:00
internal static void GenerateSolution()
2024-07-19 15:24:50 +02:00
{
2024-07-21 14:03:40 +02:00
if(Project == null)
{
return;
}
Nerfed.Compiler.Compiler.GenerateSolution(ProjectPath, Project, out string solutionFilePath);
ProjectSolutionFilePath = solutionFilePath;
2024-07-19 15:24:50 +02:00
}
2024-07-21 14:03:40 +02:00
private static void SetupDefaultFolders()
2024-07-19 15:24:50 +02:00
{
2024-07-21 14:03:40 +02:00
if (Project == null || ProjectPath == null)
{
return;
}
2024-07-19 15:24:50 +02:00
2024-07-21 14:03:40 +02:00
string contentPath = Path.Combine(ProjectPath, "Content");
2024-07-19 15:24:50 +02:00
if (!Directory.Exists(contentPath))
{
Directory.CreateDirectory(contentPath);
}
2024-07-21 14:03:40 +02:00
ProjectContentPath = contentPath;
string scriptsPath = Path.Combine(ProjectContentPath, "Scripts");
2024-07-20 00:46:08 +02:00
if (!Directory.Exists(scriptsPath))
{
Directory.CreateDirectory(scriptsPath);
}
string scriptsRuntimePath = Path.Combine(scriptsPath, "Runtime");
if (!Directory.Exists(scriptsRuntimePath))
{
Directory.CreateDirectory(scriptsRuntimePath);
}
2024-07-19 15:24:50 +02:00
2024-07-21 14:03:40 +02:00
string tempPath = Path.Combine(ProjectPath, "Temp");
2024-07-19 15:24:50 +02:00
if (!Directory.Exists(tempPath))
{
Directory.CreateDirectory(tempPath);
}
2024-07-21 14:03:40 +02:00
ProjectTempPath = tempPath;
2024-07-19 15:24:50 +02:00
}
}