ModuleAssemblyComponent pass

This commit is contained in:
EmosewaMC 2023-07-08 01:31:26 -07:00
parent 5301346ed5
commit 28fbe20b97
2 changed files with 29 additions and 64 deletions

View File

@ -1,70 +1,31 @@
#include "ModuleAssemblyComponent.h"
#include "Entity.h"
ModuleAssemblyComponent::ModuleAssemblyComponent(Entity* parent) : Component(parent) {
m_SubKey = LWOOBJID_EMPTY;
m_UseOptionalParts = false;
m_AssemblyPartsLOTs = u"";
}
ModuleAssemblyComponent::~ModuleAssemblyComponent() {
}
void ModuleAssemblyComponent::SetSubKey(LWOOBJID value) {
m_SubKey = value;
}
LWOOBJID ModuleAssemblyComponent::GetSubKey() const {
return m_SubKey;
}
void ModuleAssemblyComponent::SetUseOptionalParts(bool value) {
m_UseOptionalParts = value;
}
bool ModuleAssemblyComponent::GetUseOptionalParts() const {
return m_UseOptionalParts;
}
void ModuleAssemblyComponent::SetAssemblyPartsLOTs(const std::u16string& value) {
std::u16string val{};
val.reserve(value.size() + 1);
for (auto character : value) {
if (character == '+') character = ';';
val.push_back(character);
}
val.push_back(';');
m_AssemblyPartsLOTs = val;
}
const std::u16string& ModuleAssemblyComponent::GetAssemblyPartsLOTs() const {
return m_AssemblyPartsLOTs;
m_AssemblyPartsLOTs = value;
std::replace(m_AssemblyPartsLOTs.begin(), m_AssemblyPartsLOTs.end(), u'+', u';');
// doesn't matter if we push back a ; or a +. The client splits on either of them.
// For congruency however, maintain one or the other.
m_AssemblyPartsLOTs.push_back(u';');
}
void ModuleAssemblyComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
if (bIsInitialUpdate) {
outBitStream->Write1();
if (!bIsInitialUpdate) return;
outBitStream->Write(bIsInitialUpdate);
outBitStream->Write(m_SubKey != LWOOBJID_EMPTY);
if (m_SubKey != LWOOBJID_EMPTY) {
outBitStream->Write(m_SubKey);
}
if (m_SubKey != LWOOBJID_EMPTY) outBitStream->Write(m_SubKey);
outBitStream->Write(m_UseOptionalParts);
outBitStream->Write(static_cast<uint16_t>(m_AssemblyPartsLOTs.size()));
for (char16_t character : m_AssemblyPartsLOTs) {
outBitStream->Write<uint16_t>(m_AssemblyPartsLOTs.size());
for (const char16_t character : m_AssemblyPartsLOTs) {
outBitStream->Write(character);
}
}
}
void ModuleAssemblyComponent::Update(float deltaTime) {
}

View File

@ -1,10 +1,15 @@
#ifndef __MODULEASSEMBLYCOMPONENT__H__
#define __MODULEASSEMBLYCOMPONENT__H__
#pragma once
#include "BitStream.h"
#include "Entity.h"
#include "Component.h"
#include "eReplicaComponentType.h"
namespace RakNet {
class BitStream;
};
/**
* Component that belongs to an object that may be modularly built, like cars and rockets. Note that this is not the
* same as having said items in your inventory (the subkey for this component) this component is the one that
@ -15,35 +20,32 @@ public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MODULE_ASSEMBLY;
ModuleAssemblyComponent(Entity* parent);
~ModuleAssemblyComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void Update(float deltaTime) override;
/**
* Sets the subkey of this entity
* @param value the subkey to set
*/
void SetSubKey(LWOOBJID value);
void SetSubKey(const LWOOBJID& value) { m_SubKey = value; };
/**
* Returns the subkey for this entity
* @return the subkey for this entity
*/
LWOOBJID GetSubKey() const;
LWOOBJID GetSubKey() const { return m_SubKey; };
/**
* Sets the optional parts value
* @param value the value to set
*/
void SetUseOptionalParts(bool value);
void SetUseOptionalParts(bool value) { m_UseOptionalParts = value; };
/**
* Returns the optional parts value
* @return the value to set
*/
bool GetUseOptionalParts() const;
bool GetUseOptionalParts() const { return m_UseOptionalParts; };
/**
* Sets the assembly part lots (the subsections of this modular build)
@ -55,7 +57,7 @@ public:
* Returns the assembly part lots (the subsections of this modular build)
* @return
*/
const std::u16string& GetAssemblyPartsLOTs() const;
const std::u16string& GetAssemblyPartsLOTs() const { return m_AssemblyPartsLOTs; };
private:
@ -75,3 +77,5 @@ private:
*/
std::u16string m_AssemblyPartsLOTs;
};
#endif //!__MODULEASSEMBLYCOMPONENT__H__