Skip to content

Commit

Permalink
feat: lua variables show up in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMcAvoy committed Nov 7, 2024
1 parent 422ad35 commit b22ffe1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion engine/include/jenjin/gameobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class GameObject {
glm::vec3 color = glm::vec3(1.0f);

std::string texturePath = "";

DataStore dataStore;

// Getters
Expand Down
38 changes: 38 additions & 0 deletions engine/src/editor/editor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <cstring>
#include <sol/make_reference.hpp>
#include <sol/object.hpp>
#define GLFW_INCLUDE_NONE

#include "jenjin/editor/editor.h"
Expand Down Expand Up @@ -357,6 +359,42 @@ void Manager::inspector(Jenjin::Scene *scene) {

ImGui::ItemSize(ImVec2(0, 10));

static auto lua_data_title = ICON_FA_DATABASE " Lua Data";
if (ImGui::CollapsingHeader(lua_data_title)) {
ImGui::Indent();

auto &dataStore = selectedObject.ptr->dataStore;

if (ImGui::BeginTable("luaVars", 2)) {
for (auto &[key, value] : dataStore.entries) {
ImGui::TableNextRow();

ImGui::TableSetColumnIndex(0);
ImGui::Text("%s", key.c_str());

ImGui::TableSetColumnIndex(1);
if (value.get_type() == sol::type::number) {
float copy = value.as<float>();
ImGui::PushID(key.c_str());
if (ImGui::DragFloat("##Value", &copy)) {
scene->GetLuaManager()->Execute(
fmt::format("scene:GetGameObject('{}')['{}'] = {}",
selectedObject.name, key, copy));
}
ImGui::PopID();
} else if (value.get_type() == sol::type::string) {
ImGui::Text("%s", value.as<std::string>().c_str());
} else {
ImGui::Text("Unknown type");
}
}

ImGui::EndTable();
}
}

ImGui::ItemSize(ImVec2(0, 10));

static auto manage_title = ICON_FA_JAR " Manage";
if (ImGui::CollapsingHeader(manage_title, ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Indent();
Expand Down

0 comments on commit b22ffe1

Please sign in to comment.