Renamed all instances of "Property" to "Field" in ComponentWrapper to maintain consistent naming with ComponentInfo
This commit is contained in:
@@ -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 <typename T>
|
||||
T& Property(std::string name)
|
||||
T& Field(std::string name)
|
||||
{
|
||||
unsigned int offset = Info.Fields.at(name).Offset;
|
||||
return *reinterpret_cast<T*>(&Data[offset]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetProperty(std::string name, const T value) { Property<T>(name) = value; }
|
||||
void SetField(std::string name, const T value) { Field<T>(name) = value; }
|
||||
//template <typename T>
|
||||
//void SetProperty(std::string name, T& value) { Property<T>(name) = value; }
|
||||
//void SetField(std::string name, T& value) { Field<T>(name) = value; }
|
||||
|
||||
// Specialization for string literals
|
||||
template <std::size_t N>
|
||||
void SetProperty(std::string name, const char(&value)[N]) { Property<std::string>(name) = std::string(value); }
|
||||
void SetField(std::string name, const char(&value)[N]) { Field<std::string>(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 <typename T>
|
||||
operator T&() { return m_Component->Property<T>(m_PropertyName); }
|
||||
operator T&() { return m_Component->Field<T>(m_PropertyName); }
|
||||
|
||||
template <typename T>
|
||||
void operator=(const T val) { m_Component->SetProperty<T>(m_PropertyName, val); }
|
||||
void operator=(const T val) { m_Component->SetField<T>(m_PropertyName, val); }
|
||||
// TODO: Pass by reference and rvalue (universal reference?)
|
||||
//template <typename T>
|
||||
//void operator=(T& val) { m_Component->SetProperty<T>(m_PropertyName, val); }
|
||||
//void operator=(T& val) { m_Component->SetField<T>(m_PropertyName, val); }
|
||||
|
||||
// Specialization for string literals
|
||||
template<std::size_t N>
|
||||
void operator=(const char(&val)[N]) { m_Component->SetProperty<N>(m_PropertyName, val); }
|
||||
template <std::size_t N>
|
||||
void operator=(const char(&val)[N]) { m_Component->SetField<N>(m_PropertyName, val); }
|
||||
};
|
||||
SubscriptProxy operator[](std::string propertyName) { return SubscriptProxy(this, propertyName); }
|
||||
};
|
||||
|
||||
@@ -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<glm::vec3>(fieldName);
|
||||
auto& val = component.Field<glm::vec3>(fieldName);
|
||||
if (fieldName == "Scale") {
|
||||
ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, 0.f, std::numeric_limits<float>::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<float>::lowest(), std::numeric_limits<float>::max());
|
||||
}
|
||||
} else if (field.Type == "Color") {
|
||||
auto& val = component.Property<glm::vec4>(fieldName);
|
||||
auto& val = component.Field<glm::vec4>(fieldName);
|
||||
ImGui::ColorEdit4("", glm::value_ptr(val), true);
|
||||
} else if (field.Type == "string") {
|
||||
std::string& val = component.Property<std::string>(fieldName);
|
||||
std::string& val = component.Field<std::string>(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<float>(component.Property<double>(fieldName));
|
||||
float tempVal = static_cast<float>(component.Field<double>(fieldName));
|
||||
if (ImGui::InputFloat("", &tempVal, 0.01f, 1.f)) {
|
||||
component.SetProperty(fieldName, static_cast<double>(tempVal));
|
||||
component.SetField(fieldName, static_cast<double>(tempVal));
|
||||
}
|
||||
} else if (field.Type == "int") {
|
||||
int val = component.Property<int>(fieldName);
|
||||
int val = component.Field<int>(fieldName);
|
||||
ImGui::InputInt("", &val);
|
||||
} else if (field.Type == "enum") {
|
||||
int currentValue = component.Property<int>(fieldName);
|
||||
int currentValue = component.Field<int>(fieldName);
|
||||
int item = -1;
|
||||
std::stringstream enumKeys;
|
||||
std::vector<int> 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<bool>(fieldName);
|
||||
auto& val = component.Field<bool>(fieldName);
|
||||
ImGui::Checkbox("", &val);
|
||||
} else {
|
||||
ImGui::TextDisabled(field.Type.c_str());
|
||||
|
||||
@@ -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<int>("TestInteger"));
|
||||
BOOST_TEST((int)c["TestInteger"] == c.Field<int>("TestInteger"));
|
||||
BOOST_TEST((int)c["TestInteger"] == 1337);
|
||||
BOOST_TEST((double)c["TestDouble"] == 13.37);
|
||||
BOOST_TEST((std::string)c["TestString"] == "Carlito");
|
||||
|
||||
Reference in New Issue
Block a user