refactor: Rewrite BehaviorMessage classes to use member initialization, preferred member naming conventions, and const-ref getters (#1456)

* Split out BehaviorMessage class changes from PR #1452

* remove <string_view> inclusion in ActionContext.h

* add the arguments nullptr check back in

* remove redundant std::string constructor calls

* Update AddStripMessage.cpp - change push_back to emplace_back
This commit is contained in:
jadebenn 2024-02-18 00:38:26 -06:00 committed by GitHub
parent c7b3d9e817
commit b6af92ef81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
46 changed files with 362 additions and 341 deletions

View File

@ -127,12 +127,12 @@ public:
/** /**
* Returns the Associative portion of the object * Returns the Associative portion of the object
*/ */
[[nodiscard]] inline AMFAssociative& GetAssociative() noexcept { return this->associative; } [[nodiscard]] inline const AMFAssociative& GetAssociative() const noexcept { return this->associative; }
/** /**
* Returns the dense portion of the object * Returns the dense portion of the object
*/ */
[[nodiscard]] inline AMFDense& GetDense() noexcept { return this->dense; } [[nodiscard]] inline const AMFDense& GetDense() const noexcept { return this->dense; }
/** /**
* Inserts an AMFValue into the associative portion with the given key. * Inserts an AMFValue into the associative portion with the given key.
@ -297,7 +297,7 @@ public:
if (!this->dense.empty()) Remove(this->dense.size() - 1); if (!this->dense.empty()) Remove(this->dense.size() - 1);
} }
[[nodiscard]] AMFArrayValue* GetArray(const std::string& key) { [[nodiscard]] AMFArrayValue* GetArray(const std::string& key) const {
AMFAssociative::const_iterator it = this->associative.find(key); AMFAssociative::const_iterator it = this->associative.find(key);
if (it != this->associative.end()) { if (it != this->associative.end()) {
return dynamic_cast<AMFArrayValue*>(it->second); return dynamic_cast<AMFArrayValue*>(it->second);
@ -305,7 +305,7 @@ public:
return nullptr; return nullptr;
} }
[[nodiscard]] AMFArrayValue* GetArray(const size_t index) { [[nodiscard]] AMFArrayValue* GetArray(const size_t index) const {
return index >= this->dense.size() ? nullptr : dynamic_cast<AMFArrayValue*>(this->dense.at(index)); return index >= this->dense.size() ? nullptr : dynamic_cast<AMFArrayValue*>(this->dense.at(index));
} }

View File

@ -2504,7 +2504,7 @@ void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* e
auto owner = PropertyManagementComponent::Instance()->GetOwner(); auto owner = PropertyManagementComponent::Instance()->GetOwner();
if (!owner) return; if (!owner) return;
ControlBehaviors::Instance().ProcessCommand(entity, sysAddr, static_cast<AMFArrayValue*>(amfArguments.get()), command, owner); ControlBehaviors::Instance().ProcessCommand(entity, static_cast<AMFArrayValue*>(amfArguments.get()), command, owner);
} }
void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {

View File

@ -2,8 +2,8 @@
BlockDefinition BlockDefinition::blockDefinitionDefault{}; BlockDefinition BlockDefinition::blockDefinitionDefault{};
BlockDefinition::BlockDefinition(std::string defaultValue, float minimumValue, float maximumValue) { BlockDefinition::BlockDefinition(const std::string& defaultValue, const float minimumValue, const float maximumValue)
this->defaultValue = defaultValue; : m_DefaultValue{ defaultValue }
this->minimumValue = minimumValue; , m_MinimumValue{ minimumValue }
this->maximumValue = maximumValue; , m_MaximumValue{ maximumValue } {
} }

View File

@ -7,19 +7,20 @@ class AMFArrayValue;
class BlockDefinition { class BlockDefinition {
public: public:
BlockDefinition(std::string defaultValue = "", float minimumValue = 0.0f, float maximumValue = 0.0f); BlockDefinition(const std::string& defaultValue = "", const float minimumValue = 0.0f, const float maximumValue = 0.0f);
static BlockDefinition blockDefinitionDefault; static BlockDefinition blockDefinitionDefault;
std::string& GetDefaultValue() { return defaultValue; }; [[nodiscard]] const std::string& GetDefaultValue() const { return m_DefaultValue; }
float GetMinimumValue() { return minimumValue; }; [[nodiscard]] float GetMinimumValue() const noexcept { return m_MinimumValue; }
float GetMaximumValue() { return maximumValue; }; [[nodiscard]] float GetMaximumValue() const noexcept { return m_MaximumValue; }
void SetDefaultValue(std::string value) { defaultValue = value; }; void SetDefaultValue(const std::string& value) { m_DefaultValue = value; }
void SetMinimumValue(float value) { minimumValue = value; }; void SetMinimumValue(const float value) noexcept { m_MinimumValue = value; }
void SetMaximumValue(float value) { maximumValue = value; }; void SetMaximumValue(const float value) noexcept { m_MaximumValue = value; }
private: private:
std::string defaultValue; std::string m_DefaultValue;
float minimumValue; float m_MinimumValue;
float maximumValue; float m_MaximumValue;
}; };
#endif //!__BLOCKDEFINITION__H__ #endif //!__BLOCKDEFINITION__H__

View File

@ -1,46 +1,34 @@
#include "Action.h" #include "Action.h"
#include "Amf3.h" #include "Amf3.h"
Action::Action() { Action::Action(const AMFArrayValue* arguments) {
type = ""; for (const auto& [paramName, paramValue] : arguments->GetAssociative()) {
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
}
Action::Action(AMFArrayValue* arguments) {
type = "";
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
for (auto& [paramName, paramValue] : arguments->GetAssociative()) {
if (paramName == "Type") { if (paramName == "Type") {
if (paramValue->GetValueType() != eAmf::String) continue; if (paramValue->GetValueType() != eAmf::String) continue;
type = static_cast<AMFStringValue*>(paramValue)->GetValue(); m_Type = static_cast<AMFStringValue*>(paramValue)->GetValue();
} else { } else {
valueParameterName = paramName; m_ValueParameterName = paramName;
// Message is the only known string parameter // Message is the only known string parameter
if (valueParameterName == "Message") { if (m_ValueParameterName == "Message") {
if (paramValue->GetValueType() != eAmf::String) continue; if (paramValue->GetValueType() != eAmf::String) continue;
valueParameterString = static_cast<AMFStringValue*>(paramValue)->GetValue(); m_ValueParameterString = static_cast<AMFStringValue*>(paramValue)->GetValue();
} else { } else {
if (paramValue->GetValueType() != eAmf::Double) continue; if (paramValue->GetValueType() != eAmf::Double) continue;
valueParameterDouble = static_cast<AMFDoubleValue*>(paramValue)->GetValue(); m_ValueParameterDouble = static_cast<AMFDoubleValue*>(paramValue)->GetValue();
} }
} }
} }
} }
void Action::SendBehaviorBlocksToClient(AMFArrayValue& args) const { void Action::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
auto* actionArgs = args.PushArray(); auto* const actionArgs = args.PushArray();
actionArgs->Insert("Type", type); actionArgs->Insert("Type", m_Type);
auto valueParameterName = GetValueParameterName(); if (m_ValueParameterName.empty()) return;
if (valueParameterName.empty()) return;
if (valueParameterName == "Message") { if (m_ValueParameterName == "Message") {
actionArgs->Insert(valueParameterName, valueParameterString); actionArgs->Insert(m_ValueParameterName, m_ValueParameterString);
} else { } else {
actionArgs->Insert(valueParameterName, valueParameterDouble); actionArgs->Insert(m_ValueParameterName, m_ValueParameterDouble);
} }
} }

View File

@ -11,19 +11,20 @@ class AMFArrayValue;
*/ */
class Action { class Action {
public: public:
Action(); Action() = default;
Action(AMFArrayValue* arguments); Action(const AMFArrayValue* arguments);
const std::string& GetType() const { return type; }; [[nodiscard]] const std::string& GetType() const { return m_Type; };
const std::string& GetValueParameterName() const { return valueParameterName; }; [[nodiscard]] const std::string& GetValueParameterName() const { return m_ValueParameterName; };
const std::string& GetValueParameterString() const { return valueParameterString; }; [[nodiscard]] const std::string& GetValueParameterString() const { return m_ValueParameterString; };
const double GetValueParameterDouble() const { return valueParameterDouble; }; [[nodiscard]] double GetValueParameterDouble() const noexcept { return m_ValueParameterDouble; };
void SendBehaviorBlocksToClient(AMFArrayValue& args) const; void SendBehaviorBlocksToClient(AMFArrayValue& args) const;
private: private:
std::string type; double m_ValueParameterDouble{ 0.0 };
std::string valueParameterName; std::string m_Type{ "" };
std::string valueParameterString; std::string m_ValueParameterName{ "" };
double valueParameterDouble; std::string m_ValueParameterString{ "" };
}; };
#endif //!__ACTION__H__ #endif //!__ACTION__H__

View File

@ -4,27 +4,20 @@
#include "Amf3.h" #include "Amf3.h"
ActionContext::ActionContext() { ActionContext::ActionContext(const AMFArrayValue* arguments, const std::string& customStateKey, const std::string& customStripKey)
stripId = 0; : m_StripId{ GetStripIdFromArgument(arguments, customStripKey) }
stateId = BehaviorState::HOME_STATE; , m_StateId{ GetBehaviorStateFromArgument(arguments, customStateKey) } {
} }
ActionContext::ActionContext(AMFArrayValue* arguments, std::string customStateKey, std::string customStripKey) { BehaviorState ActionContext::GetBehaviorStateFromArgument(const AMFArrayValue* arguments, const std::string& key) const {
stripId = 0; const auto* const stateIDValue = arguments->Get<double>(key);
stateId = BehaviorState::HOME_STATE;
stripId = GetStripIdFromArgument(arguments, customStripKey);
stateId = GetBehaviorStateFromArgument(arguments, customStateKey);
}
BehaviorState ActionContext::GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key) {
auto* stateIDValue = arguments->Get<double>(key);
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\""); if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\"");
return static_cast<BehaviorState>(stateIDValue->GetValue()); return static_cast<BehaviorState>(stateIDValue->GetValue());
} }
StripId ActionContext::GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key) { StripId ActionContext::GetStripIdFromArgument(const AMFArrayValue* arguments, const std::string& key) const {
auto* stripIdValue = arguments->Get<double>(key); const auto* const stripIdValue = arguments->Get<double>(key);
if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\""); if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\"");
return static_cast<StripId>(stripIdValue->GetValue()); return static_cast<StripId>(stripIdValue->GetValue());

View File

@ -12,15 +12,16 @@ class AMFArrayValue;
*/ */
class ActionContext { class ActionContext {
public: public:
ActionContext(); ActionContext() noexcept = default;
ActionContext(AMFArrayValue* arguments, std::string customStateKey = "stateID", std::string customStripKey = "stripID"); ActionContext(const AMFArrayValue* arguments, const std::string& customStateKey = "stateID", const std::string& customStripKey = "stripID");
const StripId GetStripId() const { return stripId; }; [[nodiscard]] StripId GetStripId() const noexcept { return m_StripId; };
const BehaviorState GetStateId() const { return stateId; }; [[nodiscard]] BehaviorState GetStateId() const noexcept { return m_StateId; };
private: private:
BehaviorState GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key); [[nodiscard]] BehaviorState GetBehaviorStateFromArgument(const AMFArrayValue* arguments, const std::string& key) const;
StripId GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key); [[nodiscard]] StripId GetStripIdFromArgument(const AMFArrayValue* arguments, const std::string& key) const;
StripId stripId; StripId m_StripId{ 0 };
BehaviorState stateId; BehaviorState m_StateId{ BehaviorState::HOME_STATE };
}; };
#endif //!__ACTIONCONTEXT__H__ #endif //!__ACTIONCONTEXT__H__

View File

@ -1,13 +1,14 @@
#include "AddActionMessage.h" #include "AddActionMessage.h"
AddActionMessage::AddActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { AddActionMessage::AddActionMessage(const AMFArrayValue* arguments)
actionContext = ActionContext(arguments); : BehaviorMessageBase{ arguments }
actionIndex = GetActionIndexFromArgument(arguments); , m_ActionIndex{ GetActionIndexFromArgument(arguments) }
, m_ActionContext{ arguments } {
auto* actionValue = arguments->GetArray("action"); const auto* const actionValue = arguments->GetArray("action");
if (!actionValue) return; if (!actionValue) return;
action = Action(actionValue); m_Action = Action{ actionValue };
LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i", actionIndex, actionContext.GetStripId(), actionContext.GetStateId(), action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId); LOG_DEBUG("actionIndex %i stripId %i stateId %i type %s valueParameterName %s valueParameterString %s valueParameterDouble %f m_BehaviorId %i", m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_Action.GetType().c_str(), m_Action.GetValueParameterName().c_str(), m_Action.GetValueParameterString().c_str(), m_Action.GetValueParameterDouble(), m_BehaviorId);
} }

View File

@ -13,14 +13,18 @@ class AMFArrayValue;
*/ */
class AddActionMessage : public BehaviorMessageBase { class AddActionMessage : public BehaviorMessageBase {
public: public:
AddActionMessage(AMFArrayValue* arguments); AddActionMessage(const AMFArrayValue* arguments);
int32_t GetActionIndex() const { return actionIndex; };
Action GetAction() const { return action; }; [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; };
ActionContext GetActionContext() const { return actionContext; };
[[nodiscard]] const Action& GetAction() const noexcept { return m_Action; };
[[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; };
private: private:
int32_t actionIndex = -1; int32_t m_ActionIndex{ -1 };
ActionContext actionContext; ActionContext m_ActionContext;
Action action; Action m_Action;
}; };
#endif //!__ADDACTIONMESSAGE__H__ #endif //!__ADDACTIONMESSAGE__H__

View File

@ -1,11 +1,9 @@
#include "AddMessage.h" #include "AddMessage.h"
AddMessage::AddMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { AddMessage::AddMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } {
behaviorIndex = 0; const auto* const behaviorIndexValue = arguments->Get<double>("BehaviorIndex");
auto* behaviorIndexValue = arguments->Get<double>("BehaviorIndex");
if (!behaviorIndexValue) return; if (!behaviorIndexValue) return;
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue()); m_BehaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());
LOG_DEBUG("behaviorId %i index %i", behaviorId, behaviorIndex); LOG_DEBUG("behaviorId %i index %i", m_BehaviorId, m_BehaviorIndex);
} }

View File

@ -9,10 +9,11 @@
*/ */
class AddMessage : public BehaviorMessageBase { class AddMessage : public BehaviorMessageBase {
public: public:
AddMessage(AMFArrayValue* arguments); AddMessage(const AMFArrayValue* arguments);
const uint32_t GetBehaviorIndex() const { return behaviorIndex; }; [[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; };
private: private:
uint32_t behaviorIndex; uint32_t m_BehaviorIndex{ 0 };
}; };
#endif //!__ADDMESSAGE__H__ #endif //!__ADDMESSAGE__H__

View File

@ -2,27 +2,24 @@
#include "Action.h" #include "Action.h"
AddStripMessage::AddStripMessage(AMFArrayValue* const arguments) : BehaviorMessageBase{ arguments } { AddStripMessage::AddStripMessage(const AMFArrayValue* arguments)
actionContext = ActionContext(arguments); : BehaviorMessageBase{ arguments }
position = StripUiPosition(arguments); , m_Position{ arguments }
, m_ActionContext{ arguments } {
auto* strip = arguments->GetArray("strip"); const auto* const strip = arguments->GetArray("strip");
if (!strip) return; if (!strip) return;
auto* actions = strip->GetArray("actions"); const auto* const actions = strip->GetArray("actions");
if (!actions) return; if (!actions) return;
for (uint32_t actionNumber = 0; actionNumber < actions->GetDense().size(); actionNumber++) { for (uint32_t actionNumber = 0; actionNumber < actions->GetDense().size(); actionNumber++) {
auto* actionValue = actions->GetArray(actionNumber); const auto* const actionValue = actions->GetArray(actionNumber);
if (!actionValue) continue; if (!actionValue) continue;
actionsToAdd.push_back(Action(actionValue)); m_ActionsToAdd.emplace_back(actionValue);
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId, actionsToAdd.back().GetType().c_str(), actionsToAdd.back().GetValueParameterName().c_str(), actionsToAdd.back().GetValueParameterString().c_str(), actionsToAdd.back().GetValueParameterDouble()); LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId, m_ActionsToAdd.back().GetType().c_str(), m_ActionsToAdd.back().GetValueParameterName().c_str(), m_ActionsToAdd.back().GetValueParameterString().c_str(), m_ActionsToAdd.back().GetValueParameterDouble());
} }
LOG_DEBUG("number of actions %i", actionsToAdd.size()); LOG_DEBUG("number of actions %i", m_ActionsToAdd.size());
}
std::vector<Action> AddStripMessage::GetActionsToAdd() const {
return actionsToAdd;
} }

View File

@ -18,14 +18,18 @@ class AMFArrayValue;
*/ */
class AddStripMessage : public BehaviorMessageBase { class AddStripMessage : public BehaviorMessageBase {
public: public:
AddStripMessage(AMFArrayValue* const arguments); AddStripMessage(const AMFArrayValue* arguments);
StripUiPosition GetPosition() const { return position; };
ActionContext GetActionContext() const { return actionContext; }; [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; }
std::vector<Action> GetActionsToAdd() const;
[[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }
[[nodiscard]] const std::vector<Action>& GetActionsToAdd() const noexcept { return m_ActionsToAdd; }
private: private:
StripUiPosition position; StripUiPosition m_Position;
ActionContext actionContext; ActionContext m_ActionContext;
std::vector<Action> actionsToAdd; std::vector<Action> m_ActionsToAdd;
}; };
#endif //!__ADDSTRIPMESSAGE__H__ #endif //!__ADDSTRIPMESSAGE__H__

View File

@ -4,25 +4,22 @@
#include "BehaviorStates.h" #include "BehaviorStates.h"
#include "dCommonVars.h" #include "dCommonVars.h"
BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) { int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue* arguments) {
this->behaviorId = GetBehaviorIdFromArgument(arguments); static constexpr const char* key = "BehaviorID";
}
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* const arguments) {
const char* const key = "BehaviorID";
const auto* const behaviorIDValue = arguments->Get<std::string>(key); const auto* const behaviorIDValue = arguments->Get<std::string>(key);
int32_t behaviorId = DefaultBehaviorId;
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
this->behaviorId = behaviorId =
GeneralUtils::TryParse<int32_t>(behaviorIDValue->GetValue()).value_or(this->behaviorId); GeneralUtils::TryParse<int32_t>(behaviorIDValue->GetValue()).value_or(behaviorId);
} else if (arguments->Get(key) && arguments->Get(key)->GetValueType() != eAmf::Undefined) { } else if (arguments->Get(key) && arguments->Get(key)->GetValueType() != eAmf::Undefined) {
throw std::invalid_argument("Unable to find behavior ID"); throw std::invalid_argument("Unable to find behavior ID");
} }
return this->behaviorId; return behaviorId;
} }
int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName) const { int32_t BehaviorMessageBase::GetActionIndexFromArgument(const AMFArrayValue* arguments, const std::string& keyName) const {
const auto* const actionIndexAmf = arguments->Get<double>(keyName); const auto* const actionIndexAmf = arguments->Get<double>(keyName);
if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex"); if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex");

View File

@ -15,14 +15,15 @@ enum class BehaviorState : uint32_t;
*/ */
class BehaviorMessageBase { class BehaviorMessageBase {
public: public:
static constexpr int32_t DefaultBehaviorId = -1; static constexpr int32_t DefaultBehaviorId{ -1 };
[[nodiscard]] int32_t GetBehaviorId() const { return behaviorId; }; BehaviorMessageBase(const AMFArrayValue* arguments) : m_BehaviorId{ GetBehaviorIdFromArgument(arguments) } {}
[[nodiscard]] bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; }; [[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; }
BehaviorMessageBase(AMFArrayValue* const arguments); [[nodiscard]] bool IsDefaultBehaviorId() const noexcept { return m_BehaviorId == DefaultBehaviorId; }
protected: protected:
[[nodiscard]] int32_t GetBehaviorIdFromArgument(AMFArrayValue* const arguments); [[nodiscard]] int32_t GetBehaviorIdFromArgument(const AMFArrayValue* arguments);
[[nodiscard]] int32_t GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName = "actionIndex") const; [[nodiscard]] int32_t GetActionIndexFromArgument(const AMFArrayValue* arguments, const std::string& keyName = "actionIndex") const;
int32_t behaviorId = DefaultBehaviorId; int32_t m_BehaviorId{ DefaultBehaviorId };
}; };
#endif //!__BEHAVIORMESSAGEBASE__H__ #endif //!__BEHAVIORMESSAGEBASE__H__

View File

@ -1,11 +1,11 @@
#include "MergeStripsMessage.h" #include "MergeStripsMessage.h"
MergeStripsMessage::MergeStripsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { MergeStripsMessage::MergeStripsMessage(const AMFArrayValue* arguments)
sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); : BehaviorMessageBase{ arguments }
, m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") }
, m_SourceActionContext{ arguments, "srcStateID", "srcStripID" }
, m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" } {
destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); LOG_DEBUG("srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_DstActionIndex, m_BehaviorId);
dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex");
LOG_DEBUG("srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), dstActionIndex, behaviorId);
} }

View File

@ -13,17 +13,23 @@ class AMFArrayValue;
*/ */
class MergeStripsMessage : public BehaviorMessageBase { class MergeStripsMessage : public BehaviorMessageBase {
public: public:
MergeStripsMessage(AMFArrayValue* arguments); MergeStripsMessage(const AMFArrayValue* arguments);
int32_t GetDstActionIndex() const { return dstActionIndex; };
ActionContext GetSourceActionContext() const { return sourceActionContext; }; [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; }
ActionContext GetDestinationActionContext() const { return destinationActionContext; };
const std::vector<Action>& GetMigratedActions() const { return migratedActions; }; [[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; }
void SetMigratedActions(std::vector<Action>::const_iterator start, std::vector<Action>::const_iterator end) { migratedActions.assign(start, end); };
[[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; }
[[nodiscard]] const std::vector<Action>& GetMigratedActions() const noexcept { return m_MigratedActions; }
void SetMigratedActions(std::vector<Action>::const_iterator start, std::vector<Action>::const_iterator end) { m_MigratedActions.assign(start, end); };
private: private:
std::vector<Action> migratedActions; int32_t m_DstActionIndex;
ActionContext sourceActionContext; std::vector<Action> m_MigratedActions;
ActionContext destinationActionContext; ActionContext m_SourceActionContext;
int32_t dstActionIndex; ActionContext m_DestinationActionContext;
}; };
#endif //!__MERGESTRIPSMESSAGE__H__ #endif //!__MERGESTRIPSMESSAGE__H__

View File

@ -1,11 +1,11 @@
#include "MigrateActionsMessage.h" #include "MigrateActionsMessage.h"
MigrateActionsMessage::MigrateActionsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { MigrateActionsMessage::MigrateActionsMessage(const AMFArrayValue* arguments)
sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); : BehaviorMessageBase{ arguments }
srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") }
, m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") }
, m_SourceActionContext{ arguments, "srcStateID", "srcStripID" }
, m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" } {
destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); LOG_DEBUG("srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %i", m_SrcActionIndex, m_DstActionIndex, m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_BehaviorId);
dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex");
LOG_DEBUG("srcactionIndex %i dstactionIndex %i srcstripId %i dststripId %i srcstateId %i dststateId %i behaviorId %i", srcActionIndex, dstActionIndex, sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), behaviorId);
} }

View File

@ -13,19 +13,26 @@ class AMFArrayValue;
*/ */
class MigrateActionsMessage : public BehaviorMessageBase { class MigrateActionsMessage : public BehaviorMessageBase {
public: public:
MigrateActionsMessage(AMFArrayValue* arguments); MigrateActionsMessage(const AMFArrayValue* arguments);
int32_t GetSrcActionIndex() const { return srcActionIndex; };
int32_t GetDstActionIndex() const { return dstActionIndex; }; [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; }
ActionContext GetSourceActionContext() const { return sourceActionContext; };
ActionContext GetDestinationActionContext() const { return destinationActionContext; }; [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; }
const std::vector<Action>& GetMigratedActions() const { return migratedActions; };
void SetMigratedActions(std::vector<Action>::const_iterator start, std::vector<Action>::const_iterator end) { migratedActions.assign(start, end); }; [[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; }
[[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; }
[[nodiscard]] const std::vector<Action>& GetMigratedActions() const noexcept { return m_MigratedActions; }
void SetMigratedActions(std::vector<Action>::const_iterator start, std::vector<Action>::const_iterator end) { m_MigratedActions.assign(start, end); }
private: private:
std::vector<Action> migratedActions; int32_t m_SrcActionIndex;
ActionContext sourceActionContext; int32_t m_DstActionIndex;
ActionContext destinationActionContext; std::vector<Action> m_MigratedActions;
int32_t srcActionIndex; ActionContext m_SourceActionContext;
int32_t dstActionIndex; ActionContext m_DestinationActionContext;
}; };
#endif //!__MIGRATEACTIONSMESSAGE__H__ #endif //!__MIGRATEACTIONSMESSAGE__H__

View File

@ -1,9 +1,9 @@
#include "MoveToInventoryMessage.h" #include "MoveToInventoryMessage.h"
MoveToInventoryMessage::MoveToInventoryMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { MoveToInventoryMessage::MoveToInventoryMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } {
auto* behaviorIndexValue = arguments->Get<double>("BehaviorIndex"); const auto* const behaviorIndexValue = arguments->Get<double>("BehaviorIndex");
if (!behaviorIndexValue) return; if (!behaviorIndexValue) return;
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue()); m_BehaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetValue());
LOG_DEBUG("behaviorId %i behaviorIndex %i", behaviorId, behaviorIndex); LOG_DEBUG("behaviorId %i behaviorIndex %i", m_BehaviorId, m_BehaviorIndex);
} }

View File

@ -7,15 +7,15 @@ class AMFArrayValue;
/** /**
* @brief Sent when a player moves a Behavior A at position B to their inventory. * @brief Sent when a player moves a Behavior A at position B to their inventory.
*
*/ */
#pragma warning("This Control Behavior Message does not have a test yet. Non-developers can ignore this warning.") #pragma warning("This Control Behavior Message does not have a test yet. Non-developers can ignore this warning.")
class MoveToInventoryMessage : public BehaviorMessageBase { class MoveToInventoryMessage : public BehaviorMessageBase {
public: public:
MoveToInventoryMessage(AMFArrayValue* arguments); MoveToInventoryMessage(const AMFArrayValue* arguments);
const uint32_t GetBehaviorIndex() const { return behaviorIndex; }; [[nodiscard]] uint32_t GetBehaviorIndex() const noexcept { return m_BehaviorIndex; };
private: private:
uint32_t behaviorIndex; uint32_t m_BehaviorIndex;
}; };
#endif //!__MOVETOINVENTORYMESSAGE__H__ #endif //!__MOVETOINVENTORYMESSAGE__H__

View File

@ -1,10 +1,10 @@
#include "RearrangeStripMessage.h" #include "RearrangeStripMessage.h"
RearrangeStripMessage::RearrangeStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { RearrangeStripMessage::RearrangeStripMessage(const AMFArrayValue* arguments)
actionContext = ActionContext(arguments); : BehaviorMessageBase{ arguments }
srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") }
, m_DstActionIndex{ GetActionIndexFromArgument(arguments, "dstActionIndex") }
, m_ActionContext{ arguments } {
dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex"); LOG_DEBUG("srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", m_SrcActionIndex, m_DstActionIndex, m_ActionContext.GetStripId(), m_BehaviorId, m_ActionContext.GetStateId());
LOG_DEBUG("srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", srcActionIndex, dstActionIndex, actionContext.GetStripId(), behaviorId, actionContext.GetStateId());
} }

View File

@ -10,14 +10,17 @@
*/ */
class RearrangeStripMessage : public BehaviorMessageBase { class RearrangeStripMessage : public BehaviorMessageBase {
public: public:
RearrangeStripMessage(AMFArrayValue* arguments); RearrangeStripMessage(const AMFArrayValue* arguments);
int32_t GetSrcActionIndex() const { return srcActionIndex; };
int32_t GetDstActionIndex() const { return dstActionIndex; }; [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; }
ActionContext GetActionContext() const { return actionContext; }; [[nodiscard]] int32_t GetDstActionIndex() const noexcept { return m_DstActionIndex; }
[[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }
private: private:
ActionContext actionContext; int32_t m_SrcActionIndex;
int32_t srcActionIndex; int32_t m_DstActionIndex;
int32_t dstActionIndex; ActionContext m_ActionContext;
}; };
#endif //!__REARRANGESTRIPMESSAGE__H__ #endif //!__REARRANGESTRIPMESSAGE__H__

View File

@ -1,8 +1,9 @@
#include "RemoveActionsMessage.h" #include "RemoveActionsMessage.h"
RemoveActionsMessage::RemoveActionsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { RemoveActionsMessage::RemoveActionsMessage(const AMFArrayValue* arguments)
actionContext = ActionContext(arguments); : BehaviorMessageBase{ arguments }
actionIndex = GetActionIndexFromArgument(arguments); , m_ActionIndex{ GetActionIndexFromArgument(arguments) }
, m_ActionContext{ arguments } {
LOG_DEBUG("behaviorId %i actionIndex %i stripId %i stateId %i", behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId()); LOG_DEBUG("behaviorId %i actionIndex %i stripId %i stateId %i", m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId());
} }

View File

@ -12,12 +12,15 @@ class AMFArrayValue;
*/ */
class RemoveActionsMessage : public BehaviorMessageBase { class RemoveActionsMessage : public BehaviorMessageBase {
public: public:
RemoveActionsMessage(AMFArrayValue* arguments); RemoveActionsMessage(const AMFArrayValue* arguments);
int32_t GetActionIndex() const { return actionIndex; };
ActionContext GetActionContext() const { return actionContext; }; [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; }
[[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }
private: private:
ActionContext actionContext; int32_t m_ActionIndex;
int32_t actionIndex; ActionContext m_ActionContext;
}; };
#endif //!__REMOVEACTIONSMESSAGE__H__ #endif //!__REMOVEACTIONSMESSAGE__H__

View File

@ -1,7 +1,8 @@
#include "RemoveStripMessage.h" #include "RemoveStripMessage.h"
RemoveStripMessage::RemoveStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { RemoveStripMessage::RemoveStripMessage(const AMFArrayValue* arguments)
actionContext = ActionContext(arguments); : BehaviorMessageBase{ arguments }
, m_ActionContext{ arguments } {
LOG_DEBUG("stripId %i stateId %i behaviorId %i", actionContext.GetStripId(), actionContext.GetStateId(), behaviorId); LOG_DEBUG("stripId %i stateId %i behaviorId %i", m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId);
} }

View File

@ -10,10 +10,12 @@
*/ */
class RemoveStripMessage : public BehaviorMessageBase { class RemoveStripMessage : public BehaviorMessageBase {
public: public:
RemoveStripMessage(AMFArrayValue* arguments); RemoveStripMessage(const AMFArrayValue* arguments);
ActionContext GetActionContext() const { return actionContext; };
const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }
private: private:
ActionContext actionContext; ActionContext m_ActionContext;
}; };
#endif //!__REMOVESTRIPMESSAGE__H__ #endif //!__REMOVESTRIPMESSAGE__H__

View File

@ -1,9 +1,9 @@
#include "RenameMessage.h" #include "RenameMessage.h"
RenameMessage::RenameMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { RenameMessage::RenameMessage(const AMFArrayValue* arguments) : BehaviorMessageBase{ arguments } {
auto* nameAmf = arguments->Get<std::string>("Name"); const auto* const nameAmf = arguments->Get<std::string>("Name");
if (!nameAmf) return; if (!nameAmf) return;
name = nameAmf->GetValue(); m_Name = nameAmf->GetValue();
LOG_DEBUG("behaviorId %i n %s", behaviorId, name.c_str()); LOG_DEBUG("behaviorId %i n %s", m_BehaviorId, m_Name.c_str());
} }

View File

@ -7,14 +7,14 @@ class AMFArrayValue;
/** /**
* @brief Sent when a player renames this behavior * @brief Sent when a player renames this behavior
*
*/ */
class RenameMessage : public BehaviorMessageBase { class RenameMessage : public BehaviorMessageBase {
public: public:
RenameMessage(AMFArrayValue* arguments); RenameMessage(const AMFArrayValue* arguments);
const std::string& GetName() const { return name; }; [[nodiscard]] const std::string& GetName() const { return m_Name; };
private: private:
std::string name; std::string m_Name;
}; };
#endif //!__RENAMEMESSAGE__H__ #endif //!__RENAMEMESSAGE__H__

View File

@ -1,11 +1,11 @@
#include "SplitStripMessage.h" #include "SplitStripMessage.h"
SplitStripMessage::SplitStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { SplitStripMessage::SplitStripMessage(const AMFArrayValue* arguments)
sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID"); : BehaviorMessageBase{ arguments }
srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex"); , m_SrcActionIndex{ GetActionIndexFromArgument(arguments, "srcActionIndex") }
, m_SourceActionContext{ arguments, "srcStateID", "srcStripID" }
, m_DestinationActionContext{ arguments, "dstStateID", "dstStripID" }
, m_DestinationPosition{ arguments, "dstStripUI" } {
destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID"); LOG_DEBUG("behaviorId %i xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", m_BehaviorId, m_DestinationPosition.GetX(), m_DestinationPosition.GetY(), m_SourceActionContext.GetStripId(), m_DestinationActionContext.GetStripId(), m_SourceActionContext.GetStateId(), m_DestinationActionContext.GetStateId(), m_SrcActionIndex);
destinationPosition = StripUiPosition(arguments, "dstStripUI");
LOG_DEBUG("behaviorId %i xPosition %f yPosition %f sourceStrip %i destinationStrip %i sourceState %i destinationState %i srcActindex %i", behaviorId, destinationPosition.GetX(), destinationPosition.GetY(), sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), srcActionIndex);
} }

View File

@ -14,20 +14,27 @@ class AMFArrayValue;
*/ */
class SplitStripMessage : public BehaviorMessageBase { class SplitStripMessage : public BehaviorMessageBase {
public: public:
SplitStripMessage(AMFArrayValue* arguments); SplitStripMessage(const AMFArrayValue* arguments);
ActionContext GetSourceActionContext() const { return sourceActionContext; };
ActionContext GetDestinationActionContext() const { return destinationActionContext; };
int32_t GetSrcActionIndex() const { return srcActionIndex; };
StripUiPosition GetPosition() const { return destinationPosition; };
const std::vector<Action>& GetTransferredActions() const { return transferredActions; };
void SetTransferredActions(std::vector<Action>::const_iterator begin, std::vector<Action>::const_iterator end) { transferredActions.assign(begin, end); };
private:
ActionContext sourceActionContext;
ActionContext destinationActionContext;
int32_t srcActionIndex;
StripUiPosition destinationPosition;
std::vector<Action> transferredActions; [[nodiscard]] int32_t GetSrcActionIndex() const noexcept { return m_SrcActionIndex; }
[[nodiscard]] const ActionContext& GetSourceActionContext() const noexcept { return m_SourceActionContext; }
[[nodiscard]] const ActionContext& GetDestinationActionContext() const noexcept { return m_DestinationActionContext; }
[[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_DestinationPosition; }
[[nodiscard]] const std::vector<Action>& GetTransferredActions() const noexcept { return m_TransferredActions; }
void SetTransferredActions(std::vector<Action>::const_iterator begin, std::vector<Action>::const_iterator end) { m_TransferredActions.assign(begin, end); };
private:
int32_t m_SrcActionIndex;
ActionContext m_SourceActionContext;
ActionContext m_DestinationActionContext;
StripUiPosition m_DestinationPosition;
std::vector<Action> m_TransferredActions;
}; };
#endif //!__SPLITSTRIPMESSAGE__H__ #endif //!__SPLITSTRIPMESSAGE__H__

View File

@ -2,27 +2,22 @@
#include "Amf3.h" #include "Amf3.h"
StripUiPosition::StripUiPosition() { StripUiPosition::StripUiPosition(const AMFArrayValue* arguments, const std::string& uiKeyName) {
xPosition = 0.0; const auto* const uiArray = arguments->GetArray(uiKeyName);
yPosition = 0.0;
}
StripUiPosition::StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName) {
xPosition = 0.0;
yPosition = 0.0;
auto* uiArray = arguments->GetArray(uiKeyName);
if (!uiArray) return; if (!uiArray) return;
auto* xPositionValue = uiArray->Get<double>("x"); const auto* const xPositionValue = uiArray->Get<double>("x");
auto* yPositionValue = uiArray->Get<double>("y"); if (!xPositionValue) return;
if (!xPositionValue || !yPositionValue) return;
yPosition = yPositionValue->GetValue(); const auto* const yPositionValue = uiArray->Get<double>("y");
xPosition = xPositionValue->GetValue(); if (!yPositionValue) return;
m_YPosition = yPositionValue->GetValue();
m_XPosition = xPositionValue->GetValue();
} }
void StripUiPosition::SendBehaviorBlocksToClient(AMFArrayValue& args) const { void StripUiPosition::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
auto* uiArgs = args.InsertArray("ui"); auto* const uiArgs = args.InsertArray("ui");
uiArgs->Insert("x", xPosition); uiArgs->Insert("x", m_XPosition);
uiArgs->Insert("y", yPosition); uiArgs->Insert("y", m_YPosition);
} }

View File

@ -9,14 +9,15 @@ class AMFArrayValue;
*/ */
class StripUiPosition { class StripUiPosition {
public: public:
StripUiPosition(); StripUiPosition() noexcept = default;
StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName = "ui"); StripUiPosition(const AMFArrayValue* arguments, const std::string& uiKeyName = "ui");
void SendBehaviorBlocksToClient(AMFArrayValue& args) const; void SendBehaviorBlocksToClient(AMFArrayValue& args) const;
double GetX() const { return xPosition; }; [[nodiscard]] double GetX() const noexcept { return m_XPosition; }
double GetY() const { return yPosition; }; [[nodiscard]] double GetY() const noexcept { return m_YPosition; }
private: private:
double xPosition; double m_XPosition{ 0.0 };
double yPosition; double m_YPosition{ 0.0 };
}; };
#endif //!__STRIPUIPOSITION__H__ #endif //!__STRIPUIPOSITION__H__

View File

@ -2,14 +2,15 @@
#include "Action.h" #include "Action.h"
UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { UpdateActionMessage::UpdateActionMessage(const AMFArrayValue* arguments)
actionContext = ActionContext(arguments); : BehaviorMessageBase{ arguments }
, m_ActionIndex{ GetActionIndexFromArgument(arguments) }
, m_ActionContext{ arguments } {
auto* actionValue = arguments->GetArray("action"); const auto* const actionValue = arguments->GetArray("action");
if (!actionValue) return; if (!actionValue) return;
action = Action(actionValue); m_Action = Action{ actionValue };
actionIndex = GetActionIndexFromArgument(arguments);
LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId()); LOG_DEBUG("type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", m_Action.GetType().c_str(), m_Action.GetValueParameterName().c_str(), m_Action.GetValueParameterString().c_str(), m_Action.GetValueParameterDouble(), m_BehaviorId, m_ActionIndex, m_ActionContext.GetStripId(), m_ActionContext.GetStateId());
} }

View File

@ -13,14 +13,18 @@ class AMFArrayValue;
*/ */
class UpdateActionMessage : public BehaviorMessageBase { class UpdateActionMessage : public BehaviorMessageBase {
public: public:
UpdateActionMessage(AMFArrayValue* arguments); UpdateActionMessage(const AMFArrayValue* arguments);
int32_t GetActionIndex() const { return actionIndex; };
ActionContext GetActionContext() const { return actionContext; }; [[nodiscard]] int32_t GetActionIndex() const noexcept { return m_ActionIndex; }
Action GetAction() const { return action; };
[[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; }
[[nodiscard]] const Action& GetAction() const noexcept { return m_Action; }
private: private:
int32_t actionIndex; int32_t m_ActionIndex;
ActionContext actionContext; ActionContext m_ActionContext;
Action action; Action m_Action;
}; };
#endif //!__UPDATEACTIONMESSAGE__H__ #endif //!__UPDATEACTIONMESSAGE__H__

View File

@ -1,8 +1,9 @@
#include "UpdateStripUiMessage.h" #include "UpdateStripUiMessage.h"
UpdateStripUiMessage::UpdateStripUiMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { UpdateStripUiMessage::UpdateStripUiMessage(const AMFArrayValue* arguments)
position = StripUiPosition(arguments); : BehaviorMessageBase{ arguments }
actionContext = ActionContext(arguments); , m_Position{ arguments }
, m_ActionContext{ arguments } {
LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId); LOG_DEBUG("xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", m_Position.GetX(), m_Position.GetY(), m_ActionContext.GetStripId(), m_ActionContext.GetStateId(), m_BehaviorId);
} }

View File

@ -13,12 +13,15 @@ class AMFArrayValue;
*/ */
class UpdateStripUiMessage : public BehaviorMessageBase { class UpdateStripUiMessage : public BehaviorMessageBase {
public: public:
UpdateStripUiMessage(AMFArrayValue* arguments); UpdateStripUiMessage(const AMFArrayValue* arguments);
StripUiPosition GetPosition() const { return position; };
ActionContext GetActionContext() const { return actionContext; }; [[nodiscard]] const StripUiPosition& GetPosition() const noexcept { return m_Position; };
[[nodiscard]] const ActionContext& GetActionContext() const noexcept { return m_ActionContext; };
private: private:
StripUiPosition position; StripUiPosition m_Position;
ActionContext actionContext; ActionContext m_ActionContext;
}; };
#endif //!__UPDATESTRIPUIMESSAGE__H__ #endif //!__UPDATESTRIPUIMESSAGE__H__

View File

@ -63,7 +63,7 @@ void ControlBehaviors::SendBehaviorListToClient(const ControlBehaviorContext& co
// TODO This is also supposed to serialize the state of the behaviors in progress but those aren't implemented yet // TODO This is also supposed to serialize the state of the behaviors in progress but those aren't implemented yet
void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& context) { void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& context) {
if (!context) return; if (!context) return;
BehaviorMessageBase behaviorMsg(context.arguments); BehaviorMessageBase behaviorMsg{ context.arguments };
context.modelComponent->VerifyBehaviors(); context.modelComponent->VerifyBehaviors();
AMFArrayValue behavior; AMFArrayValue behavior;
@ -71,8 +71,8 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& contex
GameMessages::SendUIMessageServerToSingleClient(context.modelOwner, context.modelOwner->GetSystemAddress(), "UpdateBehaviorBlocks", behavior); GameMessages::SendUIMessageServerToSingleClient(context.modelOwner, context.modelOwner->GetSystemAddress(), "UpdateBehaviorBlocks", behavior);
} }
void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) { void ControlBehaviors::UpdateAction(const AMFArrayValue* arguments) {
UpdateActionMessage updateActionMessage(arguments); UpdateActionMessage updateActionMessage{ arguments };
auto blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType()); auto blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType());
if (!blockDefinition) { if (!blockDefinition) {
@ -95,18 +95,18 @@ void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) {
} }
} }
void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress& sysAddr, AMFArrayValue* arguments, std::string command, Entity* modelOwner) { void ControlBehaviors::ProcessCommand(Entity* modelEntity, AMFArrayValue* arguments, std::string& command, Entity* modelOwner) {
if (!isInitialized || !modelEntity || !modelOwner || !arguments) return; if (!isInitialized || !modelEntity || !modelOwner || !arguments) return;
auto* modelComponent = modelEntity->GetComponent<ModelComponent>(); auto* const modelComponent = modelEntity->GetComponent<ModelComponent>();
if (!modelComponent) return; if (!modelComponent) return;
ControlBehaviorContext context(arguments, modelComponent, modelOwner); ControlBehaviorContext context{ arguments, modelComponent, modelOwner };
if (command == "sendBehaviorListToClient") { if (command == "sendBehaviorListToClient") {
SendBehaviorListToClient(context); SendBehaviorListToClient(context);
} else if (command == "modelTypeChanged") { } else if (command == "modelTypeChanged") {
auto* modelType = arguments->Get<double>("ModelType"); auto* const modelType = arguments->Get<double>("ModelType");
if (!modelType) return; if (!modelType) return;
modelEntity->SetVar<int>(u"modelType", modelType->GetValue()); modelEntity->SetVar<int>(u"modelType", modelType->GetValue());
@ -131,7 +131,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress&
} else if (command == "rearrangeStrip") { } else if (command == "rearrangeStrip") {
context.modelComponent->HandleControlBehaviorsMsg<RearrangeStripMessage>(arguments); context.modelComponent->HandleControlBehaviorsMsg<RearrangeStripMessage>(arguments);
} else if (command == "add") { } else if (command == "add") {
AddMessage msg(context.arguments); AddMessage msg{ context.arguments };
context.modelComponent->AddBehavior(msg); context.modelComponent->AddBehavior(msg);
SendBehaviorListToClient(context); SendBehaviorListToClient(context);
} else if (command == "removeActions") { } else if (command == "removeActions") {
@ -144,7 +144,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress&
} else if (command == "sendBehaviorBlocksToClient") { } else if (command == "sendBehaviorBlocksToClient") {
SendBehaviorBlocksToClient(context); SendBehaviorBlocksToClient(context);
} else if (command == "moveToInventory") { } else if (command == "moveToInventory") {
MoveToInventoryMessage msg(arguments); MoveToInventoryMessage msg{ arguments };
context.modelComponent->MoveToInventory(msg); context.modelComponent->MoveToInventory(msg);
auto* characterComponent = modelOwner->GetComponent<CharacterComponent>(); auto* characterComponent = modelOwner->GetComponent<CharacterComponent>();
if (!characterComponent) return; if (!characterComponent) return;
@ -239,7 +239,7 @@ ControlBehaviors::ControlBehaviors() {
if (values) { if (values) {
auto* value = values->FirstChildElement("Value"); auto* value = values->FirstChildElement("Value");
while (value) { while (value) {
if (value->GetText() == blockDefinition.GetDefaultValue()) blockDefinition.GetDefaultValue() = std::to_string(blockDefinition.GetMaximumValue()); if (value->GetText() == blockDefinition.GetDefaultValue()) blockDefinition.SetDefaultValue(std::to_string(blockDefinition.GetMaximumValue()));
blockDefinition.SetMaximumValue(blockDefinition.GetMaximumValue() + 1); blockDefinition.SetMaximumValue(blockDefinition.GetMaximumValue() + 1);
value = value->NextSiblingElement("Value"); value = value->NextSiblingElement("Value");
} }
@ -283,7 +283,7 @@ ControlBehaviors::ControlBehaviors() {
} }
} }
std::optional<BlockDefinition> ControlBehaviors::GetBlockInfo(const BlockName& blockName) { std::optional<BlockDefinition> ControlBehaviors::GetBlockInfo(const std::string& blockName) {
auto blockDefinition = blockTypes.find(blockName); auto blockDefinition = blockTypes.find(blockName);
return blockDefinition != blockTypes.end() ? std::optional(blockDefinition->second) : std::nullopt; return blockDefinition != blockTypes.end() ? std::optional(blockDefinition->second) : std::nullopt;
} }

View File

@ -19,15 +19,17 @@ class SystemAddress;
typedef std::string BlockName; //! A block name typedef std::string BlockName; //! A block name
struct ControlBehaviorContext { struct ControlBehaviorContext {
ControlBehaviorContext(AMFArrayValue* args, ModelComponent* modelComponent, Entity* modelOwner) : arguments(args), modelComponent(modelComponent), modelOwner(modelOwner) {}; ControlBehaviorContext(AMFArrayValue* args, ModelComponent* modelComponent, Entity* modelOwner) noexcept
: arguments{ args }, modelComponent{ modelComponent }, modelOwner{ modelOwner } {
};
operator bool() const { operator bool() const {
return arguments != nullptr && modelComponent != nullptr && modelOwner != nullptr; return arguments != nullptr && modelComponent != nullptr && modelOwner != nullptr;
} }
AMFArrayValue* arguments; AMFArrayValue* arguments;
Entity* modelOwner;
ModelComponent* modelComponent; ModelComponent* modelComponent;
Entity* modelOwner;
}; };
class ControlBehaviors: public Singleton<ControlBehaviors> { class ControlBehaviors: public Singleton<ControlBehaviors> {
@ -37,12 +39,11 @@ public:
* @brief Main driver for processing Property Behavior commands * @brief Main driver for processing Property Behavior commands
* *
* @param modelEntity The model that sent this command * @param modelEntity The model that sent this command
* @param sysAddr The SystemAddress to respond to
* @param arguments The arguments formatted as an AMFArrayValue * @param arguments The arguments formatted as an AMFArrayValue
* @param command The command to perform * @param command The command to perform
* @param modelOwner The owner of the model which sent this command * @param modelOwner The owner of the model which sent this command
*/ */
void ProcessCommand(Entity* modelEntity, const SystemAddress& sysAddr, AMFArrayValue* arguments, std::string command, Entity* modelOwner); void ProcessCommand(Entity* modelEntity, AMFArrayValue* arguments, std::string& command, Entity* modelOwner);
/** /**
* @brief Gets a blocks parameter values by the name * @brief Gets a blocks parameter values by the name
@ -52,13 +53,13 @@ public:
* *
* @return A pair of the block parameter name to its typing * @return A pair of the block parameter name to its typing
*/ */
std::optional<BlockDefinition> GetBlockInfo(const BlockName& blockName); [[nodiscard]] std::optional<BlockDefinition> GetBlockInfo(const std::string& blockName);
private: private:
void RequestUpdatedID(ControlBehaviorContext& context); void RequestUpdatedID(ControlBehaviorContext& context);
void SendBehaviorListToClient(const ControlBehaviorContext& context); void SendBehaviorListToClient(const ControlBehaviorContext& context);
void SendBehaviorBlocksToClient(ControlBehaviorContext& context); void SendBehaviorBlocksToClient(ControlBehaviorContext& context);
void UpdateAction(AMFArrayValue* arguments); void UpdateAction(const AMFArrayValue* arguments);
std::map<BlockName, BlockDefinition> blockTypes{}; std::map<BlockName, BlockDefinition, std::less<>> blockTypes{};
// If false, property behaviors will not be able to be edited. // If false, property behaviors will not be able to be edited.
bool isInitialized = false; bool isInitialized = false;

View File

@ -83,10 +83,6 @@ void PropertyBehavior::HandleMsg(AddMessage& msg) {
isLoot = m_BehaviorId != 7965; isLoot = m_BehaviorId != 7965;
}; };
void PropertyBehavior::SetBehaviorId(int32_t behaviorId) {
m_BehaviorId = behaviorId;
}
void PropertyBehavior::SendBehaviorListToClient(AMFArrayValue& args) const { void PropertyBehavior::SendBehaviorListToClient(AMFArrayValue& args) const {
args.Insert("id", std::to_string(m_BehaviorId)); args.Insert("id", std::to_string(m_BehaviorId));
args.Insert("name", m_Name); args.Insert("name", m_Name);
@ -111,19 +107,18 @@ void PropertyBehavior::VerifyLastEditedState() {
} }
void PropertyBehavior::SendBehaviorBlocksToClient(AMFArrayValue& args) const { void PropertyBehavior::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
auto* stateArray = args.InsertArray("states"); auto* const stateArray = args.InsertArray("states");
auto lastState = BehaviorState::HOME_STATE; for (const auto& [stateId, state] : m_States) {
for (auto& [stateId, state] : m_States) {
if (state.IsEmpty()) continue; if (state.IsEmpty()) continue;
LOG_DEBUG("Serializing state %i", stateId); LOG_DEBUG("Serializing state %i", stateId);
auto* stateArgs = stateArray->PushArray(); auto* const stateArgs = stateArray->PushArray();
stateArgs->Insert("id", static_cast<double>(stateId)); stateArgs->Insert("id", static_cast<double>(stateId));
state.SendBehaviorBlocksToClient(*stateArgs); state.SendBehaviorBlocksToClient(*stateArgs);
} }
auto* executionState = args.InsertArray("executionState"); auto* const executionState = args.InsertArray("executionState");
executionState->Insert("stateID", static_cast<double>(m_LastEditedState)); executionState->Insert("stateID", static_cast<double>(m_LastEditedState));
executionState->InsertArray("strips"); executionState->InsertArray("strips");

View File

@ -13,6 +13,7 @@ class AMFArrayValue;
class PropertyBehavior { class PropertyBehavior {
public: public:
PropertyBehavior(); PropertyBehavior();
template <typename Msg> template <typename Msg>
void HandleMsg(Msg& msg); void HandleMsg(Msg& msg);
@ -21,8 +22,9 @@ public:
void SendBehaviorListToClient(AMFArrayValue& args) const; void SendBehaviorListToClient(AMFArrayValue& args) const;
void SendBehaviorBlocksToClient(AMFArrayValue& args) const; void SendBehaviorBlocksToClient(AMFArrayValue& args) const;
int32_t GetBehaviorId() const { return m_BehaviorId; } [[nodiscard]] int32_t GetBehaviorId() const noexcept { return m_BehaviorId; }
void SetBehaviorId(int32_t id); void SetBehaviorId(int32_t id) noexcept { m_BehaviorId = id; }
private: private:
// The states this behavior has. // The states this behavior has.

View File

@ -117,19 +117,19 @@ void State::HandleMsg(MigrateActionsMessage& msg) {
}; };
bool State::IsEmpty() const { bool State::IsEmpty() const {
for (auto& strip : m_Strips) { for (const auto& strip : m_Strips) {
if (!strip.IsEmpty()) return false; if (!strip.IsEmpty()) return false;
} }
return true; return true;
} }
void State::SendBehaviorBlocksToClient(AMFArrayValue& args) const { void State::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
auto* strips = args.InsertArray("strips"); auto* const strips = args.InsertArray("strips");
for (int32_t stripId = 0; stripId < m_Strips.size(); stripId++) { for (size_t stripId = 0; stripId < m_Strips.size(); ++stripId) {
auto& strip = m_Strips.at(stripId); const auto& strip = m_Strips.at(stripId);
if (strip.IsEmpty()) continue; if (strip.IsEmpty()) continue;
auto* stripArgs = strips->PushArray(); auto* const stripArgs = strips->PushArray();
stripArgs->Insert("id", static_cast<double>(stripId)); stripArgs->Insert("id", static_cast<double>(stripId));
strip.SendBehaviorBlocksToClient(*stripArgs); strip.SendBehaviorBlocksToClient(*stripArgs);

View File

@ -12,6 +12,7 @@ public:
void SendBehaviorBlocksToClient(AMFArrayValue& args) const; void SendBehaviorBlocksToClient(AMFArrayValue& args) const;
bool IsEmpty() const; bool IsEmpty() const;
private: private:
std::vector<Strip> m_Strips; std::vector<Strip> m_Strips;
}; };

View File

@ -12,7 +12,6 @@ void Strip::HandleMsg(AddStripMessage& msg) {
template <> template <>
void Strip::HandleMsg(AddActionMessage& msg) { void Strip::HandleMsg(AddActionMessage& msg) {
if (msg.GetActionIndex() == -1) return; if (msg.GetActionIndex() == -1) return;
m_Actions.insert(m_Actions.begin() + msg.GetActionIndex(), msg.GetAction()); m_Actions.insert(m_Actions.begin() + msg.GetActionIndex(), msg.GetAction());
}; };
@ -80,8 +79,8 @@ void Strip::HandleMsg(MigrateActionsMessage& msg) {
void Strip::SendBehaviorBlocksToClient(AMFArrayValue& args) const { void Strip::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
m_Position.SendBehaviorBlocksToClient(args); m_Position.SendBehaviorBlocksToClient(args);
auto* actions = args.InsertArray("actions"); auto* const actions = args.InsertArray("actions");
for (auto& action : m_Actions) { for (const auto& action : m_Actions) {
action.SendBehaviorBlocksToClient(*actions); action.SendBehaviorBlocksToClient(*actions);
} }
}; };

View File

@ -14,7 +14,8 @@ public:
void HandleMsg(Msg& msg); void HandleMsg(Msg& msg);
void SendBehaviorBlocksToClient(AMFArrayValue& args) const; void SendBehaviorBlocksToClient(AMFArrayValue& args) const;
bool IsEmpty() const { return m_Actions.empty(); } bool IsEmpty() const noexcept { return m_Actions.empty(); }
private: private:
std::vector<Action> m_Actions; std::vector<Action> m_Actions;
StripUiPosition m_Position; StripUiPosition m_Position;