diff --git a/include/Engine/Core/ComponentWrapper.h b/include/Engine/Core/ComponentWrapper.h index 9d27b0f8..b1e5f9ad 100644 --- a/include/Engine/Core/ComponentWrapper.h +++ b/include/Engine/Core/ComponentWrapper.h @@ -5,8 +5,7 @@ #include "Entity.h" #include "ComponentInfo.h" #include "Util/Any.h" - -// TODO: Change all instances "Property" to "Field" to remain consistent with ComponentInfo +Minecraft hard drilling struct ComponentWrapper { ComponentWrapper(const ComponentInfo& componentInfo, char* data) @@ -25,20 +24,20 @@ struct ComponentWrapper } template - T& Property(std::string name) + T& Field(std::string name) { unsigned int offset = Info.Fields.at(name).Offset; return *reinterpret_cast(&Data[offset]); } template - void SetProperty(std::string name, const T value) { Property(name) = value; } + void SetField(std::string name, const T value) { Field(name) = value; } //template - //void SetProperty(std::string name, T& value) { Property(name) = value; } + //void SetField(std::string name, T& value) { Field(name) = value; } // Specialization for string literals template - void SetProperty(std::string name, const char(&value)[N]) { Property(name) = std::string(value); } + void SetField(std::string name, const char(&value)[N]) { Field(name) = std::string(value); } struct SubscriptProxy { @@ -57,17 +56,17 @@ struct ComponentWrapper int Enum(const char* enumKey) { return m_Component->Enum(m_PropertyName.c_str(), enumKey); } template - operator T&() { return m_Component->Property(m_PropertyName); } + operator T&() { return m_Component->Field(m_PropertyName); } template - void operator=(const T val) { m_Component->SetProperty(m_PropertyName, val); } + void operator=(const T val) { m_Component->SetField(m_PropertyName, val); } // TODO: Pass by reference and rvalue (universal reference?) //template - //void operator=(T& val) { m_Component->SetProperty(m_PropertyName, val); } + //void operator=(T& val) { m_Component->SetField(m_PropertyName, val); } // Specialization for string literals - template - void operator=(const char(&val)[N]) { m_Component->SetProperty(m_PropertyName, val); } + template + void operator=(const char(&val)[N]) { m_Component->SetField(m_PropertyName, val); } }; SubscriptProxy operator[](std::string propertyName) { return SubscriptProxy(this, propertyName); } }; diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 22e1bfc0..d5863814 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -496,7 +496,7 @@ void EditorSystem::drawUI(World* world, double dt) std::string uniqueID = componentType + fieldName; ImGui::PushID(uniqueID.c_str()); if (field.Type == "Vector") { - auto& val = component.Property(fieldName); + auto& val = component.Field(fieldName); if (fieldName == "Scale") { ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, 0.f, std::numeric_limits::max()); } else if (fieldName == "Orientation") { @@ -508,10 +508,10 @@ void EditorSystem::drawUI(World* world, double dt) ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, std::numeric_limits::lowest(), std::numeric_limits::max()); } } else if (field.Type == "Color") { - auto& val = component.Property(fieldName); + auto& val = component.Field(fieldName); ImGui::ColorEdit4("", glm::value_ptr(val), true); } else if (field.Type == "string") { - std::string& val = component.Property(fieldName); + std::string& val = component.Field(fieldName); char tempString[1024]; memcpy(tempString, val.c_str(), std::min(val.length() + 1, sizeof(tempString))); if (ImGui::InputText("", tempString, sizeof(tempString))) { @@ -525,15 +525,15 @@ void EditorSystem::drawUI(World* world, double dt) } } else if (field.Type == "double") { - float tempVal = static_cast(component.Property(fieldName)); + float tempVal = static_cast(component.Field(fieldName)); if (ImGui::InputFloat("", &tempVal, 0.01f, 1.f)) { - component.SetProperty(fieldName, static_cast(tempVal)); + component.SetField(fieldName, static_cast(tempVal)); } } else if (field.Type == "int") { - int val = component.Property(fieldName); + int val = component.Field(fieldName); ImGui::InputInt("", &val); } else if (field.Type == "enum") { - int currentValue = component.Property(fieldName); + int currentValue = component.Field(fieldName); int item = -1; std::stringstream enumKeys; std::vector enumValues; @@ -547,10 +547,10 @@ void EditorSystem::drawUI(World* world, double dt) i++; } if (ImGui::Combo("", &item, enumKeys.str().c_str())) { - component.SetProperty(fieldName, enumValues.at(item)); + component.SetField(fieldName, enumValues.at(item)); } } else if (field.Type == "bool") { - auto& val = component.Property(fieldName); + auto& val = component.Field(fieldName); ImGui::Checkbox("", &val); } else { ImGui::TextDisabled(field.Type.c_str()); diff --git a/src/Tests/WorldTest.cpp b/src/Tests/WorldTest.cpp index 8d92a328..03008562 100644 --- a/src/Tests/WorldTest.cpp +++ b/src/Tests/WorldTest.cpp @@ -20,7 +20,7 @@ BOOST_AUTO_TEST_CASE(WorldTestSingleAllocation, * boost::unit_test::tolerance(0. ComponentWrapper c = w.AttachComponent(e, "Test"); // Check default values - BOOST_TEST((int)c["TestInteger"] == c.Property("TestInteger")); + BOOST_TEST((int)c["TestInteger"] == c.Field("TestInteger")); BOOST_TEST((int)c["TestInteger"] == 1337); BOOST_TEST((double)c["TestDouble"] == 13.37); BOOST_TEST((std::string)c["TestString"] == "Carlito");