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

@@ -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());
}