2023-02-16 17:30:33 +00:00
|
|
|
#include "BehaviorMessageBase.h"
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
#include "Amf3.h"
|
2023-02-16 17:30:33 +00:00
|
|
|
#include "BehaviorStates.h"
|
|
|
|
#include "dCommonVars.h"
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(const AMFArrayValue& arguments) {
|
2024-11-19 02:45:24 +00:00
|
|
|
static constexpr std::string_view key = "BehaviorID";
|
2024-02-27 07:29:51 +00:00
|
|
|
const auto* const behaviorIDValue = arguments.Get<std::string>(key);
|
2024-02-18 06:38:26 +00:00
|
|
|
int32_t behaviorId = DefaultBehaviorId;
|
2023-02-16 17:30:33 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
|
2024-02-18 06:38:26 +00:00
|
|
|
behaviorId =
|
|
|
|
GeneralUtils::TryParse<int32_t>(behaviorIDValue->GetValue()).value_or(behaviorId);
|
2024-02-27 07:29:51 +00:00
|
|
|
} else if (arguments.Get(key) && arguments.Get(key)->GetValueType() != eAmf::Undefined) {
|
2023-02-16 17:30:33 +00:00
|
|
|
throw std::invalid_argument("Unable to find behavior ID");
|
|
|
|
}
|
|
|
|
|
2024-02-18 06:38:26 +00:00
|
|
|
return behaviorId;
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 02:45:24 +00:00
|
|
|
int32_t BehaviorMessageBase::GetActionIndexFromArgument(const AMFArrayValue& arguments, const std::string_view keyName) const {
|
2024-02-27 07:29:51 +00:00
|
|
|
const auto* const actionIndexAmf = arguments.Get<double>(keyName);
|
2024-02-10 19:44:40 +00:00
|
|
|
if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex");
|
2023-02-16 17:30:33 +00:00
|
|
|
|
2024-01-03 13:34:38 +00:00
|
|
|
return static_cast<int32_t>(actionIndexAmf->GetValue());
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|