Collision Tags autosave on change, fixed serialisation bug with collision tags #342

Merged
direnbharwani merged 2 commits from SP3-2-Physics into main 2023-02-04 01:02:25 +08:00
2 changed files with 14 additions and 4 deletions

View File

@ -50,7 +50,14 @@ namespace SHADE
ImGui::TableNextColumn();
ImGui::PushID(i);
SHEditorWidgets::InputText("##", [i]{return SHCollisionTagMatrix::GetTagName(i);}, [i](std::string const& value){SHCollisionTagMatrix::GetTag(i)->SetName(value);}, tagName.data(), ImGuiInputTextFlags_EnterReturnsTrue);
if (SHEditorWidgets::InputText("##", [i]{return SHCollisionTagMatrix::GetTagName(i);}, [i](std::string const& value){SHCollisionTagMatrix::GetTag(i)->SetName(value);}, tagName.data(), ImGuiInputTextFlags_EnterReturnsTrue))
{
isDirty = true;
std::filesystem::path defaultCollisionTagNameFilePath{ ASSET_ROOT };
defaultCollisionTagNameFilePath.append("CollisionTags.SHConfig");
SHCollisionTagMatrix::SaveToFile(defaultCollisionTagNameFilePath);
}
ImGui::PopID();
// The checkboxes are just to set the layers of each tag
@ -60,10 +67,13 @@ namespace SHADE
{
ImGui::TableNextColumn();
std::string label = std::format("##{}, Layer {}", tagName, j);
std::string label = std::format("##{}, Layer {}", tagName, j+1);
if (SHEditorWidgets::CheckBox(label, [tag, &j] {return tag->GetLayerState(j); }, [tag, j](bool const& value) {tag->SetLayerState(j, value); }, label.substr(2)))
{
isDirty = true;
std::filesystem::path defaultCollisionTagNameFilePath{ ASSET_ROOT };
defaultCollisionTagNameFilePath.append("CollisionTags.SHConfig");
SHCollisionTagMatrix::SaveToFile(defaultCollisionTagNameFilePath);
}
}
}

View File

@ -137,7 +137,7 @@ namespace YAML
Node node;
node[IsTrigger] = rhs.IsTrigger();
node[CollisionTag] = rhs.GetCollisionTag().GetName();
node[CollisionTag] = SHCollisionTagMatrix::GetTagIndex(rhs.GetCollisionTag().GetName());
rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
SHCollisionShape::Type colliderType = rhs.GetType();
@ -176,7 +176,7 @@ namespace YAML
rhs.SetIsTrigger(node[IsTrigger].as<bool>());
if(node[CollisionTag].IsDefined())
rhs.SetCollisionTag(SHCollisionTagMatrix::GetTag(node[CollisionTag].as<std::string>()));
rhs.SetCollisionTag(SHCollisionTagMatrix::GetTag(node[CollisionTag].as<int>()));
if (!node[Type].IsDefined())
return false;