Adding notes in commonly edited scripts to clarify where functions with // notes to know what the script does in better detail.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "EditorUI.h"
|
||||
|
||||
// FileBrowser implementation
|
||||
#pragma region File Browser
|
||||
FileBrowser::FileBrowser() {
|
||||
currentPath = fs::current_path();
|
||||
projectRoot = currentPath;
|
||||
@@ -183,7 +183,9 @@ bool FileBrowser::matchesFilter(const fs::directory_entry& entry) const {
|
||||
|
||||
return filenameLower.find(filterLower) != std::string::npos;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region ImGui Theme
|
||||
void applyModernTheme() {
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec4* colors = style.Colors;
|
||||
@@ -271,7 +273,10 @@ void applyModernTheme() {
|
||||
style.PopupBorderSize = 1.0f;
|
||||
style.TabBorderSize = 1.0f;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Dockspace
|
||||
// Call once per frame before rendering editor panels.
|
||||
void setupDockspace(const std::function<void()>& menuBarContent) {
|
||||
static bool dockspaceOpen = true;
|
||||
static ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags_None;
|
||||
@@ -304,3 +309,4 @@ void setupDockspace(const std::function<void()>& menuBarContent) {
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <functional>
|
||||
#include "Common.h"
|
||||
|
||||
#pragma region File Browser Enums
|
||||
|
||||
enum class FileBrowserViewMode {
|
||||
List,
|
||||
Grid
|
||||
@@ -20,6 +22,9 @@ enum class FileCategory {
|
||||
Text,
|
||||
Unknown
|
||||
};
|
||||
#pragma endregion
|
||||
|
||||
#pragma region File Browser
|
||||
|
||||
class FileBrowser {
|
||||
public:
|
||||
@@ -40,6 +45,7 @@ public:
|
||||
|
||||
FileBrowser();
|
||||
|
||||
// Call refresh after mutating currentPath/searchFilter/showHiddenFiles.
|
||||
void refresh();
|
||||
void navigateUp();
|
||||
void navigateTo(const fs::path& path);
|
||||
@@ -57,9 +63,13 @@ public:
|
||||
// Legacy compatibility
|
||||
bool isOBJFile(const fs::directory_entry& entry) const;
|
||||
};
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Editor UI Helpers
|
||||
|
||||
// Apply the modern dark theme to ImGui
|
||||
void applyModernTheme();
|
||||
|
||||
// Setup ImGui dockspace for the editor
|
||||
void setupDockspace(const std::function<void()>& menuBarContent = nullptr);
|
||||
#pragma endregion
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#pragma region Environment Window
|
||||
void Engine::renderEnvironmentWindow() {
|
||||
if (!showEnvironmentWindow) return;
|
||||
ImGui::Begin("Environment", &showEnvironmentWindow);
|
||||
@@ -74,7 +75,9 @@ void Engine::renderEnvironmentWindow() {
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Camera Window
|
||||
void Engine::renderCameraWindow() {
|
||||
if (!showCameraWindow) return;
|
||||
ImGui::Begin("Camera", &showCameraWindow);
|
||||
@@ -96,3 +99,4 @@ void Engine::renderCameraWindow() {
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
|
||||
#pragma region File Icons
|
||||
namespace FileIcons {
|
||||
namespace {
|
||||
ImU32 BlendColor(ImU32 a, ImU32 b, float t) {
|
||||
@@ -401,7 +402,9 @@ namespace FileIcons {
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region File Actions
|
||||
namespace {
|
||||
enum class CreateKind {
|
||||
Folder,
|
||||
@@ -475,8 +478,10 @@ namespace {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region File Browser Panel
|
||||
// Uses FileBrowser state for navigation, selection, and drag-drop.
|
||||
void Engine::renderFileBrowserPanel() {
|
||||
ImGui::Begin("Project", &showFileBrowser);
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
@@ -1242,3 +1247,4 @@ void Engine::renderFileBrowserPanel() {
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#pragma region ImGui Helpers
|
||||
namespace ImGui {
|
||||
|
||||
// Animated progress bar that keeps circles moving while work happens in the background.
|
||||
@@ -103,7 +104,9 @@ bool Spinner(const char* label, float radius, int thickness, const ImU32& color)
|
||||
}
|
||||
|
||||
} // namespace ImGui
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Package Task State
|
||||
namespace {
|
||||
struct PackageTaskResult {
|
||||
bool success = false;
|
||||
@@ -117,8 +120,9 @@ struct PackageTaskState {
|
||||
std::future<PackageTaskResult> future;
|
||||
};
|
||||
} // namespace
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Launcher
|
||||
void Engine::renderLauncher() {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImVec2 displaySize = io.DisplaySize;
|
||||
@@ -364,7 +368,9 @@ void Engine::renderLauncher() {
|
||||
if (projectManager.showOpenProjectDialog)
|
||||
renderOpenProjectDialog();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region New Project Dialog
|
||||
void Engine::renderNewProjectDialog() {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImVec2 center = ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
|
||||
@@ -441,7 +447,9 @@ void Engine::renderNewProjectDialog() {
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Open Project Dialog
|
||||
void Engine::renderOpenProjectDialog() {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImVec2 center = ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
|
||||
@@ -497,7 +505,9 @@ void Engine::renderOpenProjectDialog() {
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Project Browser Panel
|
||||
void Engine::renderProjectBrowserPanel() {
|
||||
ImVec4 headerCol = ImVec4(0.20f, 0.27f, 0.36f, 1.0f);
|
||||
ImVec4 headerColActive = ImVec4(0.24f, 0.34f, 0.46f, 1.0f);
|
||||
@@ -793,3 +803,4 @@ void Engine::renderProjectBrowserPanel() {
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor(3);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#pragma region Hierarchy Helpers
|
||||
namespace {
|
||||
ImU32 GetHierarchyTypeColor(ObjectType type) {
|
||||
switch (type) {
|
||||
@@ -94,7 +95,9 @@ namespace {
|
||||
drawList->AddLine(ImVec2(connectorX, rowMid), ImVec2(itemMin.x + 6.0f, rowMid), lineColor, 1.0f);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Hierarchy Panel
|
||||
void Engine::renderHierarchyPanel() {
|
||||
ImGui::Begin("Hierarchy", &showHierarchy);
|
||||
|
||||
@@ -400,7 +403,9 @@ void Engine::renderObjectNode(SceneObject& obj, const std::string& filter,
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Inspector Panel
|
||||
void Engine::renderInspectorPanel() {
|
||||
ImGui::Begin("Inspector", &showInspector);
|
||||
|
||||
@@ -2124,6 +2129,9 @@ void Engine::renderInspectorPanel() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Console Panel
|
||||
void Engine::renderConsolePanel() {
|
||||
ImGui::Begin("Console", &showConsole);
|
||||
|
||||
@@ -2160,6 +2168,9 @@ void Engine::renderConsolePanel() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Mesh Builder Panel
|
||||
void Engine::renderMeshBuilderPanel() {
|
||||
ImGui::Begin("Mesh Builder", &showMeshBuilder);
|
||||
|
||||
@@ -2301,6 +2312,9 @@ void Engine::renderMeshBuilderPanel() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Dialogs
|
||||
void Engine::renderDialogs() {
|
||||
if (showNewSceneDialog) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#pragma region Gizmo Toolbar
|
||||
namespace GizmoToolbar {
|
||||
enum class Icon {
|
||||
Translate,
|
||||
@@ -249,8 +250,10 @@ namespace GizmoToolbar {
|
||||
return pressed;
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Game Viewport Window
|
||||
void Engine::renderGameViewportWindow() {
|
||||
gameViewportFocused = false;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(6.0f, 6.0f));
|
||||
@@ -350,6 +353,9 @@ void Engine::renderGameViewportWindow() {
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Play Controls Bar
|
||||
void Engine::renderPlayControlsBar() {
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec2 buttonPadding(10.0f, 4.0f);
|
||||
@@ -428,6 +434,9 @@ void Engine::renderPlayControlsBar() {
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Main Menu Bar
|
||||
void Engine::renderMainMenuBar() {
|
||||
refreshScriptEditorWindows();
|
||||
|
||||
@@ -572,6 +581,10 @@ void Engine::renderMainMenuBar() {
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Scene Viewport
|
||||
// Final scene output for the editor viewport.
|
||||
void Engine::renderViewport() {
|
||||
ImGuiWindowFlags viewportFlags = ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoScrollbar;
|
||||
|
||||
@@ -1817,3 +1830,4 @@ void Engine::renderViewport() {
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
||||
#pragma region Material File IO Helpers
|
||||
namespace {
|
||||
struct MaterialFileData {
|
||||
MaterialProperties props;
|
||||
@@ -78,7 +79,9 @@ bool writeMaterialFile(const MaterialFileData& data, const std::string& path) {
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Window + Selection Utilities
|
||||
void window_size_callback(GLFWwindow* window, int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
@@ -141,7 +144,9 @@ Camera Engine::makeCameraFromObject(const SceneObject& obj) const {
|
||||
}
|
||||
return cam;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Transform Helpers
|
||||
namespace {
|
||||
// Equivalent to glm::extractEulerAngleXYZ without depending on the experimental header.
|
||||
glm::vec3 ExtractEulerXYZ(const glm::mat3& m) {
|
||||
@@ -195,7 +200,9 @@ glm::mat4 Engine::ComposeTransform(const glm::vec3& position, const glm::quat& r
|
||||
glm::mat4 Engine::ComposeTransform(const glm::vec3& position, const glm::vec3& rotationDeg, const glm::vec3& scale) {
|
||||
return ComposeTransform(position, QuatFromEulerXYZ(rotationDeg), scale);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Undo / Redo
|
||||
void Engine::recordState(const char* /*reason*/) {
|
||||
SceneSnapshot snap;
|
||||
snap.objects = sceneObjects;
|
||||
@@ -246,7 +253,9 @@ void Engine::redo() {
|
||||
nextObjectId = snap.nextId;
|
||||
projectManager.currentProject.hasUnsavedChanges = true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Engine Lifecycle
|
||||
bool Engine::init() {
|
||||
std::cerr << "[DEBUG] Creating window..." << std::endl;
|
||||
editorWindow = window.makeWindow();
|
||||
@@ -481,7 +490,9 @@ void Engine::shutdown() {
|
||||
ImGui::DestroyContext();
|
||||
glfwTerminate();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Asset Import
|
||||
void Engine::importOBJToScene(const std::string& filepath, const std::string& objectName) {
|
||||
recordState("importOBJ");
|
||||
std::string errorMsg;
|
||||
@@ -564,7 +575,9 @@ void Engine::convertModelToRawMesh(const std::string& filepath) {
|
||||
addConsoleMessage("Raw mesh export failed: " + error, ConsoleMessageType::Error);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Mesh Editing
|
||||
bool Engine::ensureMeshEditTarget(SceneObject* obj) {
|
||||
if (!obj) return false;
|
||||
fs::path ext = fs::path(obj->meshPath).extension();
|
||||
@@ -604,7 +617,9 @@ bool Engine::syncMeshEditToGPU(SceneObject* obj) {
|
||||
projectManager.currentProject.hasUnsavedChanges = true;
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Material IO
|
||||
void Engine::loadMaterialFromFile(SceneObject& obj) {
|
||||
if (obj.materialPath.empty()) return;
|
||||
try {
|
||||
@@ -688,7 +703,9 @@ void Engine::saveMaterialToFile(const SceneObject& obj) {
|
||||
addConsoleMessage("Failed to save material: " + obj.materialPath, ConsoleMessageType::Error);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Editor Shortcuts
|
||||
void Engine::handleKeyboardShortcuts() {
|
||||
static bool f11Pressed = false;
|
||||
if (glfwGetKey(editorWindow, GLFW_KEY_F11) == GLFW_PRESS && !f11Pressed) {
|
||||
@@ -792,7 +809,9 @@ void Engine::handleKeyboardShortcuts() {
|
||||
gameViewCursorLocked = false;
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Runtime Updates
|
||||
void Engine::updateScripts(float delta) {
|
||||
if (sceneObjects.empty()) return;
|
||||
|
||||
@@ -923,7 +942,9 @@ void Engine::updatePlayerController(float delta) {
|
||||
}
|
||||
syncLocalTransform(*player);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Transform Hierarchy
|
||||
void Engine::updateLocalFromWorld(SceneObject& obj, const glm::vec3& parentPos, const glm::quat& parentRot, const glm::vec3& parentScale) {
|
||||
auto safeDiv = [](float v, float d) { return (std::abs(d) > 1e-6f) ? (v / d) : 0.0f; };
|
||||
auto unwrapNear = [](float angle, float reference) {
|
||||
@@ -1078,6 +1099,9 @@ void Engine::updateHierarchyWorldTransforms() {
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Project Lifecycle
|
||||
void Engine::OpenProjectPath(const std::string& path) {
|
||||
try {
|
||||
if (projectManager.loadProject(path)) {
|
||||
@@ -1171,7 +1195,9 @@ void Engine::createNewProject(const char* name, const char* location) {
|
||||
projectManager.errorMessage = "Failed to create project directory";
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Scene Management
|
||||
void Engine::loadRecentScenes() {
|
||||
sceneObjects.clear();
|
||||
clearSelection();
|
||||
@@ -1269,7 +1295,9 @@ void Engine::createNewScene(const std::string& sceneName) {
|
||||
|
||||
addConsoleMessage("Created new scene: " + sceneName, ConsoleMessageType::Success);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Scene Objects
|
||||
void Engine::addObject(ObjectType type, const std::string& baseName) {
|
||||
recordState("addObject");
|
||||
int id = nextObjectId++;
|
||||
@@ -1419,7 +1447,9 @@ void Engine::setParent(int childId, int parentId) {
|
||||
projectManager.currentProject.hasUnsavedChanges = true;
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Console Logging
|
||||
void Engine::addConsoleMessage(const std::string& message, ConsoleMessageType type) {
|
||||
std::string prefix;
|
||||
switch (type) {
|
||||
@@ -1447,7 +1477,9 @@ void Engine::logToConsole(const std::string& message) {
|
||||
void Engine::addConsoleMessageFromScript(const std::string& message, ConsoleMessageType type) {
|
||||
addConsoleMessage(message, type);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Object Lookup
|
||||
SceneObject* Engine::findObjectByName(const std::string& name) {
|
||||
auto it = std::find_if(sceneObjects.begin(), sceneObjects.end(), [&](const SceneObject& o) {
|
||||
return o.name == name;
|
||||
@@ -1463,7 +1495,9 @@ SceneObject* Engine::findObjectById(int id) {
|
||||
if (it != sceneObjects.end()) return &(*it);
|
||||
return nullptr;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Script Hooks
|
||||
fs::path Engine::resolveScriptBinary(const fs::path& sourcePath) {
|
||||
ScriptBuildConfig config;
|
||||
std::string error;
|
||||
@@ -1579,7 +1613,9 @@ bool Engine::setAudioClipFromScript(int id, const std::string& path) {
|
||||
audio.setObjectLoop(*obj, obj->audioSource.loop);
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Script Compilation + Editor Tabs
|
||||
void Engine::compileScriptFile(const fs::path& scriptPath) {
|
||||
if (!projectManager.currentProject.isLoaded) {
|
||||
addConsoleMessage("No project is loaded", ConsoleMessageType::Warning);
|
||||
@@ -1747,7 +1783,9 @@ void Engine::renderScriptEditorWindows() {
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region ImGui Setup
|
||||
void Engine::setupImGui() {
|
||||
std::cerr << "[DEBUG] setupImGui: getting primary monitor..." << std::endl;
|
||||
float mainScale = 1.0f;
|
||||
@@ -1793,3 +1831,4 @@ void Engine::setupImGui() {
|
||||
}
|
||||
std::cerr << "[DEBUG] setupImGui: complete!" << std::endl;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "MeshBuilder.h"
|
||||
|
||||
#pragma region State Reset
|
||||
void MeshBuilder::clear() {
|
||||
mesh = RawMeshAsset();
|
||||
hasMesh = false;
|
||||
@@ -7,7 +8,9 @@ void MeshBuilder::clear() {
|
||||
selectedVertex = -1;
|
||||
loadedPath.clear();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region File IO
|
||||
bool MeshBuilder::load(const std::string& path, std::string& error) {
|
||||
auto& loader = getModelLoader();
|
||||
RawMeshAsset loaded;
|
||||
@@ -35,7 +38,9 @@ bool MeshBuilder::save(const std::string& path, std::string& error) {
|
||||
dirty = false;
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Geometry Editing
|
||||
void MeshBuilder::recomputeNormals() {
|
||||
if (mesh.positions.empty()) return;
|
||||
mesh.normals.assign(mesh.positions.size(), glm::vec3(0.0f));
|
||||
@@ -103,3 +108,4 @@ bool MeshBuilder::addFace(const std::vector<uint32_t>& indices, std::string& err
|
||||
dirty = true;
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Common.h"
|
||||
#include "ModelLoader.h"
|
||||
|
||||
#pragma region Mesh Builder State
|
||||
// Lightweight mesh editing state used by the MeshBuilder panel.
|
||||
class MeshBuilder {
|
||||
public:
|
||||
@@ -11,7 +12,9 @@ public:
|
||||
std::string loadedPath;
|
||||
bool dirty = false;
|
||||
int selectedVertex = -1;
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Mesh Builder API
|
||||
bool load(const std::string& path, std::string& error);
|
||||
bool save(const std::string& path, std::string& error);
|
||||
void clear();
|
||||
@@ -20,3 +23,4 @@ public:
|
||||
// Add a new face defined by vertex indices (3 = triangle, 4 = quad fan).
|
||||
bool addFace(const std::vector<uint32_t>& indices, std::string& error);
|
||||
};
|
||||
#pragma endregion
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
|
||||
#pragma region Local Path Helpers
|
||||
namespace {
|
||||
fs::path normalizePath(const fs::path& p) {
|
||||
std::error_code ec;
|
||||
@@ -59,7 +60,9 @@ fs::path guessIncludeDir(const fs::path& repoRoot, const std::string& includeRel
|
||||
return normalizePath(repoRoot);
|
||||
}
|
||||
} // namespace
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Lifecycle
|
||||
PackageManager::PackageManager() {
|
||||
buildRegistry();
|
||||
}
|
||||
@@ -70,7 +73,9 @@ void PackageManager::setProjectRoot(const fs::path& root) {
|
||||
manifestPath = projectRoot / "packages.modu";
|
||||
loadManifest();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Install / Remove
|
||||
bool PackageManager::isInstalled(const std::string& id) const {
|
||||
return std::find(installedIds.begin(), installedIds.end(), id) != installedIds.end();
|
||||
}
|
||||
@@ -135,7 +140,9 @@ bool PackageManager::remove(const std::string& id) {
|
||||
saveManifest();
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Build Config
|
||||
void PackageManager::applyToBuildConfig(ScriptBuildConfig& config) const {
|
||||
std::unordered_set<std::string> defineSet(config.defines.begin(), config.defines.end());
|
||||
std::unordered_set<std::string> linuxLibSet(config.linuxLinkLibs.begin(), config.linuxLinkLibs.end());
|
||||
@@ -167,7 +174,9 @@ void PackageManager::applyToBuildConfig(ScriptBuildConfig& config) const {
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Registry
|
||||
void PackageManager::buildRegistry() {
|
||||
registry.clear();
|
||||
fs::path engineRoot = fs::current_path();
|
||||
@@ -230,7 +239,9 @@ void PackageManager::buildRegistry() {
|
||||
miniaudio.includeDirs = { engineRoot / "include/ThirdParty" };
|
||||
add(miniaudio);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Manifest IO
|
||||
void PackageManager::loadManifest() {
|
||||
installedIds.clear();
|
||||
for (const auto& pkg : registry) {
|
||||
@@ -336,7 +347,9 @@ void PackageManager::saveManifest() const {
|
||||
file << join(pkg->windowsLibs, ';') << "\n";
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Registry Lookup
|
||||
const PackageInfo* PackageManager::findPackage(const std::string& id) const {
|
||||
auto it = std::find_if(registry.begin(), registry.end(), [&](const PackageInfo& p) {
|
||||
return p.id == id;
|
||||
@@ -348,7 +361,9 @@ bool PackageManager::isBuiltIn(const std::string& id) const {
|
||||
const PackageInfo* pkg = findPackage(id);
|
||||
return pkg && pkg->builtIn;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Utility Helpers
|
||||
std::string PackageManager::trim(const std::string& value) {
|
||||
size_t start = 0;
|
||||
while (start < value.size() && std::isspace(static_cast<unsigned char>(value[start]))) start++;
|
||||
@@ -406,7 +421,9 @@ std::string PackageManager::join(const std::vector<std::string>& vals, char deli
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region External Packages
|
||||
fs::path PackageManager::packagesFolder() const {
|
||||
fs::path newFolder = projectRoot / "Library" / "InstalledPackages";
|
||||
if (fs::exists(newFolder) || fs::exists(projectRoot / "scripts.modu")) {
|
||||
@@ -516,3 +533,4 @@ bool PackageManager::updateGitPackage(const std::string& id, std::string& outLog
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
Reference in New Issue
Block a user