Animation WIP merge #321

Merged
XiaoQiDigipen merged 76 commits from SP3-17-animation-system into main 2023-01-30 17:35:57 +08:00
1 changed files with 21 additions and 7 deletions
Showing only changes of commit 406759f856 - Show all commits

View File

@ -27,6 +27,13 @@
namespace SHADE namespace SHADE
{ {
template<typename Component>
void EnsureComponent(EntityID eid)
{
if(SHComponentManager::GetComponent_s<Component>(eid) == nullptr)
SHComponentManager::AddComponent<Component>(eid);
}
template<typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true> template<typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
bool DrawAddComponentButton(EntityID const& eid) bool DrawAddComponentButton(EntityID const& eid)
{ {
@ -48,9 +55,13 @@ namespace SHADE
return selected; return selected;
} }
template <typename ComponentType, typename EnforcedComponent, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true, std::enable_if_t<std::is_base_of_v<SHComponent, EnforcedComponent>, bool> = true> template <typename ComponentType, typename ... EnforcedComponents>
bool DrawAddComponentWithEnforcedComponentButton(EntityID const& eid) bool DrawAddComponentWithEnforcedComponentButton(EntityID const& eid)
{ {
// Only make sure components are passed here
static_assert(std::is_base_of_v<SHComponent, ComponentType>, "");
//(static_assert(std::is_base_of_v<SHComponent, EnforcedComponents>, ""), ...);
bool selected = false; bool selected = false;
if (!SHComponentManager::HasComponent<ComponentType>(eid)) if (!SHComponentManager::HasComponent<ComponentType>(eid))
{ {
@ -58,9 +69,8 @@ namespace SHADE
if(selected = ImGui::Selectable(std::format("Add {}", componentName).data()); selected) if(selected = ImGui::Selectable(std::format("Add {}", componentName).data()); selected)
{ {
if(SHComponentManager::GetComponent_s<EnforcedComponent>(eid) == nullptr) // Ensure that all required components are present
SHComponentManager::AddComponent<EnforcedComponent>(eid); (EnsureComponent<EnforcedComponents>(eid), ...);
SHComponentManager::AddComponent<ComponentType>(eid); SHComponentManager::AddComponent<ComponentType>(eid);
} }
if(ImGui::IsItemHovered()) if(ImGui::IsItemHovered())
@ -69,9 +79,8 @@ namespace SHADE
ImGui::Text("Adds", componentName); ImGui::SameLine(); ImGui::Text("Adds", componentName); ImGui::SameLine();
ImGui::TextColored(ImGuiColors::green, "%s", componentName); ImGui::SameLine(); ImGui::TextColored(ImGuiColors::green, "%s", componentName); ImGui::SameLine();
ImGui::Text("to this entity", componentName); ImGui::Text("to this entity", componentName);
ImGui::Text("Adds"); ImGui::SameLine(); ImGui::Text("Adds the following components if the entity does not already have it: ");
ImGui::TextColored(ImGuiColors::red, "%s", rttr::type::get<EnforcedComponent>().get_name().data()); ImGui::SameLine(); (ImGui::TextColored(ImGuiColors::red, "%s", rttr::type::get<EnforcedComponents>().get_name().data()), ...);
ImGui::Text("if the entity does not already have it");
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
} }
@ -118,6 +127,10 @@ namespace SHADE
{ {
DrawComponent(renderableComponent); DrawComponent(renderableComponent);
} }
if (auto animatorComponent = SHComponentManager::GetComponent_s<SHAnimatorComponent>(eid))
{
DrawComponent(animatorComponent);
}
if(auto colliderComponent = SHComponentManager::GetComponent_s<SHColliderComponent>(eid)) if(auto colliderComponent = SHComponentManager::GetComponent_s<SHColliderComponent>(eid))
{ {
DrawComponent(colliderComponent); DrawComponent(colliderComponent);
@ -174,6 +187,7 @@ namespace SHADE
DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid); DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid);
DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid); DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid);
DrawAddComponentWithEnforcedComponentButton<SHTextRenderableComponent, SHTransformComponent>(eid); DrawAddComponentWithEnforcedComponentButton<SHTextRenderableComponent, SHTransformComponent>(eid);
DrawAddComponentWithEnforcedComponentButton<SHAnimatorComponent, SHTransformComponent, SHRenderable>(eid);
ImGui::EndMenu(); ImGui::EndMenu();