From 7429902a646699013d94954556c00b015e71ccf8 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sat, 12 Nov 2022 08:44:27 -0600 Subject: [PATCH] Prevent adding movingplatform components to all entites with an attached_path (#829) * Stop adding movingpla comps where they aren't needed * move stuff around to make it more congruent * invert if else block logic patter Since setting up the comp will be longer han just adding the path will make the readability flow better * address feedback --- dGame/Entity.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 52eddd06..62ac8bc2 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -317,15 +317,6 @@ void Entity::Initialize() { m_Components.insert(std::make_pair(COMPONENT_TYPE_SOUND_TRIGGER, comp)); } - //Check to see if we have a moving platform component: - //Which, for some reason didn't get added to the ComponentsRegistry so we have to check for a path manually here. - std::string attachedPath = GetVarAsString(u"attached_path"); - - if (!attachedPath.empty() || compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MOVING_PLATFORM, -1) != -1) { - MovingPlatformComponent* plat = new MovingPlatformComponent(this, attachedPath); - m_Components.insert(std::make_pair(COMPONENT_TYPE_MOVING_PLATFORM, plat)); - } - //Also check for the collectible id: m_CollectibleID = GetVarAs(u"collectible_id"); @@ -696,6 +687,26 @@ void Entity::Initialize() { m_Components.insert(std::make_pair(COMPONENT_TYPE_MOVEMENT_AI, new MovementAIComponent(this, moveInfo))); } + std::string pathName = GetVarAsString(u"attached_path"); + const Path* path = dZoneManager::Instance()->GetZone()->GetPath(pathName); + + //Check to see if we have an attached path and add the appropiate component to handle it: + if (path){ + // if we have a moving platform path, then we need a moving platform component + if (path->pathType == PathType::MovingPlatform) { + MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName); + m_Components.insert(std::make_pair(COMPONENT_TYPE_MOVING_PLATFORM, plat)); + // else if we are a movement path + } /*else if (path->pathType == PathType::Movement) { + auto movementAIcomp = GetComponent(); + if (movementAIcomp){ + // TODO: set path in existing movementAIComp + } else { + // TODO: create movementAIcomp and set path + } + }*/ + } + int proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_PROXIMITY_MONITOR); if (proximityMonitorID > 0) { CDProximityMonitorComponentTable* proxCompTable = CDClientManager::Instance()->GetTable("ProximityMonitorComponent");