Added double, bool string

This commit is contained in:
Antoine Pilote
2024-08-13 21:42:20 -04:00
parent 9733e9651a
commit 44cb6f7325
2 changed files with 65 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
#include <src/Scene/Components/NetScriptComponent.h>
#include <src/Core/FileSystem.h>
#include <src/Scripting/ScriptingEngineNet.h>
#include <src/Scene/Entities/ImGuiHelper.h>
void NetScriptPanel::Draw(Nuake::Entity entity)
{
@@ -138,6 +139,46 @@ void NetScriptPanel::Draw(Nuake::Entity entity)
field.Value = currentValue;
}
if (field.Type == Nuake::NetScriptExposedVarType::Double)
{
if (!field.Value.has_value())
{
field.Value = field.DefaultValue;
}
float currentValue = (float)std::any_cast<double>(field.Value);
const std::string sliderName = "##" + field.Name + "slider";
ImGui::DragFloat(sliderName.c_str(), &currentValue);
field.Value = (double)currentValue;
}
if (field.Type == Nuake::NetScriptExposedVarType::Bool)
{
if (!field.Value.has_value())
{
field.Value = field.DefaultValue;
}
bool currentValue = std::any_cast<bool>(field.Value);
const std::string sliderName = "##" + field.Name + "slider";
ImGui::Checkbox(sliderName.c_str(), &currentValue);
field.Value = currentValue;
}
if (field.Type == Nuake::NetScriptExposedVarType::String)
{
if (!field.Value.has_value())
{
field.Value = field.DefaultValue;
}
std::string currentValue = std::any_cast<std::string>(field.Value);
const std::string sliderName = "##" + field.Name + "slider";
ImGui::InputText(sliderName.c_str(), &currentValue);
field.Value = currentValue;
}
ImGui::TableNextColumn();
}
}

View File

@@ -207,6 +207,14 @@ namespace Nuake
{
varType = ExposedVarTypes::Double;
}
else if (typeName == "System.String")
{
varType = ExposedVarTypes::String;
}
else if (typeName == "System.Boolean")
{
varType = ExposedVarTypes::Bool;
}
exposedVar.Type = varType;
@@ -284,7 +292,12 @@ namespace Nuake
}
case ExposedVarTypes::String:
{
exposedVar.Value = classInstance.GetFieldValue<float>(varName);
exposedVar.Value = std::string(classInstance.GetFieldValue<Coral::String>(varName));
break;
}
case ExposedVarTypes::Bool:
{
exposedVar.Value = (bool)classInstance.GetFieldValue<int>(varName);
break;
}
case ExposedVarTypes::Entity:
@@ -295,12 +308,19 @@ namespace Nuake
}
}
// Override with user values set in the editor.
for (auto& exposedVarUserValue : component.ExposedVar)
{
classInstance.SetFieldValue(exposedVarUserValue.Name, exposedVarUserValue.Value);
if (exposedVarUserValue.Type == NetScriptExposedVarType::String)
{
std::string stringValue = std::any_cast<std::string>(exposedVarUserValue.Value);
Coral::String coralString = Coral::String::New(stringValue);
classInstance.SetFieldValue(exposedVarUserValue.Name, coralString);
}
else
{
classInstance.SetFieldValue(exposedVarUserValue.Name, exposedVarUserValue.Value);
}
}
m_EntityToManagedObjects.emplace(entity.GetID(), classInstance);