2023-02-16 17:30:33 +00:00
|
|
|
#include "ActionContext.h"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
#include "Amf3.h"
|
2023-02-16 17:30:33 +00:00
|
|
|
|
2024-11-19 02:45:24 +00:00
|
|
|
ActionContext::ActionContext(const AMFArrayValue& arguments, const std::string_view customStateKey, const std::string_view customStripKey)
|
2024-02-18 06:38:26 +00:00
|
|
|
: m_StripId{ GetStripIdFromArgument(arguments, customStripKey) }
|
|
|
|
, m_StateId{ GetBehaviorStateFromArgument(arguments, customStateKey) } {
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 02:45:24 +00:00
|
|
|
BehaviorState ActionContext::GetBehaviorStateFromArgument(const AMFArrayValue& arguments, const std::string_view key) const {
|
2024-02-27 07:29:51 +00:00
|
|
|
const auto* const stateIDValue = arguments.Get<double>(key);
|
2024-11-19 02:45:24 +00:00
|
|
|
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + std::string{ key } + "\"");
|
2023-02-16 17:30:33 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
return static_cast<BehaviorState>(stateIDValue->GetValue());
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 02:45:24 +00:00
|
|
|
StripId ActionContext::GetStripIdFromArgument(const AMFArrayValue& arguments, const std::string_view key) const {
|
2024-02-27 07:29:51 +00:00
|
|
|
const auto* const stripIdValue = arguments.Get<double>(key);
|
2024-11-19 02:45:24 +00:00
|
|
|
if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + std::string{ key } + "\"");
|
2023-02-16 17:30:33 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
return static_cast<StripId>(stripIdValue->GetValue());
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|