Options to rebuild scripts at runtime are now present in the editor

This commit is contained in:
Kah Wei 2022-09-27 17:13:32 +08:00
parent 337894ebc2
commit 4effe016e4
3 changed files with 40 additions and 6 deletions

View File

@ -6,6 +6,9 @@
#include "SHEditorMenuBar.h"
#include "Editor/IconsMaterialDesign.h"
#include "Editor/Command/SHCommandManager.h"
#include "Scripting/SHScriptEngine.h"
#include "Editor/SHEditor.hpp"
#include "ECS_Base/Managers/SHSystemManager.h"
//#==============================================================#
//|| Library Includes ||
@ -14,9 +17,6 @@
#include <imgui_internal.h>
#include <rttr/type>
#include "Editor/SHEditor.hpp"
namespace SHADE
{
constexpr ImGuiWindowFlags editorMenuBarFlags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse |
@ -100,6 +100,25 @@ namespace SHADE
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Scripts"))
{
if (ImGui::Selectable("Generate Visual Studio Project"))
{
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
scriptEngine->GenerateScriptsCsProjFile();
}
if (ImGui::Selectable("Build Scripts - Debug"))
{
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
scriptEngine->BuildScriptAssembly(true, true);
}
if (ImGui::Selectable("Build Scripts - Release"))
{
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
scriptEngine->BuildScriptAssembly(false, true);
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}

View File

@ -160,10 +160,16 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/
/* Static Utility Functions */
/*-----------------------------------------------------------------------------------*/
bool SHScriptEngine::BuildScriptAssembly(bool debug) const
bool SHScriptEngine::BuildScriptAssembly(bool debug, bool reload)
{
static const std::string BUILD_LOG_PATH = "../Build.log";
// Unload if we need to reload
if (reload)
{
UnloadScriptAssembly();
}
// Generate csproj file if it doesn't exist
if (!std::filesystem::exists(CSPROJ_PATH))
{
@ -209,6 +215,12 @@ namespace SHADE
// Delete the build log file since we no longer need it
deleteFile(BUILD_LOG_PATH);
// If reloading, we need to load
if (reload)
{
LoadScriptAssembly();
}
return BUILD_SUCCESS;
}

View File

@ -184,13 +184,16 @@ namespace SHADE
/// Whether or not a debug build will be built. Only debug built C# assemblies
/// can be debugged.
/// </param>
/// <param name="reload">
/// Whether or not we are reloading the assembly, if so, unload and then reload it.
/// </param>
/// <returns>Whether or not the build succeeded.</returns>
bool BuildScriptAssembly(bool debug = false) const;
bool BuildScriptAssembly(bool debug = false, bool reload = false);
/// <summary>
/// Generates a .csproj file for editing and compiling the C# scripts.
/// </summary>
/// <param name="path">File path to the generated file.</param>
void GenerateScriptsCsProjFile(const std::filesystem::path& path) const;
void GenerateScriptsCsProjFile(const std::filesystem::path& path = CSPROJ_PATH) const;
private:
/*-----------------------------------------------------------------------------*/