Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 63 additions & 49 deletions Prowl.Editor/Build/ProjectBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,87 @@
// This file is part of the Prowl Game Engine
// Licensed under the MIT License. See the LICENSE file in the project root for details.

using Prowl.Runtime;
using System.Reflection;

namespace Prowl.Editor.Build;
using Prowl.Editor.Assets;
using Prowl.Editor.Utilities;
using Prowl.Runtime;

public abstract class ProjectBuilder
namespace Prowl.Editor.Build
{
public void StartBuild(AssetRef<Scene>[] scenes, DirectoryInfo output)
public abstract class ProjectBuilder
{
if (!Project.HasProject)
public void StartBuild(AssetRef<Scene>[] scenes, DirectoryInfo output)
{
Debug.LogError($"No Project Loaded...");
return;
}
if (!Project.HasProject)
{
Debug.LogError($"No Project Loaded...");
return;
}

if (!AreScenesValid(scenes))
return;
AssetDatabase.Update();
if (!AreScenesValid(scenes))
return;

Debug.Log($"Starting Project Build...");
BoundedLog($"Creating Directories...");
Debug.Log($"Starting Project Build...");
Project.BoundedLog($"Creating Directories...");

if (output.Exists)
{
BoundedLog($"Deleting existing build directory...");
output.Delete(true);
}
if (output.Exists)
{
Project.BoundedLog($"Deleting existing build directory...");
output.Delete(true);
}

try
{
Build(scenes, output);
}
catch (Exception e)
{
Debug.LogError($"Failed to build project: {e.Message}");
try
{
Build(scenes, output);
}
catch (Exception e)
{
Debug.LogError($"Failed to build project: {e.Message}");
}
}
}

protected abstract void Build(AssetRef<Scene>[] scenes, DirectoryInfo output);
protected abstract void Build(AssetRef<Scene>[] scenes, DirectoryInfo output);

private bool AreScenesValid(AssetRef<Scene>[] scenes)
{
if (scenes == null)
private bool AreScenesValid(AssetRef<Scene>[] scenes)
{
Debug.LogError($"Atleast 1 Scene must be assigned in the Build Project Settings Window");
return false;
}

if (scenes.Length <= 0)
{
Debug.LogError($"Atleast 1 Scene must be assigned in the Build Project Settings Window");
return false;
}
if (scenes == null)
{
Debug.LogError($"At least 1 Scene must be assigned in the Build Project Settings Window");
return false;
}

// Make sure all scenes are valid
foreach (var scene in scenes)
if (!scene.IsAvailable)
if (scenes.Length <= 0)
{
Debug.LogError($"Scene {scene.Name} is not available, please assign a valid available scene");
Debug.LogError($"At least 1 Scene must be assigned in the Build Project Settings Window");
return false;
}

return true;
}
// Make sure all scenes are valid
foreach (var scene in scenes)
if (!scene.IsAvailable)
{
Debug.LogError($"Scene {scene.Name} is not available, please assign a valid available scene");
return false;
}

protected void BoundedLog(string message)
{
Debug.Log("**********************************************************************************************************************");
Debug.Log(message);
Debug.Log("**********************************************************************************************************************");
return true;
}

public static IEnumerable<ProjectBuilder> GetAll()
{
foreach (Assembly editorAssembly in AssemblyManager.ExternalAssemblies.Append(typeof(Program).Assembly))
{
List<Type> derivedTypes = EditorUtils.GetDerivedTypes(typeof(ProjectBuilder), editorAssembly);
foreach (Type type in derivedTypes)
{
if (type.IsAbstract)
continue;

yield return (ProjectBuilder)Activator.CreateInstance(type);
}
}
}
}
}
19 changes: 19 additions & 0 deletions Prowl.Editor/Editor/CLI/CliBuildOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is part of the Prowl Game Engine
// Licensed under the MIT License. See the LICENSE file in the project root for details.

using CommandLine;

namespace Prowl.Editor.Editor.CLI;

/// <summary>
/// Command line options for the `build` command.
/// </summary>
[Verb("build", false, HelpText = "build a given project")]
internal class CliBuildOptions : CliOptionsBase
{
/// <summary>
/// The path of the output files.
/// </summary>
[Option('o', "output", Required = false, HelpText = "Output directory path")]
public required DirectoryInfo Output { get; set; }
}
7 changes: 1 addition & 6 deletions Prowl.Editor/Editor/CLI/CliCreateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ namespace Prowl.Editor.Editor.CLI;
/// Command line options for the `create` command.
/// </summary>
[Verb("create", false, HelpText = "create a project")]
internal class CliCreateOptions
internal class CliCreateOptions : CliOptionsBase
{
/// <summary>
/// The path of the project to be created.
/// </summary>
[Option('p', "project", Required = false, HelpText = "Project path", Default = "./")]
public required DirectoryInfo ProjectPath { get; set; }
}
9 changes: 1 addition & 8 deletions Prowl.Editor/Editor/CLI/CliOpenOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,4 @@ namespace Prowl.Editor.Editor.CLI;
/// Command line options for the `open` command.
/// </summary>
[Verb("open", true, HelpText = "Open a given project")]
internal class CliOpenOptions
{
/// <summary>
/// The path of the project to be open.
/// </summary>
[Option('p', "project", Required = false, HelpText = "Project path")]
public required DirectoryInfo ProjectPath { get; set; }
}
internal class CliOpenOptions : CliOptionsBase { }
18 changes: 18 additions & 0 deletions Prowl.Editor/Editor/CLI/CliOptionsBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file is part of the Prowl Game Engine
// Licensed under the MIT License. See the LICENSE file in the project root for details.

using CommandLine;

namespace Prowl.Editor.Editor.CLI;

/// <summary>
/// Repetitive options.
/// </summary>
internal class CliOptionsBase
{
/// <summary>
/// The path of the project to perform the command (open, build, create, etc).
/// </summary>
[Option('p', "project", Required = false, HelpText = "Project path")]
public required DirectoryInfo? ProjectPath { get; init; }
}
3 changes: 3 additions & 0 deletions Prowl.Editor/Editor/CLI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Command Line (CLI) options

These classes map the optional commands that Prowl accept from the Console/Terminal/Command line.
36 changes: 18 additions & 18 deletions Prowl.Editor/Editor/ConsoleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ private static bool FastCompareMessage(LogMessage log, string message, DebugStac
if ((log.trace == null) != (stackTrace == null))
return false;

if (log.trace != null && log.trace.stackFrames.Length != stackTrace.stackFrames.Length)
if (log.trace != null && log.trace.StackFrames.Length != stackTrace.StackFrames.Length)
return false;

// Slower checks later
// Check stack frame 0 earlier since it potentially avoids comparing big messages.
if (stackTrace != null && stackTrace.stackFrames.Length > 0)
if (stackTrace != null && stackTrace.StackFrames.Length > 0)
{
DebugStackFrame frame = log.trace.stackFrames[0];
DebugStackFrame frame2 = stackTrace.stackFrames[0];
DebugStackFrame frame = log.trace.StackFrames[0];
DebugStackFrame frame2 = stackTrace.StackFrames[0];

if (frame.line != frame2.line && frame.column != frame2.column)
if (frame.Line != frame2.Line && frame.Column != frame2.Column)
return false;

if (frame.fileName != frame2.fileName)
if (frame.FileName != frame2.FileName)
return false;
}

Expand All @@ -76,15 +76,15 @@ private static bool FastCompareMessage(LogMessage log, string message, DebugStac
// Potentially slowest check last
if (log.trace != null)
{
for (int i = 1; i < log.trace.stackFrames.Length; i++)
for (int i = 1; i < log.trace.StackFrames.Length; i++)
{
DebugStackFrame frame = log.trace.stackFrames[i];
DebugStackFrame frame2 = stackTrace.stackFrames[i];
DebugStackFrame frame = log.trace.StackFrames[i];
DebugStackFrame frame2 = stackTrace.StackFrames[i];

if (frame.line != frame2.line && frame.column != frame2.column)
if (frame.Line != frame2.Line && frame.Column != frame2.Column)
return false;

if (frame.fileName != frame2.fileName)
if (frame.FileName != frame2.FileName)
return false;
}
}
Expand Down Expand Up @@ -242,7 +242,7 @@ private void DrawMessage(LogMessage message, int index)

textRect.x += 7.5;

bool hasTrace = message.trace != null && message.trace.stackFrames.Length > 0;
bool hasTrace = message.trace != null && message.trace.StackFrames.Length > 0;

Vector2 textPos = textRect.Position;
textPos.y += (rect.height / 2) - (7.5 + (hasTrace ? 5 : 0));
Expand Down Expand Up @@ -271,7 +271,7 @@ private void DrawMessage(LogMessage message, int index)
{
textPos.y += 15;

DebugStackFrame frame = message.trace!.stackFrames[0];
DebugStackFrame frame = message.trace!.StackFrames[0];

string frameText = frame.ToString();

Expand Down Expand Up @@ -311,11 +311,11 @@ private bool DrawExpandedMessage(LogMessage message)
gui.Draw2D.DrawText(Font.DefaultFont, selMsg, 20, textPos, color);
}

if (message.trace != null && message.trace.stackFrames.Length != 0)
if (message.trace != null && message.trace.StackFrames.Length != 0)
{
for (int i = 0; i < message.trace.stackFrames.Length; i++)
for (int i = 0; i < message.trace.StackFrames.Length; i++)
{
DebugStackFrame frame = message.trace.stackFrames[i];
DebugStackFrame frame = message.trace.StackFrames[i];
string frameText = frame.ToString();
Vector2 frameSize = Font.DefaultFont.CalcTextSize(frameText, font_size: 21, 0);

Expand Down Expand Up @@ -364,10 +364,10 @@ private bool DrawExpandedMessage(LogMessage message)

private static void OpenStackFrame(DebugStackFrame frame)
{
if (frame.fileName == null)
if (frame.FileName == null)
return;

AssetDatabase.OpenPath(new FileInfo(frame.fileName), frame.line, frame.column);
AssetDatabase.OpenPath(new FileInfo(frame.FileName), frame.Line, frame.Column);
}


Expand Down
Loading