Make ControlBehavior messages far more modular (#991)

* Make case consistent

* How modular can you go?

Holy modular

* Add comments

* Initialize values
This commit is contained in:
David Markowitz 2023-02-16 09:30:33 -08:00 committed by GitHub
parent 484488e47d
commit d138b7b878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 461 additions and 438 deletions

View File

@ -0,0 +1,31 @@
#include "Action.h"
Action::Action() {
type = "";
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
}
Action::Action(AMFArrayValue* arguments) {
type = "";
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
for (auto& typeValueMap : arguments->GetAssociativeMap()) {
if (typeValueMap.first == "Type") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
type = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
valueParameterName = typeValueMap.first;
// Message is the only known string parameter
if (valueParameterName == "Message") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
valueParameterString = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue;
valueParameterDouble = static_cast<AMFDoubleValue*>(typeValueMap.second)->GetDoubleValue();
}
}
}
}

View File

@ -0,0 +1,25 @@
#ifndef __ACTION__H__
#define __ACTION__H__
#include "BehaviorMessageBase.h"
/**
* @brief Sent if a ControlBehavior message has an Action associated with it
*
*/
class Action {
public:
Action();
Action(AMFArrayValue* arguments);
const std::string& GetType() { return type; };
const std::string& GetValueParameterName() { return valueParameterName; };
const std::string& GetValueParameterString() { return valueParameterString; };
const double GetValueParameterDouble() { return valueParameterDouble; };
private:
std::string type;
std::string valueParameterName;
std::string valueParameterString;
double valueParameterDouble;
};
#endif //!__ACTION__H__

View File

@ -0,0 +1,31 @@
#include "ActionContext.h"
#include <stdexcept>
#include "AMFFormat.h"
ActionContext::ActionContext() {
stripId = 0;
stateId = BehaviorState::HOME_STATE;
}
ActionContext::ActionContext(AMFArrayValue* arguments, std::string customStateKey, std::string customStripKey) {
stripId = 0;
stateId = BehaviorState::HOME_STATE;
stripId = GetStripIdFromArgument(arguments, customStripKey);
stateId = GetBehaviorStateFromArgument(arguments, customStateKey);
}
BehaviorState ActionContext::GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key) {
auto* stateIDValue = arguments->FindValue<AMFDoubleValue>(key);
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\"");
return static_cast<BehaviorState>(stateIDValue->GetDoubleValue());
}
StripId ActionContext::GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key) {
auto* stripIdValue = arguments->FindValue<AMFDoubleValue>(key);
if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\"");
return static_cast<StripId>(stripIdValue->GetDoubleValue());
}

View File

@ -0,0 +1,26 @@
#ifndef __ACTIONCONTEXT__H__
#define __ACTIONCONTEXT__H__
#include "BehaviorStates.h"
#include "dCommonVars.h"
class AMFArrayValue;
/**
* @brief Sent if contextual State and Strip informationis needed for a ControlBehaviors message
*
*/
class ActionContext {
public:
ActionContext();
ActionContext(AMFArrayValue* arguments, std::string customStateKey = "stateID", std::string customStripKey = "stripID");
const StripId GetStripId() { return stripId; };
const BehaviorState GetStateId() { return stateId; };
private:
BehaviorState GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key);
StripId GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key);
StripId stripId;
BehaviorState stateId;
};
#endif //!__ACTIONCONTEXT__H__

View File

@ -1,39 +1,13 @@
#include "AddActionMessage.h" #include "AddActionMessage.h"
AddActionMessage::AddActionMessage(AMFArrayValue* arguments) { AddActionMessage::AddActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
auto* actionIndexAmf = arguments->FindValue<AMFDoubleValue>("actionIndex"); actionContext = ActionContext(arguments);
if (!actionIndexAmf) return; actionIndex = GetActionIndexFromArgument(arguments);
actionIndex = static_cast<uint32_t>(actionIndexAmf->GetDoubleValue()); auto* actionValue = arguments->FindValue<AMFArrayValue>("action");
if (!actionValue) return;
stripId = GetStripIDFromArgument(arguments); action = Action(actionValue);
stateId = GetBehaviorStateFromArgument(arguments); Game::logger->LogDebug("AddActionMessage", "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);
type = "";
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
auto* action = arguments->FindValue<AMFArrayValue>("action");
if (!action) return;
for (auto& typeValueMap : action->GetAssociativeMap()) {
if (typeValueMap.first == "Type") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
type = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
valueParameterName = typeValueMap.first;
// Message is the only known string parameter
if (valueParameterName == "Message") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
valueParameterString = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue;
valueParameterDouble = static_cast<AMFDoubleValue*>(typeValueMap.second)->GetDoubleValue();
}
}
}
behaviorId = GetBehaviorIDFromArgument(arguments);
Game::logger->LogDebug("AddActionMessage", "acnNdx %i stpId %i sttId %i t %s vpn %s vps %s vpd %f bhId %i", actionIndex, stripId, stateId, type.c_str(), valueParameterName.c_str(), valueParameterString.c_str(), valueParameterDouble, behaviorId);
} }

View File

@ -1,30 +1,26 @@
#ifndef __ADDACTIONMESSAGE__H__ #ifndef __ADDACTIONMESSAGE__H__
#define __ADDACTIONMESSAGE__H__ #define __ADDACTIONMESSAGE__H__
#include "Action.h"
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Send if a player takes an Action A from the toolbox and adds it to an already existing strip
*
*/
class AddActionMessage : public BehaviorMessageBase { class AddActionMessage : public BehaviorMessageBase {
public: public:
AddActionMessage(AMFArrayValue* arguments); AddActionMessage(AMFArrayValue* arguments);
const uint32_t GetActionIndex() { return actionIndex; }; const uint32_t GetActionIndex() { return actionIndex; };
const StripId GetStripId() { return stripId; }; Action GetAction() { return action; };
const BehaviorState GetStateId() { return stateId; }; ActionContext GetActionContext() { return actionContext; };
const std::string& GetType() { return type; };
const std::string& GetValueParameterName() { return valueParameterName; };
const std::string& GetValueParameterString() { return valueParameterString; };
const double GetValueParameterDouble() { return valueParameterDouble; };
const uint32_t GetBehaviorId() { return behaviorId; };
private: private:
uint32_t actionIndex; uint32_t actionIndex;
StripId stripId; ActionContext actionContext;
BehaviorState stateId; Action action;
std::string type;
std::string valueParameterName;
std::string valueParameterString;
double valueParameterDouble;
uint32_t behaviorId;
}; };
#endif //!__ADDACTIONMESSAGE__H__ #endif //!__ADDACTIONMESSAGE__H__

View File

@ -1,13 +1,11 @@
#include "AddMessage.h" #include "AddMessage.h"
AddMessage::AddMessage(AMFArrayValue* arguments) { AddMessage::AddMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
behaviorId = GetBehaviorIDFromArgument(arguments);
behaviorIndex = 0; behaviorIndex = 0;
auto* behaviorIndexValue = arguments->FindValue<AMFDoubleValue>("BehaviorIndex"); auto* behaviorIndexValue = arguments->FindValue<AMFDoubleValue>("BehaviorIndex");
if (!behaviorIndexValue) return; if (!behaviorIndexValue) return;
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetDoubleValue()); behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetDoubleValue());
Game::logger->LogDebug("AddMessage", "bhId %i ndx %i", behaviorId, behaviorIndex); Game::logger->LogDebug("AddMessage", "behaviorId %i index %i", behaviorId, behaviorIndex);
} }

View File

@ -3,13 +3,15 @@
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
/**
* @brief Sent when a player adds a Behavior A from their inventory to a model.
*
*/
class AddMessage : public BehaviorMessageBase { class AddMessage : public BehaviorMessageBase {
public: public:
AddMessage(AMFArrayValue* arguments); AddMessage(AMFArrayValue* arguments);
const uint32_t GetBehaviorIndex() { return behaviorIndex; }; const uint32_t GetBehaviorIndex() { return behaviorIndex; };
const uint32_t GetBehaviorId() { return behaviorId; };
private: private:
uint32_t behaviorId;
uint32_t behaviorIndex; uint32_t behaviorIndex;
}; };

View File

@ -1,56 +1,25 @@
#include "AddStripMessage.h" #include "AddStripMessage.h"
AddStripMessage::AddStripMessage(AMFArrayValue* arguments) { #include "Action.h"
AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
actionContext = ActionContext(arguments);
position = StripUiPosition(arguments);
auto* strip = arguments->FindValue<AMFArrayValue>("strip"); auto* strip = arguments->FindValue<AMFArrayValue>("strip");
if (!strip) return; if (!strip) return;
auto* actions = strip->FindValue<AMFArrayValue>("actions"); auto* actions = strip->FindValue<AMFArrayValue>("actions");
if (!actions) return; if (!actions) return;
auto* uiArray = arguments->FindValue<AMFArrayValue>("ui"); for (uint32_t actionNumber = 0; actionNumber < actions->GetDenseValueSize(); actionNumber++) {
if (!uiArray) return; auto* actionValue = actions->GetValueAt<AMFArrayValue>(actionNumber);
if (!actionValue) continue;
auto* xPositionValue = uiArray->FindValue<AMFDoubleValue>("x"); actionsToAdd.push_back(Action(actionValue));
if (!xPositionValue) return;
xPosition = xPositionValue->GetDoubleValue(); Game::logger->LogDebug("AddStripMessage", "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());
auto* yPositionValue = uiArray->FindValue<AMFDoubleValue>("y");
if (!yPositionValue) return;
yPosition = yPositionValue->GetDoubleValue();
stripId = GetStripIDFromArgument(arguments);
stateId = GetBehaviorStateFromArgument(arguments);
behaviorId = GetBehaviorIDFromArgument(arguments);
type = "";
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
for (uint32_t position = 0; position < actions->GetDenseValueSize(); position++) {
auto* actionAsArray = actions->GetValueAt<AMFArrayValue>(position);
if (!actionAsArray) continue;
for (auto& typeValueMap : actionAsArray->GetAssociativeMap()) {
if (typeValueMap.first == "Type") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
type = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
valueParameterName = typeValueMap.first;
// Message is the only known string parameter
if (valueParameterName == "Message") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
valueParameterString = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue;
valueParameterDouble = static_cast<AMFDoubleValue*>(typeValueMap.second)->GetDoubleValue();
}
}
}
Game::logger->LogDebug("AddStripMessage", "x %f y %f stpId %i sttId %i bhId %i t %s vpn %s vps %s vpd %f", xPosition, yPosition, stripId, stateId, behaviorId, type.c_str(), valueParameterName.c_str(), valueParameterString.c_str(), valueParameterDouble);
} }
Game::logger->Log("AddStripMessage", "number of actions %i", actionsToAdd.size());
} }

View File

@ -1,32 +1,31 @@
#ifndef __ADDSTRIPMESSAGE__H__ #ifndef __ADDSTRIPMESSAGE__H__
#define __ADDSTRIPMESSAGE__H__ #define __ADDSTRIPMESSAGE__H__
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
#include "StripUiPosition.h"
#include <vector>
class Action;
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Sent in 2 contexts:
* A player adds an Action A from their toolbox without attaching it to an existing Strip. In this case, only 1 action is sent.
* A player moves a Strip from BehaviorState A directly to BehaviorState B. In this case, a list of actions are sent.
*
*/
class AddStripMessage : public BehaviorMessageBase { class AddStripMessage : public BehaviorMessageBase {
public: public:
AddStripMessage(AMFArrayValue* arguments); AddStripMessage(AMFArrayValue* arguments);
const StripId GetStripId() { return stripId; }; StripUiPosition GetPosition() { return position; };
const BehaviorState GetStateId() { return stateId; }; ActionContext GetActionContext() { return actionContext; };
const std::string& GetType() { return type; }; std::vector<Action> GetActionsToAdd() { return actionsToAdd; };
const std::string& GetValueParameterName() { return valueParameterName; };
const std::string& GetValueParameterString() { return valueParameterString; };
const double GetXPosition() { return xPosition; };
const double GetYPosition() { return yPosition; };
const double GetValueParameterDouble() { return valueParameterDouble; };
const uint32_t GetBehaviorId() { return behaviorId; };
private: private:
double xPosition; StripUiPosition position;
double yPosition; ActionContext actionContext;
StripId stripId; std::vector<Action> actionsToAdd;
BehaviorState stateId;
uint32_t behaviorId;
std::string type;
std::string valueParameterName;
std::string valueParameterString;
double valueParameterDouble;
}; };
#endif //!__ADDSTRIPMESSAGE__H__ #endif //!__ADDSTRIPMESSAGE__H__

View File

@ -0,0 +1,33 @@
#include "BehaviorMessageBase.h"
#include "AMFFormat.h"
#include "BehaviorStates.h"
#include "dCommonVars.h"
BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) {
behaviorId = 0;
behaviorId = GetBehaviorIdFromArgument(arguments);
}
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) {
const auto* key = "BehaviorID";
auto* behaviorIDValue = arguments->FindValue<AMFStringValue>(key);
int32_t behaviorID = -1;
if (behaviorIDValue) {
behaviorID = std::stoul(behaviorIDValue->GetStringValue());
} else if (!arguments->FindValue<AMFUndefinedValue>(key)) {
throw std::invalid_argument("Unable to find behavior ID");
}
return behaviorID;
}
uint32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) {
auto* actionIndexAmf = arguments->FindValue<AMFDoubleValue>(keyName);
if (!actionIndexAmf) {
throw std::invalid_argument("Unable to find actionIndex");
}
return static_cast<uint32_t>(actionIndexAmf->GetDoubleValue());
}

View File

@ -5,44 +5,25 @@
#include <string> #include <string>
#include "AMFFormat.h" #include "AMFFormat.h"
#include "BehaviorStates.h"
#include "dCommonVars.h" #include "dCommonVars.h"
#include "Game.h" #include "Game.h"
#include "dLogger.h" #include "dLogger.h"
enum class BehaviorState : uint32_t;
/**
* @brief The behaviorID target of this ControlBehaviors message
*
*/
class BehaviorMessageBase { class BehaviorMessageBase {
public: public:
uint32_t GetBehaviorIDFromArgument(AMFArrayValue* arguments, const std::string& key = "BehaviorID") { const uint32_t GetBehaviorId() { return behaviorId; };
auto* behaviorIDValue = arguments->FindValue<AMFStringValue>(key); protected:
uint32_t behaviorID = -1; BehaviorMessageBase(AMFArrayValue* arguments);
int32_t GetBehaviorIdFromArgument(AMFArrayValue* arguments);
if (behaviorIDValue) { uint32_t GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName = "actionIndex");
behaviorID = std::stoul(behaviorIDValue->GetStringValue()); int32_t behaviorId = -1;
} else if (arguments->FindValue<AMFUndefinedValue>(key) == nullptr) {
throw std::invalid_argument("Unable to find behavior ID from argument \"" + key + "\"");
}
return behaviorID;
}
BehaviorState GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key = "stateID") {
auto* stateIDValue = arguments->FindValue<AMFDoubleValue>(key);
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\"");
BehaviorState stateID = static_cast<BehaviorState>(stateIDValue->GetDoubleValue());
return stateID;
}
StripId GetStripIDFromArgument(AMFArrayValue* arguments, const std::string& key = "stripID") {
auto* stripIDValue = arguments->FindValue<AMFDoubleValue>(key);
if (!stripIDValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\"");
StripId stripID = static_cast<StripId>(stripIDValue->GetDoubleValue());
return stripID;
}
}; };
#endif //!__BEHAVIORMESSAGEBASE__H__ #endif //!__BEHAVIORMESSAGEBASE__H__

View File

@ -1,7 +1,10 @@
set(DGAME_DPROPERTYBEHAVIORS_CONTROLBEHAVIORMESSAGES set(DGAME_DPROPERTYBEHAVIORS_CONTROLBEHAVIORMESSAGES
"Action.cpp"
"ActionContext.cpp"
"AddActionMessage.cpp" "AddActionMessage.cpp"
"AddMessage.cpp" "AddMessage.cpp"
"AddStripMessage.cpp" "AddStripMessage.cpp"
"BehaviorMessageBase.cpp"
"MergeStripsMessage.cpp" "MergeStripsMessage.cpp"
"MigrateActionsMessage.cpp" "MigrateActionsMessage.cpp"
"MoveToInventoryMessage.cpp" "MoveToInventoryMessage.cpp"
@ -10,6 +13,7 @@ set(DGAME_DPROPERTYBEHAVIORS_CONTROLBEHAVIORMESSAGES
"RemoveStripMessage.cpp" "RemoveStripMessage.cpp"
"RenameMessage.cpp" "RenameMessage.cpp"
"SplitStripMessage.cpp" "SplitStripMessage.cpp"
"StripUiPosition.cpp"
"UpdateActionMessage.cpp" "UpdateActionMessage.cpp"
"UpdateStripUiMessage.cpp" "UpdateStripUiMessage.cpp"
PARENT_SCOPE PARENT_SCOPE

View File

@ -1,20 +1,11 @@
#include "MergeStripsMessage.h" #include "MergeStripsMessage.h"
MergeStripsMessage::MergeStripsMessage(AMFArrayValue* arguments) { MergeStripsMessage::MergeStripsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
srcStripID = GetStripIDFromArgument(arguments, "srcStripID"); sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID");
dstStateID = GetBehaviorStateFromArgument(arguments, "dstStateID"); destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID");
dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex");
srcStateID = GetBehaviorStateFromArgument(arguments, "srcStateID"); Game::logger->LogDebug("MergeStripsMessage", "srcstripId %i dststripId %i srcstateId %i dststateId %i dstactionIndex %i behaviorId %i", sourceActionContext.GetStripId(), destinationActionContext.GetStripId(), sourceActionContext.GetStateId(), destinationActionContext.GetStateId(), dstActionIndex, behaviorId);
auto* dstActionIndexValue = arguments->FindValue<AMFDoubleValue>("dstActionIndex");
if (!dstActionIndexValue) return;
dstActionIndex = static_cast<uint32_t>(dstActionIndexValue->GetDoubleValue());
dstStripID = GetStripIDFromArgument(arguments, "dstStripID");
behaviorID = GetBehaviorIDFromArgument(arguments);
Game::logger->LogDebug("MergeStripsMessage", "srcStpId %i dstStpId %i srcSttId %i dstSttId %i dstAcnNdx %i bhId %i", srcStripID, dstStripID, srcStateID, dstStateID, dstActionIndex, behaviorID);
} }

View File

@ -1,26 +1,25 @@
#ifndef __MERGESTRIPSMESSAGE__H__ #ifndef __MERGESTRIPSMESSAGE__H__
#define __MERGESTRIPSMESSAGE__H__ #define __MERGESTRIPSMESSAGE__H__
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Sent when a player adds the first Action of Strip A to a Strip B
*
*/
class MergeStripsMessage : public BehaviorMessageBase { class MergeStripsMessage : public BehaviorMessageBase {
public: public:
MergeStripsMessage(AMFArrayValue* arguments); MergeStripsMessage(AMFArrayValue* arguments);
const StripId GetSrcStripID() { return srcStripID; };
const BehaviorState GetDstStateID() { return dstStateID; };
const BehaviorState GetSrcStateID() { return srcStateID; };
const uint32_t GetDstActionIndex() { return dstActionIndex; }; const uint32_t GetDstActionIndex() { return dstActionIndex; };
const StripId GetDstStripID() { return dstStripID; }; ActionContext GetSourceActionContext() { return sourceActionContext; };
const uint32_t GetBehaviorID() { return behaviorID; }; ActionContext GetDestinationActionContext() { return destinationActionContext; };
private: private:
StripId srcStripID; ActionContext sourceActionContext;
BehaviorState dstStateID; ActionContext destinationActionContext;
BehaviorState srcStateID;
uint32_t dstActionIndex; uint32_t dstActionIndex;
StripId dstStripID;
uint32_t behaviorID;
}; };
#endif //!__MERGESTRIPSMESSAGE__H__ #endif //!__MERGESTRIPSMESSAGE__H__

View File

@ -1,24 +1,11 @@
#include "MigrateActionsMessage.h" #include "MigrateActionsMessage.h"
MigrateActionsMessage::MigrateActionsMessage(AMFArrayValue* arguments) { MigrateActionsMessage::MigrateActionsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
auto* srcActionIndexAmf = arguments->FindValue<AMFDoubleValue>("srcActionIndex"); sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID");
if (!srcActionIndexAmf) return; srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex");
srcActionIndex = static_cast<uint32_t>(srcActionIndexAmf->GetDoubleValue()); destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID");
dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex");
srcStripID = GetStripIDFromArgument(arguments, "srcStripID"); Game::logger->LogDebug("MigrateActionsMessage", "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);
srcStateID = GetBehaviorStateFromArgument(arguments, "srcStateID");
auto* dstActionIndexAmf = arguments->FindValue<AMFDoubleValue>("dstActionIndex");
if (!dstActionIndexAmf) return;
dstActionIndex = static_cast<uint32_t>(dstActionIndexAmf->GetDoubleValue());
dstStripID = GetStripIDFromArgument(arguments, "dstStripID");
dstStateID = GetBehaviorStateFromArgument(arguments, "dstStateID");
behaviorID = GetBehaviorIDFromArgument(arguments);
Game::logger->LogDebug("MigrateActionsMessage", "srcAcnNdx %i dstAcnNdx %i srcStpId %i dstStpId %i srcSttId %i dstSttId %i bhid %i", srcActionIndex, dstActionIndex, srcStripID, dstStripID, srcStateID, dstStateID, behaviorID);
} }

View File

@ -1,28 +1,27 @@
#ifndef __MIGRATEACTIONSMESSAGE__H__ #ifndef __MIGRATEACTIONSMESSAGE__H__
#define __MIGRATEACTIONSMESSAGE__H__ #define __MIGRATEACTIONSMESSAGE__H__
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Sent when a player moves an Action after the first Action to a different Strip
*
*/
class MigrateActionsMessage : public BehaviorMessageBase { class MigrateActionsMessage : public BehaviorMessageBase {
public: public:
MigrateActionsMessage(AMFArrayValue* arguments); MigrateActionsMessage(AMFArrayValue* arguments);
const uint32_t GetSrcActionIndex() { return srcActionIndex; }; const uint32_t GetSrcActionIndex() { return srcActionIndex; };
const StripId GetSrcStripID() { return srcStripID; };
const BehaviorState GetSrcStateID() { return srcStateID; };
const uint32_t GetDstActionIndex() { return dstActionIndex; }; const uint32_t GetDstActionIndex() { return dstActionIndex; };
const StripId GetDstStripID() { return dstStripID; }; ActionContext GetSourceActionContext() { return sourceActionContext; };
const BehaviorState GetDstStateID() { return dstStateID; }; ActionContext GetDestinationActionContext() { return destinationActionContext; };
const uint32_t GetBehaviorID() { return behaviorID; };
private: private:
ActionContext sourceActionContext;
ActionContext destinationActionContext;
uint32_t srcActionIndex; uint32_t srcActionIndex;
StripId srcStripID;
BehaviorState srcStateID;
uint32_t dstActionIndex; uint32_t dstActionIndex;
StripId dstStripID;
BehaviorState dstStateID;
uint32_t behaviorID;
}; };
#endif //!__MIGRATEACTIONSMESSAGE__H__ #endif //!__MIGRATEACTIONSMESSAGE__H__

View File

@ -1,11 +1,9 @@
#include "MoveToInventoryMessage.h" #include "MoveToInventoryMessage.h"
MoveToInventoryMessage::MoveToInventoryMessage(AMFArrayValue* arguments) { MoveToInventoryMessage::MoveToInventoryMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
behaviorID = GetBehaviorIDFromArgument(arguments);
auto* behaviorIndexValue = arguments->FindValue<AMFDoubleValue>("BehaviorIndex"); auto* behaviorIndexValue = arguments->FindValue<AMFDoubleValue>("BehaviorIndex");
if (!behaviorIndexValue) return; if (!behaviorIndexValue) return;
behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetDoubleValue()); behaviorIndex = static_cast<uint32_t>(behaviorIndexValue->GetDoubleValue());
Game::logger->LogDebug("MoveToInventoryMessage", "bhId %i bhNdx %i", behaviorID, behaviorIndex); Game::logger->LogDebug("MoveToInventoryMessage", "behaviorId %i behaviorIndex %i", behaviorId, behaviorIndex);
} }

View File

@ -5,14 +5,16 @@
class AMFArrayValue; class AMFArrayValue;
/**
* @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(AMFArrayValue* arguments);
const uint32_t GetBehaviorID() { return behaviorID; };
const uint32_t GetBehaviorIndex() { return behaviorIndex; }; const uint32_t GetBehaviorIndex() { return behaviorIndex; };
private: private:
uint32_t behaviorID;
uint32_t behaviorIndex; uint32_t behaviorIndex;
}; };

View File

@ -1,16 +1,10 @@
#include "RearrangeStripMessage.h" #include "RearrangeStripMessage.h"
RearrangeStripMessage::RearrangeStripMessage(AMFArrayValue* arguments) { RearrangeStripMessage::RearrangeStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
auto* srcActionIndexValue = arguments->FindValue<AMFDoubleValue>("srcActionIndex"); actionContext = ActionContext(arguments);
srcActionIndex = static_cast<uint32_t>(srcActionIndexValue->GetDoubleValue()); srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex");
stripID = GetStripIDFromArgument(arguments); dstActionIndex = GetActionIndexFromArgument(arguments, "dstActionIndex");
behaviorID = GetBehaviorIDFromArgument(arguments); Game::logger->LogDebug("RearrangeStripMessage", "srcactionIndex %i dstactionIndex %i stripId %i behaviorId %i stateId %i", srcActionIndex, dstActionIndex, actionContext.GetStripId(), behaviorId, actionContext.GetStateId());
auto* dstActionIndexValue = arguments->FindValue<AMFDoubleValue>("dstActionIndex");
dstActionIndex = static_cast<uint32_t>(dstActionIndexValue->GetDoubleValue());
stateID = GetBehaviorStateFromArgument(arguments);
Game::logger->LogDebug("RearrangeStripMessage", "srcAcnNdx %i dstAcnNdx %i stpId %i bhId %i sttId %i", srcActionIndex, dstActionIndex, stripID, behaviorID, stateID);
} }

View File

@ -1,22 +1,23 @@
#ifndef __REARRANGESTRIPMESSAGE__H__ #ifndef __REARRANGESTRIPMESSAGE__H__
#define __REARRANGESTRIPMESSAGE__H__ #define __REARRANGESTRIPMESSAGE__H__
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
/**
* @brief Sent when a player moves an Action around in the same strip
*
*/
class RearrangeStripMessage : public BehaviorMessageBase { class RearrangeStripMessage : public BehaviorMessageBase {
public: public:
RearrangeStripMessage(AMFArrayValue* arguments); RearrangeStripMessage(AMFArrayValue* arguments);
const uint32_t GetSrcActionIndex() { return srcActionIndex; }; const uint32_t GetSrcActionIndex() { return srcActionIndex; };
const uint32_t GetStripID() { return stripID; };
const uint32_t GetBehaviorID() { return behaviorID; };
const uint32_t GetDstActionIndex() { return dstActionIndex; }; const uint32_t GetDstActionIndex() { return dstActionIndex; };
const BehaviorState GetStateID() { return stateID; }; ActionContext GetActionContext() { return actionContext; };
private: private:
ActionContext actionContext;
uint32_t srcActionIndex; uint32_t srcActionIndex;
uint32_t stripID;
uint32_t behaviorID;
uint32_t dstActionIndex; uint32_t dstActionIndex;
BehaviorState stateID;
}; };
#endif //!__REARRANGESTRIPMESSAGE__H__ #endif //!__REARRANGESTRIPMESSAGE__H__

View File

@ -1,15 +1,8 @@
#include "RemoveActionsMessage.h" #include "RemoveActionsMessage.h"
RemoveActionsMessage::RemoveActionsMessage(AMFArrayValue* arguments) { RemoveActionsMessage::RemoveActionsMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
behaviorID = GetBehaviorIDFromArgument(arguments); actionContext = ActionContext(arguments);
actionIndex = GetActionIndexFromArgument(arguments);
auto* actionIndexAmf = arguments->FindValue<AMFDoubleValue>("actionIndex"); Game::logger->LogDebug("RemoveActionsMessage", "behaviorId %i actionIndex %i stripId %i stateId %i", behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId());
if (!actionIndexAmf) return;
actionIndex = static_cast<uint32_t>(actionIndexAmf->GetDoubleValue());
stripID = GetStripIDFromArgument(arguments);
stateID = GetBehaviorStateFromArgument(arguments);
Game::logger->LogDebug("RemoveActionsMessage", "bhId %i acnNdx %i stpId %i sttId %i", behaviorID, actionIndex, stripID, stateID);
} }

View File

@ -1,22 +1,23 @@
#ifndef __REMOVEACTIONSMESSAGE__H__ #ifndef __REMOVEACTIONSMESSAGE__H__
#define __REMOVEACTIONSMESSAGE__H__ #define __REMOVEACTIONSMESSAGE__H__
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Sent when a player removes any Action after the first one from a Strip
*
*/
class RemoveActionsMessage : public BehaviorMessageBase { class RemoveActionsMessage : public BehaviorMessageBase {
public: public:
RemoveActionsMessage(AMFArrayValue* arguments); RemoveActionsMessage(AMFArrayValue* arguments);
const uint32_t GetBehaviorID() { return behaviorID; };
const uint32_t GetActionIndex() { return actionIndex; }; const uint32_t GetActionIndex() { return actionIndex; };
const StripId GetStripID() { return stripID; }; ActionContext GetActionContext() { return actionContext; };
const BehaviorState GetStateID() { return stateID; };
private: private:
uint32_t behaviorID; ActionContext actionContext;
uint32_t actionIndex; uint32_t actionIndex;
StripId stripID;
BehaviorState stateID;
}; };
#endif //!__REMOVEACTIONSMESSAGE__H__ #endif //!__REMOVEACTIONSMESSAGE__H__

View File

@ -1,8 +1,7 @@
#include "RemoveStripMessage.h" #include "RemoveStripMessage.h"
RemoveStripMessage::RemoveStripMessage(AMFArrayValue* arguments) { RemoveStripMessage::RemoveStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
stripId = GetStripIDFromArgument(arguments); actionContext = ActionContext(arguments);
behaviorState = GetBehaviorStateFromArgument(arguments);
behaviorId = GetBehaviorIDFromArgument(arguments); Game::logger->LogDebug("RemoveStripMessage", "stripId %i stateId %i behaviorId %i", actionContext.GetStripId(), actionContext.GetStateId(), behaviorId);
Game::logger->LogDebug("RemoveStripMessage", "stpId %i bhStt %i bhId %i", stripId, behaviorState, behaviorId);
} }

View File

@ -1,18 +1,19 @@
#ifndef __REMOVESTRIPMESSAGE__H__ #ifndef __REMOVESTRIPMESSAGE__H__
#define __REMOVESTRIPMESSAGE__H__ #define __REMOVESTRIPMESSAGE__H__
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
/**
* @brief Sent when a player removes the first Action from a strip.
*
*/
class RemoveStripMessage : public BehaviorMessageBase { class RemoveStripMessage : public BehaviorMessageBase {
public: public:
RemoveStripMessage(AMFArrayValue* arguments); RemoveStripMessage(AMFArrayValue* arguments);
const StripId GetStripId() { return stripId; }; ActionContext GetActionContext() { return actionContext; };
const BehaviorState GetBehaviorState() { return behaviorState; };
const uint32_t GetBehaviorId() { return behaviorId; };
private: private:
StripId stripId; ActionContext actionContext;
BehaviorState behaviorState;
uint32_t behaviorId;
}; };
#endif //!__REMOVESTRIPMESSAGE__H__ #endif //!__REMOVESTRIPMESSAGE__H__

View File

@ -1,11 +1,9 @@
#include "RenameMessage.h" #include "RenameMessage.h"
RenameMessage::RenameMessage(AMFArrayValue* arguments) { RenameMessage::RenameMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
behaviorID = GetBehaviorIDFromArgument(arguments);
auto* nameAmf = arguments->FindValue<AMFStringValue>("Name"); auto* nameAmf = arguments->FindValue<AMFStringValue>("Name");
if (!nameAmf) return; if (!nameAmf) return;
name = nameAmf->GetStringValue(); name = nameAmf->GetStringValue();
Game::logger->LogDebug("RenameMessage", "bhId %i n %s", behaviorID, name.c_str()); Game::logger->LogDebug("RenameMessage", "behaviorId %i n %s", behaviorId, name.c_str());
} }

View File

@ -5,13 +5,15 @@
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Sent when a player renames this behavior
*
*/
class RenameMessage : public BehaviorMessageBase { class RenameMessage : public BehaviorMessageBase {
public: public:
RenameMessage(AMFArrayValue* arguments); RenameMessage(AMFArrayValue* arguments);
const uint32_t GetBehaviorID() { return behaviorID; };
const std::string& GetName() { return name; }; const std::string& GetName() { return name; };
private: private:
uint32_t behaviorID;
std::string name; std::string name;
}; };

View File

@ -1,29 +1,11 @@
#include "SplitStripMessage.h" #include "SplitStripMessage.h"
SplitStripMessage::SplitStripMessage(AMFArrayValue* arguments) { SplitStripMessage::SplitStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
auto* srcActionIndexValue = arguments->FindValue<AMFDoubleValue>("srcActionIndex"); sourceActionContext = ActionContext(arguments, "srcStateID", "srcStripID");
if (!srcActionIndexValue) return; srcActionIndex = GetActionIndexFromArgument(arguments, "srcActionIndex");
srcActionIndex = static_cast<uint32_t>(srcActionIndexValue->GetDoubleValue()); destinationActionContext = ActionContext(arguments, "dstStateID", "dstStripID");
destinationPosition = StripUiPosition(arguments, "dstStripUI");
srcStripId = GetStripIDFromArgument(arguments, "srcStripID"); Game::logger->LogDebug("SplitStripMessage", "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);
srcStateId = GetBehaviorStateFromArgument(arguments, "srcStateID");
dstStripId = GetStripIDFromArgument(arguments, "dstStripID");
dstStateId = GetBehaviorStateFromArgument(arguments, "dstStateID");
auto* dstStripUiArray = arguments->FindValue<AMFArrayValue>("dstStripUI");
if (!dstStripUiArray) return;
auto* xPositionValue = dstStripUiArray->FindValue<AMFDoubleValue>("x");
auto* yPositionValue = dstStripUiArray->FindValue<AMFDoubleValue>("y");
if (!xPositionValue || !yPositionValue) return;
yPosition = yPositionValue->GetDoubleValue();
xPosition = xPositionValue->GetDoubleValue();
behaviorId = GetBehaviorIDFromArgument(arguments);
Game::logger->LogDebug("SplitStripMessage", "bhid %i x %f y %f srcStp %i dstStp %i srcStt %i dstStt %i srcActNdx %i", behaviorId, xPosition, yPosition, srcStripId, dstStripId, srcStateId, dstStateId, srcActionIndex);
} }

View File

@ -1,30 +1,28 @@
#ifndef __SPLITSTRIPMESSAGE__H__ #ifndef __SPLITSTRIPMESSAGE__H__
#define __SPLITSTRIPMESSAGE__H__ #define __SPLITSTRIPMESSAGE__H__
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
#include "StripUiPosition.h"
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Sent when a player takes an Action from Strip A and does not add it to an existing strip
*
*/
class SplitStripMessage : public BehaviorMessageBase { class SplitStripMessage : public BehaviorMessageBase {
public: public:
SplitStripMessage(AMFArrayValue* arguments); SplitStripMessage(AMFArrayValue* arguments);
ActionContext GetSourceActionContext() { return sourceActionContext; };
ActionContext GetDestinationActionContext() { return destinationActionContext; };
const uint32_t GetSrcActionIndex() { return srcActionIndex; }; const uint32_t GetSrcActionIndex() { return srcActionIndex; };
const StripId GetSrcStripId() { return srcStripId; }; StripUiPosition GetPosition() { return destinationPosition; };
const BehaviorState GetSrcStateId() { return srcStateId; };
const StripId GetDstStripId() { return dstStripId; };
const BehaviorState GetDstStateId() { return dstStateId; };
const double GetYPosition() { return yPosition; };
const double GetXPosition() { return xPosition; };
const uint32_t GetBehaviorId() { return behaviorId; };
private: private:
ActionContext sourceActionContext;
ActionContext destinationActionContext;
uint32_t srcActionIndex; uint32_t srcActionIndex;
StripId srcStripId; StripUiPosition destinationPosition;
BehaviorState srcStateId;
StripId dstStripId;
BehaviorState dstStateId;
double yPosition;
double xPosition;
uint32_t behaviorId;
}; };
#endif //!__SPLITSTRIPMESSAGE__H__ #endif //!__SPLITSTRIPMESSAGE__H__

View File

@ -0,0 +1,22 @@
#include "StripUiPosition.h"
#include "AMFFormat.h"
StripUiPosition::StripUiPosition() {
xPosition = 0.0;
yPosition = 0.0;
}
StripUiPosition::StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName) {
xPosition = 0.0;
yPosition = 0.0;
auto* uiArray = arguments->FindValue<AMFArrayValue>(uiKeyName);
if (!uiArray) return;
auto* xPositionValue = uiArray->FindValue<AMFDoubleValue>("x");
auto* yPositionValue = uiArray->FindValue<AMFDoubleValue>("y");
if (!xPositionValue || !yPositionValue) return;
yPosition = yPositionValue->GetDoubleValue();
xPosition = xPositionValue->GetDoubleValue();
}

View File

@ -0,0 +1,21 @@
#ifndef __STRIPUIPOSITION__H__
#define __STRIPUIPOSITION__H__
class AMFArrayValue;
/**
* @brief The position of the first Action in a Strip
*
*/
class StripUiPosition {
public:
StripUiPosition();
StripUiPosition(AMFArrayValue* arguments, std::string uiKeyName = "ui");
double GetX() { return xPosition; };
double GetY() { return yPosition; };
private:
double xPosition;
double yPosition;
};
#endif //!__STRIPUIPOSITION__H__

View File

@ -1,38 +1,15 @@
#include "UpdateActionMessage.h" #include "UpdateActionMessage.h"
UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) { #include "Action.h"
type = "";
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
auto* actionAsArray = arguments->FindValue<AMFArrayValue>("action");
if (!actionAsArray) return;
for (auto& typeValueMap : actionAsArray->GetAssociativeMap()) {
if (typeValueMap.first == "Type") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
type = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
valueParameterName = typeValueMap.first;
// Message is the only known string parameter
if (valueParameterName == "Message") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
valueParameterString = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue;
valueParameterDouble = static_cast<AMFDoubleValue*>(typeValueMap.second)->GetDoubleValue();
}
}
}
behaviorID = GetBehaviorIDFromArgument(arguments); UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
actionContext = ActionContext(arguments);
auto* actionIndexValue = arguments->FindValue<AMFDoubleValue>("actionIndex"); auto* actionValue = arguments->FindValue<AMFArrayValue>("action");
if (!actionIndexValue) return; if (!actionValue) return;
actionIndex = static_cast<uint32_t>(actionIndexValue->GetDoubleValue()); action = Action(actionValue);
actionIndex = GetActionIndexFromArgument(arguments);
stripID = GetStripIDFromArgument(arguments); Game::logger->LogDebug("UpdateActionMessage", "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());
stateID = GetBehaviorStateFromArgument(arguments);
Game::logger->LogDebug("UpdateActionMessage", "t %s vpn %s vps %s vpd %f bhId %i acnNdx %i stpId %i sttId %i", type.c_str(), valueParameterName.c_str(), valueParameterString.c_str(), valueParameterDouble, behaviorID, actionIndex, stripID, stateID);
} }

View File

@ -1,30 +1,26 @@
#ifndef __UPDATEACTIONMESSAGE__H__ #ifndef __UPDATEACTIONMESSAGE__H__
#define __UPDATEACTIONMESSAGE__H__ #define __UPDATEACTIONMESSAGE__H__
#include "Action.h"
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Sent when a player updates the value in an Action
*
*/
class UpdateActionMessage : public BehaviorMessageBase { class UpdateActionMessage : public BehaviorMessageBase {
public: public:
UpdateActionMessage(AMFArrayValue* arguments); UpdateActionMessage(AMFArrayValue* arguments);
const std::string& GetType() { return type; };
const std::string& GetValueParameterName() { return valueParameterName; };
const std::string& GetValueParameterString() { return valueParameterString; };
const double GetValueParameterDouble() { return valueParameterDouble; };
const uint32_t GetBehaviorID() { return behaviorID; };
const uint32_t GetActionIndex() { return actionIndex; }; const uint32_t GetActionIndex() { return actionIndex; };
const StripId GetStripID() { return stripID; }; ActionContext GetActionContext() { return actionContext; };
const BehaviorState GetStateID() { return stateID; }; Action GetAction() { return action; };
private: private:
std::string type;
std::string valueParameterName;
std::string valueParameterString;
double valueParameterDouble;
uint32_t behaviorID;
uint32_t actionIndex; uint32_t actionIndex;
StripId stripID; ActionContext actionContext;
BehaviorState stateID; Action action;
}; };
#endif //!__UPDATEACTIONMESSAGE__H__ #endif //!__UPDATEACTIONMESSAGE__H__

View File

@ -1,20 +1,8 @@
#include "UpdateStripUiMessage.h" #include "UpdateStripUiMessage.h"
UpdateStripUiMessage::UpdateStripUiMessage(AMFArrayValue* arguments) { UpdateStripUiMessage::UpdateStripUiMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
auto* uiArray = arguments->FindValue<AMFArrayValue>("ui"); position = StripUiPosition(arguments);
if (!uiArray) return; actionContext = ActionContext(arguments);
auto* xPositionValue = uiArray->FindValue<AMFDoubleValue>("x"); Game::logger->LogDebug("UpdateStripUIMessage", "xPosition %f yPosition %f stripId %i stateId %i behaviorId %i", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId);
auto* yPositionValue = uiArray->FindValue<AMFDoubleValue>("y");
if (!xPositionValue || !yPositionValue) return;
yPosition = yPositionValue->GetDoubleValue();
xPosition = xPositionValue->GetDoubleValue();
stripID = GetStripIDFromArgument(arguments);
stateID = GetBehaviorStateFromArgument(arguments);
behaviorID = GetBehaviorIDFromArgument(arguments);
Game::logger->LogDebug("UpdateStripUIMessage", "x %f y %f stpId %i sttId %i bhId %i", xPosition, yPosition, stripID, stateID, behaviorID);
} }

View File

@ -1,24 +1,24 @@
#ifndef __UPDATESTRIPUIMESSAGE__H__ #ifndef __UPDATESTRIPUIMESSAGE__H__
#define __UPDATESTRIPUIMESSAGE__H__ #define __UPDATESTRIPUIMESSAGE__H__
#include "ActionContext.h"
#include "BehaviorMessageBase.h" #include "BehaviorMessageBase.h"
#include "StripUiPosition.h"
class AMFArrayValue; class AMFArrayValue;
/**
* @brief Sent when a player moves the first Action in a Strip
*
*/
class UpdateStripUiMessage : public BehaviorMessageBase { class UpdateStripUiMessage : public BehaviorMessageBase {
public: public:
UpdateStripUiMessage(AMFArrayValue* arguments); UpdateStripUiMessage(AMFArrayValue* arguments);
const double GetYPosition() { return yPosition; }; StripUiPosition GetPosition() { return position; };
const double GetXPosition() { return xPosition; }; ActionContext GetActionContext() { return actionContext; };
const StripId GetStripID() { return stripID; };
const BehaviorState GetStateID() { return stateID; };
const uint32_t GetBehaviorID() { return behaviorID; };
private: private:
double yPosition; StripUiPosition position;
double xPosition; ActionContext actionContext;
StripId stripID;
BehaviorState stateID;
uint32_t behaviorID;
}; };
#endif //!__UPDATESTRIPUIMESSAGE__H__ #endif //!__UPDATESTRIPUIMESSAGE__H__

View File

@ -15,6 +15,7 @@
#include "CDClientDatabase.h" #include "CDClientDatabase.h"
// Message includes // Message includes
#include "Action.h"
#include "AddActionMessage.h" #include "AddActionMessage.h"
#include "AddStripMessage.h" #include "AddStripMessage.h"
#include "AddMessage.h" #include "AddMessage.h"
@ -248,18 +249,23 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ModelComponent* modelComponent
void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) { void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) {
UpdateActionMessage updateActionMessage(arguments); UpdateActionMessage updateActionMessage(arguments);
auto* blockDefinition = GetBlockInfo(updateActionMessage.GetType()); auto* blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType());
if (updateActionMessage.GetValueParameterString().size() > 0) { if (!blockDefinition) {
if (updateActionMessage.GetValueParameterString().size() < blockDefinition->GetMinimumValue() || Game::logger->Log("ControlBehaviors", "Received undefined block type %s. Ignoring.", updateActionMessage.GetAction().GetType().c_str());
updateActionMessage.GetValueParameterString().size() > blockDefinition->GetMaximumValue()) { return;
Game::logger->Log("ControlBehaviors", "Updated block %s is out of range. Ignoring update", updateActionMessage.GetType().c_str()); }
if (updateActionMessage.GetAction().GetValueParameterString().size() > 0) {
if (updateActionMessage.GetAction().GetValueParameterString().size() < blockDefinition->GetMinimumValue() ||
updateActionMessage.GetAction().GetValueParameterString().size() > blockDefinition->GetMaximumValue()) {
Game::logger->Log("ControlBehaviors", "Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str());
return; return;
} }
} else { } else {
if (updateActionMessage.GetValueParameterDouble() < blockDefinition->GetMinimumValue() || if (updateActionMessage.GetAction().GetValueParameterDouble() < blockDefinition->GetMinimumValue() ||
updateActionMessage.GetValueParameterDouble() > blockDefinition->GetMaximumValue()) { updateActionMessage.GetAction().GetValueParameterDouble() > blockDefinition->GetMaximumValue()) {
Game::logger->Log("ControlBehaviors", "Updated block %s is out of range. Ignoring update", updateActionMessage.GetType().c_str()); Game::logger->Log("ControlBehaviors", "Updated block %s is out of range. Ignoring update", updateActionMessage.GetAction().GetType().c_str());
return; return;
} }
} }
@ -452,5 +458,5 @@ ControlBehaviors::ControlBehaviors() {
BlockDefinition* ControlBehaviors::GetBlockInfo(const BlockName& blockName) { BlockDefinition* ControlBehaviors::GetBlockInfo(const BlockName& blockName) {
auto blockDefinition = blockTypes.find(blockName); auto blockDefinition = blockTypes.find(blockName);
return blockDefinition != blockTypes.end() ? blockDefinition->second : &BlockDefinition::blockDefinitionDefault; return blockDefinition != blockTypes.end() ? blockDefinition->second : nullptr;
} }

View File

@ -258,9 +258,9 @@ TEST(dCommonTests, AMFDeserializeLivePacketTest) {
ASSERT_EQ(actionIndex->GetDoubleValue(), 0.0f); ASSERT_EQ(actionIndex->GetDoubleValue(), 0.0f);
auto stripIDExecution = stripsPosition0->FindValue<AMFDoubleValue>("id"); auto stripIdExecution = stripsPosition0->FindValue<AMFDoubleValue>("id");
ASSERT_EQ(stripIDExecution->GetDoubleValue(), 0.0f); ASSERT_EQ(stripIdExecution->GetDoubleValue(), 0.0f);
auto stateIDExecution = executionState->FindValue<AMFDoubleValue>("stateID"); auto stateIDExecution = executionState->FindValue<AMFDoubleValue>("stateID");
@ -298,9 +298,9 @@ TEST(dCommonTests, AMFDeserializeLivePacketTest) {
ASSERT_EQ(xPos->GetDoubleValue(), 103.0f); ASSERT_EQ(xPos->GetDoubleValue(), 103.0f);
ASSERT_EQ(yPos->GetDoubleValue(), 82.0f); ASSERT_EQ(yPos->GetDoubleValue(), 82.0f);
auto stripID = firstStrip->FindValue<AMFDoubleValue>("id"); auto stripId = firstStrip->FindValue<AMFDoubleValue>("id");
ASSERT_EQ(stripID->GetDoubleValue(), 0.0f); ASSERT_EQ(stripId->GetDoubleValue(), 0.0f);
auto firstAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[0]); auto firstAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[0]);

View File

@ -1,7 +1,12 @@
#include "Action.h"
#include "AMFFormat.h"
#include "AMFDeserialize.h"
#include "GameMessages.h" #include "GameMessages.h"
#include "GameDependencies.h" #include "GameDependencies.h"
#include "AMFDeserialize.h"
#include <gtest/gtest.h>
// Message includes
#include "AddActionMessage.h" #include "AddActionMessage.h"
#include "AddStripMessage.h" #include "AddStripMessage.h"
#include "AddMessage.h" #include "AddMessage.h"
@ -16,9 +21,6 @@
#include "UpdateActionMessage.h" #include "UpdateActionMessage.h"
#include "UpdateStripUiMessage.h" #include "UpdateStripUiMessage.h"
#include <gtest/gtest.h>
#include <fstream>
class GameMessageTests: public GameDependenciesTest { class GameMessageTests: public GameDependenciesTest {
protected: protected:
void SetUp() override { void SetUp() override {
@ -27,7 +29,6 @@ protected:
void TearDown() override { void TearDown() override {
TearDownDependencies(); TearDownDependencies();
} }
std::string ReadFromFile(std::string filename) { std::string ReadFromFile(std::string filename) {
std::ifstream file(filename, std::ios::binary); std::ifstream file(filename, std::ios::binary);
std::string readFile; std::string readFile;
@ -35,10 +36,8 @@ protected:
char readCharacter = file.get(); char readCharacter = file.get();
readFile.push_back(readCharacter); readFile.push_back(readCharacter);
} }
return readFile; return readFile;
} }
AMFArrayValue* ReadArrayFromBitStream(RakNet::BitStream* inStream) { AMFArrayValue* ReadArrayFromBitStream(RakNet::BitStream* inStream) {
AMFDeserialize des; AMFDeserialize des;
AMFValue* readArray = des.Read(inStream); AMFValue* readArray = des.Read(inStream);
@ -90,23 +89,23 @@ TEST_F(GameMessageTests, ControlBehaviorAddStrip) {
auto data = ReadFromFile("addStrip"); auto data = ReadFromFile("addStrip");
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
AddStripMessage addStrip(ReadArrayFromBitStream(&inStream)); AddStripMessage addStrip(ReadArrayFromBitStream(&inStream));
ASSERT_FLOAT_EQ(addStrip.GetXPosition(), 50.65); ASSERT_FLOAT_EQ(addStrip.GetPosition().GetX(), 50.65);
ASSERT_FLOAT_EQ(addStrip.GetYPosition(), 178.05); ASSERT_FLOAT_EQ(addStrip.GetPosition().GetY(), 178.05);
ASSERT_EQ(addStrip.GetStripId(), 0); ASSERT_EQ(addStrip.GetActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(addStrip.GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(addStrip.GetActionContext().GetStateId()), 0);
ASSERT_EQ(addStrip.GetBehaviorId(), -1); ASSERT_EQ(addStrip.GetBehaviorId(), -1);
ASSERT_EQ(addStrip.GetType(), "DropImagination"); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetType(), "DropImagination");
ASSERT_EQ(addStrip.GetValueParameterName(), "Amount"); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterName(), "Amount");
ASSERT_EQ(addStrip.GetValueParameterString(), ""); ASSERT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterString(), "");
ASSERT_FLOAT_EQ(addStrip.GetValueParameterDouble(), 1.0); ASSERT_FLOAT_EQ(addStrip.GetActionsToAdd().front().GetValueParameterDouble(), 1.0);
} }
TEST_F(GameMessageTests, ControlBehaviorRemoveStrip) { TEST_F(GameMessageTests, ControlBehaviorRemoveStrip) {
auto data = ReadFromFile("removeStrip"); auto data = ReadFromFile("removeStrip");
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
RemoveStripMessage removeStrip(ReadArrayFromBitStream(&inStream)); RemoveStripMessage removeStrip(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(static_cast<int32_t>(removeStrip.GetStripId()), 1); ASSERT_EQ(static_cast<int32_t>(removeStrip.GetActionContext().GetStripId()), 1);
ASSERT_EQ(static_cast<int32_t>(removeStrip.GetBehaviorState()), 0); ASSERT_EQ(static_cast<int32_t>(removeStrip.GetActionContext().GetStateId()), 0);
ASSERT_EQ(removeStrip.GetBehaviorId(), -1); ASSERT_EQ(removeStrip.GetBehaviorId(), -1);
} }
@ -114,12 +113,12 @@ TEST_F(GameMessageTests, ControlBehaviorMergeStrips) {
auto data = ReadFromFile("mergeStrips"); auto data = ReadFromFile("mergeStrips");
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
MergeStripsMessage mergeStrips(ReadArrayFromBitStream(&inStream)); MergeStripsMessage mergeStrips(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(mergeStrips.GetSrcStripID(), 2); ASSERT_EQ(mergeStrips.GetSourceActionContext().GetStripId(), 2);
ASSERT_EQ(mergeStrips.GetDstStripID(), 0); ASSERT_EQ(mergeStrips.GetDestinationActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(mergeStrips.GetSrcStateID()), 0); ASSERT_EQ(static_cast<uint32_t>(mergeStrips.GetSourceActionContext().GetStateId()), 0);
ASSERT_EQ(static_cast<uint32_t>(mergeStrips.GetDstStateID()), 0); ASSERT_EQ(static_cast<uint32_t>(mergeStrips.GetDestinationActionContext().GetStateId()), 0);
ASSERT_EQ(mergeStrips.GetDstActionIndex(), 0); ASSERT_EQ(mergeStrips.GetDstActionIndex(), 0);
ASSERT_EQ(mergeStrips.GetBehaviorID(), -1); ASSERT_EQ(mergeStrips.GetBehaviorId(), -1);
} }
TEST_F(GameMessageTests, ControlBehaviorSplitStrip) { TEST_F(GameMessageTests, ControlBehaviorSplitStrip) {
@ -128,12 +127,12 @@ TEST_F(GameMessageTests, ControlBehaviorSplitStrip) {
SplitStripMessage splitStrip(ReadArrayFromBitStream(&inStream)); SplitStripMessage splitStrip(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(splitStrip.GetBehaviorId(), -1); ASSERT_EQ(splitStrip.GetBehaviorId(), -1);
ASSERT_FLOAT_EQ(splitStrip.GetXPosition(), 275.65); ASSERT_FLOAT_EQ(splitStrip.GetPosition().GetX(), 275.65);
ASSERT_FLOAT_EQ(splitStrip.GetYPosition(), 28.7); ASSERT_FLOAT_EQ(splitStrip.GetPosition().GetY(), 28.7);
ASSERT_EQ(splitStrip.GetSrcStripId(), 0); ASSERT_EQ(splitStrip.GetSourceActionContext().GetStripId(), 0);
ASSERT_EQ(splitStrip.GetDstStripId(), 2); ASSERT_EQ(splitStrip.GetDestinationActionContext().GetStripId(), 2);
ASSERT_EQ(static_cast<uint32_t>(splitStrip.GetSrcStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(splitStrip.GetSourceActionContext().GetStateId()), 0);
ASSERT_EQ(static_cast<uint32_t>(splitStrip.GetDstStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(splitStrip.GetDestinationActionContext().GetStateId()), 0);
ASSERT_EQ(splitStrip.GetSrcActionIndex(), 1); ASSERT_EQ(splitStrip.GetSrcActionIndex(), 1);
} }
@ -141,11 +140,11 @@ TEST_F(GameMessageTests, ControlBehaviorUpdateStripUI) {
auto data = ReadFromFile("updateStripUI"); auto data = ReadFromFile("updateStripUI");
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
UpdateStripUiMessage updateStripUi(ReadArrayFromBitStream(&inStream)); UpdateStripUiMessage updateStripUi(ReadArrayFromBitStream(&inStream));
ASSERT_FLOAT_EQ(updateStripUi.GetXPosition(), 116.65); ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetX(), 116.65);
ASSERT_FLOAT_EQ(updateStripUi.GetYPosition(), 35.35); ASSERT_FLOAT_EQ(updateStripUi.GetPosition().GetY(), 35.35);
ASSERT_EQ(updateStripUi.GetStripID(), 0); ASSERT_EQ(updateStripUi.GetActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(updateStripUi.GetStateID()), 0); ASSERT_EQ(static_cast<uint32_t>(updateStripUi.GetActionContext().GetStateId()), 0);
ASSERT_EQ(updateStripUi.GetBehaviorID(), -1); ASSERT_EQ(updateStripUi.GetBehaviorId(), -1);
} }
TEST_F(GameMessageTests, ControlBehaviorAddAction) { TEST_F(GameMessageTests, ControlBehaviorAddAction) {
@ -153,12 +152,12 @@ TEST_F(GameMessageTests, ControlBehaviorAddAction) {
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
AddActionMessage addAction(ReadArrayFromBitStream(&inStream)); AddActionMessage addAction(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(addAction.GetActionIndex(), 3); ASSERT_EQ(addAction.GetActionIndex(), 3);
ASSERT_EQ(addAction.GetStripId(), 0); ASSERT_EQ(addAction.GetActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(addAction.GetStateId()), 0); ASSERT_EQ(static_cast<uint32_t>(addAction.GetActionContext().GetStateId()), 0);
ASSERT_EQ(addAction.GetType(), "DoDamage"); ASSERT_EQ(addAction.GetAction().GetType(), "DoDamage");
ASSERT_EQ(addAction.GetValueParameterName(), ""); ASSERT_EQ(addAction.GetAction().GetValueParameterName(), "");
ASSERT_EQ(addAction.GetValueParameterString(), ""); ASSERT_EQ(addAction.GetAction().GetValueParameterString(), "");
ASSERT_EQ(addAction.GetValueParameterDouble(), 0.0); ASSERT_EQ(addAction.GetAction().GetValueParameterDouble(), 0.0);
ASSERT_EQ(addAction.GetBehaviorId(), -1); ASSERT_EQ(addAction.GetBehaviorId(), -1);
} }
@ -168,11 +167,11 @@ TEST_F(GameMessageTests, ControlBehaviorMigrateActions) {
MigrateActionsMessage migrateActions(ReadArrayFromBitStream(&inStream)); MigrateActionsMessage migrateActions(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(migrateActions.GetSrcActionIndex(), 1); ASSERT_EQ(migrateActions.GetSrcActionIndex(), 1);
ASSERT_EQ(migrateActions.GetDstActionIndex(), 2); ASSERT_EQ(migrateActions.GetDstActionIndex(), 2);
ASSERT_EQ(migrateActions.GetSrcStripID(), 1); ASSERT_EQ(migrateActions.GetSourceActionContext().GetStripId(), 1);
ASSERT_EQ(migrateActions.GetDstStripID(), 0); ASSERT_EQ(migrateActions.GetDestinationActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(migrateActions.GetSrcStateID()), 0); ASSERT_EQ(static_cast<uint32_t>(migrateActions.GetSourceActionContext().GetStateId()), 0);
ASSERT_EQ(static_cast<uint32_t>(migrateActions.GetDstStateID()), 0); ASSERT_EQ(static_cast<uint32_t>(migrateActions.GetDestinationActionContext().GetStateId()), 0);
ASSERT_EQ(migrateActions.GetBehaviorID(), -1); ASSERT_EQ(migrateActions.GetBehaviorId(), -1);
} }
TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) { TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) {
@ -181,9 +180,9 @@ TEST_F(GameMessageTests, ControlBehaviorRearrangeStrip) {
RearrangeStripMessage rearrangeStrip(ReadArrayFromBitStream(&inStream)); RearrangeStripMessage rearrangeStrip(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(rearrangeStrip.GetSrcActionIndex(), 2); ASSERT_EQ(rearrangeStrip.GetSrcActionIndex(), 2);
ASSERT_EQ(rearrangeStrip.GetDstActionIndex(), 1); ASSERT_EQ(rearrangeStrip.GetDstActionIndex(), 1);
ASSERT_EQ(rearrangeStrip.GetStripID(), 0); ASSERT_EQ(rearrangeStrip.GetActionContext().GetStripId(), 0);
ASSERT_EQ(rearrangeStrip.GetBehaviorID(), -1); ASSERT_EQ(rearrangeStrip.GetBehaviorId(), -1);
ASSERT_EQ(static_cast<uint32_t>(rearrangeStrip.GetStateID()), 0); ASSERT_EQ(static_cast<uint32_t>(rearrangeStrip.GetActionContext().GetStateId()), 0);
} }
TEST_F(GameMessageTests, ControlBehaviorAdd) { TEST_F(GameMessageTests, ControlBehaviorAdd) {
@ -198,10 +197,10 @@ TEST_F(GameMessageTests, ControlBehaviorRemoveActions) {
auto data = ReadFromFile("removeActions"); auto data = ReadFromFile("removeActions");
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
RemoveActionsMessage removeActions(ReadArrayFromBitStream(&inStream)); RemoveActionsMessage removeActions(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(removeActions.GetBehaviorID(), -1); ASSERT_EQ(removeActions.GetBehaviorId(), -1);
ASSERT_EQ(removeActions.GetActionIndex(), 1); ASSERT_EQ(removeActions.GetActionIndex(), 1);
ASSERT_EQ(removeActions.GetStripID(), 0); ASSERT_EQ(removeActions.GetActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(removeActions.GetStateID()), 0); ASSERT_EQ(static_cast<uint32_t>(removeActions.GetActionContext().GetStateId()), 0);
} }
TEST_F(GameMessageTests, ControlBehaviorRename) { TEST_F(GameMessageTests, ControlBehaviorRename) {
@ -209,19 +208,19 @@ TEST_F(GameMessageTests, ControlBehaviorRename) {
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
RenameMessage rename(ReadArrayFromBitStream(&inStream)); RenameMessage rename(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(rename.GetName(), "test"); ASSERT_EQ(rename.GetName(), "test");
ASSERT_EQ(rename.GetBehaviorID(), -1); ASSERT_EQ(rename.GetBehaviorId(), -1);
} }
TEST_F(GameMessageTests, ControlBehaviorUpdateAction) { TEST_F(GameMessageTests, ControlBehaviorUpdateAction) {
auto data = ReadFromFile("updateAction"); auto data = ReadFromFile("updateAction");
RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true); RakNet::BitStream inStream((unsigned char*)data.c_str(), data.length(), true);
UpdateActionMessage updateAction(ReadArrayFromBitStream(&inStream)); UpdateActionMessage updateAction(ReadArrayFromBitStream(&inStream));
ASSERT_EQ(updateAction.GetType(), "FlyDown"); ASSERT_EQ(updateAction.GetAction().GetType(), "FlyDown");
ASSERT_EQ(updateAction.GetValueParameterName(), "Distance"); ASSERT_EQ(updateAction.GetAction().GetValueParameterName(), "Distance");
ASSERT_EQ(updateAction.GetValueParameterString(), ""); ASSERT_EQ(updateAction.GetAction().GetValueParameterString(), "");
ASSERT_EQ(updateAction.GetValueParameterDouble(), 50.0); ASSERT_EQ(updateAction.GetAction().GetValueParameterDouble(), 50.0);
ASSERT_EQ(updateAction.GetBehaviorID(), -1); ASSERT_EQ(updateAction.GetBehaviorId(), -1);
ASSERT_EQ(updateAction.GetActionIndex(), 1); ASSERT_EQ(updateAction.GetActionIndex(), 1);
ASSERT_EQ(updateAction.GetStripID(), 0); ASSERT_EQ(updateAction.GetActionContext().GetStripId(), 0);
ASSERT_EQ(static_cast<uint32_t>(updateAction.GetStateID()), 0); ASSERT_EQ(static_cast<uint32_t>(updateAction.GetActionContext().GetStateId()), 0);
} }