mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 02:04:04 +00:00
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:
@@ -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());
|
||||
}
|
Reference in New Issue
Block a user