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
38 changed files with 461 additions and 438 deletions

View File

@@ -5,44 +5,25 @@
#include <string>
#include "AMFFormat.h"
#include "BehaviorStates.h"
#include "dCommonVars.h"
#include "Game.h"
#include "dLogger.h"
enum class BehaviorState : uint32_t;
/**
* @brief The behaviorID target of this ControlBehaviors message
*
*/
class BehaviorMessageBase {
public:
uint32_t GetBehaviorIDFromArgument(AMFArrayValue* arguments, const std::string& key = "BehaviorID") {
auto* behaviorIDValue = arguments->FindValue<AMFStringValue>(key);
uint32_t behaviorID = -1;
if (behaviorIDValue) {
behaviorID = std::stoul(behaviorIDValue->GetStringValue());
} 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;
}
const uint32_t GetBehaviorId() { return behaviorId; };
protected:
BehaviorMessageBase(AMFArrayValue* arguments);
int32_t GetBehaviorIdFromArgument(AMFArrayValue* arguments);
uint32_t GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName = "actionIndex");
int32_t behaviorId = -1;
};
#endif //!__BEHAVIORMESSAGEBASE__H__