From a7fb6eb3f3108f2cf64b0f2bacd64733e2c6c971 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sun, 24 Jul 2022 21:03:22 -0500 Subject: [PATCH] make LoadFromXml usage consistent across comps (#673) --- dGame/Entity.cpp | 9 +++++---- dGame/dComponents/BuffComponent.cpp | 2 +- dGame/dComponents/BuffComponent.h | 2 +- dGame/dComponents/CharacterComponent.cpp | 9 +-------- dGame/dComponents/CharacterComponent.h | 2 +- dGame/dComponents/ControllablePhysicsComponent.cpp | 2 +- dGame/dComponents/ControllablePhysicsComponent.h | 2 +- dGame/dComponents/DestroyableComponent.cpp | 4 ++-- dGame/dComponents/DestroyableComponent.h | 2 +- dGame/dComponents/LevelProgressionComponent.h | 1 - 10 files changed, 14 insertions(+), 21 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 32fa7d5b..fbb61437 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -252,7 +252,7 @@ void Entity::Initialize() ControllablePhysicsComponent* controllablePhysics = new ControllablePhysicsComponent(this); if (m_Character) { - controllablePhysics->LoadFromXML(m_Character->GetXMLDoc()); + controllablePhysics->LoadFromXml(m_Character->GetXMLDoc()); const auto mapID = Game::server->GetZoneID(); @@ -362,7 +362,7 @@ void Entity::Initialize() if (buffComponentID > 0 || collectibleComponentID > 0) { DestroyableComponent* comp = new DestroyableComponent(this); if (m_Character) { - comp->LoadFromXML(m_Character->GetXMLDoc()); + comp->LoadFromXml(m_Character->GetXMLDoc()); } else { if (componentID > 0) { @@ -448,8 +448,9 @@ void Entity::Initialize() m_Components.insert(std::make_pair(COMPONENT_TYPE_PLAYER_FORCED_MOVEMENT, new PlayerForcedMovementComponent(this))); - CharacterComponent* comp = new CharacterComponent(this, m_Character); - m_Components.insert(std::make_pair(COMPONENT_TYPE_CHARACTER, comp)); + CharacterComponent* charComp = new CharacterComponent(this, m_Character); + charComp->LoadFromXml(m_Character->GetXMLDoc()); + m_Components.insert(std::make_pair(COMPONENT_TYPE_CHARACTER, charComp)); } if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_INVENTORY) > 0 || m_Character) { diff --git a/dGame/dComponents/BuffComponent.cpp b/dGame/dComponents/BuffComponent.cpp index 9c12e87d..dcc74214 100644 --- a/dGame/dComponents/BuffComponent.cpp +++ b/dGame/dComponents/BuffComponent.cpp @@ -289,7 +289,7 @@ Entity* BuffComponent::GetParent() const return m_Parent; } -void BuffComponent::LoadFromXML(tinyxml2::XMLDocument* doc) +void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc) { // Load buffs auto* dest = doc->FirstChildElement("obj")->FirstChildElement("dest"); diff --git a/dGame/dComponents/BuffComponent.h b/dGame/dComponents/BuffComponent.h index ba22c08b..49d7fec4 100644 --- a/dGame/dComponents/BuffComponent.h +++ b/dGame/dComponents/BuffComponent.h @@ -49,7 +49,7 @@ public: Entity* GetParent() const; - void LoadFromXML(tinyxml2::XMLDocument* doc); + void LoadFromXml(tinyxml2::XMLDocument* doc) override; void UpdateXml(tinyxml2::XMLDocument* doc) override; diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index c7078f42..f854c2b8 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -37,8 +37,6 @@ CharacterComponent::CharacterComponent(Entity* parent, Character* character) : C m_CountryCode = 0; m_LastUpdateTimestamp = std::time(nullptr); - LoadFromXML(); - //Check to see if we're landing: if (character->GetZoneID() != Game::server->GetZoneID()) { m_IsLanding = true; @@ -184,12 +182,7 @@ void CharacterComponent::SetGMLevel(int gmlevel) { m_GMLevel = gmlevel; } -void CharacterComponent::LoadFromXML() { - if (!m_Character) return; - - tinyxml2::XMLDocument* doc = m_Character->GetXMLDoc(); - if (!doc) return; - +void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) { tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char"); if (!character) { Game::logger->Log("CharacterComponent", "Failed to find char tag while loading XML!\n"); diff --git a/dGame/dComponents/CharacterComponent.h b/dGame/dComponents/CharacterComponent.h index 83b67a17..cd5809f0 100644 --- a/dGame/dComponents/CharacterComponent.h +++ b/dGame/dComponents/CharacterComponent.h @@ -64,7 +64,7 @@ public: CharacterComponent(Entity* parent, Character* character); ~CharacterComponent() override; - void LoadFromXML(); + void LoadFromXml(tinyxml2::XMLDocument* doc) override; void UpdateXml(tinyxml2::XMLDocument* doc) override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); diff --git a/dGame/dComponents/ControllablePhysicsComponent.cpp b/dGame/dComponents/ControllablePhysicsComponent.cpp index 648b1471..5d9cdd40 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.cpp +++ b/dGame/dComponents/ControllablePhysicsComponent.cpp @@ -130,7 +130,7 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bo if (!bIsInitialUpdate) outBitStream->Write0(); } -void ControllablePhysicsComponent::LoadFromXML(tinyxml2::XMLDocument* doc) { +void ControllablePhysicsComponent::LoadFromXml(tinyxml2::XMLDocument* doc) { tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char"); if (!character) { Game::logger->Log("ControllablePhysicsComponent", "Failed to find char tag!\n"); diff --git a/dGame/dComponents/ControllablePhysicsComponent.h b/dGame/dComponents/ControllablePhysicsComponent.h index c7acec62..73b3bb69 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.h +++ b/dGame/dComponents/ControllablePhysicsComponent.h @@ -25,7 +25,7 @@ public: void Update(float deltaTime) override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); - void LoadFromXML(tinyxml2::XMLDocument* doc); + void LoadFromXml(tinyxml2::XMLDocument* doc) override; void ResetFlags(); void UpdateXml(tinyxml2::XMLDocument* doc) override; diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index efcfb5cb..e7a6d385 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -159,7 +159,7 @@ void DestroyableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsIn } } -void DestroyableComponent::LoadFromXML(tinyxml2::XMLDocument* doc) { +void DestroyableComponent::LoadFromXml(tinyxml2::XMLDocument* doc) { tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest"); if (!dest) { Game::logger->Log("DestroyableComponent", "Failed to find dest tag!\n"); @@ -169,7 +169,7 @@ void DestroyableComponent::LoadFromXML(tinyxml2::XMLDocument* doc) { auto* buffComponent = m_Parent->GetComponent(); if (buffComponent != nullptr) { - buffComponent->LoadFromXML(doc); + buffComponent->LoadFromXml(doc); } dest->QueryAttribute("hc", &m_iHealth); diff --git a/dGame/dComponents/DestroyableComponent.h b/dGame/dComponents/DestroyableComponent.h index ade3f4e8..9d2b228f 100644 --- a/dGame/dComponents/DestroyableComponent.h +++ b/dGame/dComponents/DestroyableComponent.h @@ -19,7 +19,7 @@ public: ~DestroyableComponent() override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, uint32_t& flags); - void LoadFromXML(tinyxml2::XMLDocument* doc); + void LoadFromXml(tinyxml2::XMLDocument* doc) override; void UpdateXml(tinyxml2::XMLDocument* doc) override; /** diff --git a/dGame/dComponents/LevelProgressionComponent.h b/dGame/dComponents/LevelProgressionComponent.h index ead3edfb..53f6693e 100644 --- a/dGame/dComponents/LevelProgressionComponent.h +++ b/dGame/dComponents/LevelProgressionComponent.h @@ -17,7 +17,6 @@ public: * @param parent parent that contains this component */ LevelProgressionComponent(Entity* parent); - ~LevelProgressionComponent() override {}; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);