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
|
|
|
|
|
|
|
ActionContext::ActionContext() {
|
|
|
|
stripId = 0;
|
|
|
|
stateId = BehaviorState::HOME_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionContext::ActionContext(AMFArrayValue* arguments, std::string customStateKey, std::string customStripKey) {
|
|
|
|
stripId = 0;
|
|
|
|
stateId = BehaviorState::HOME_STATE;
|
|
|
|
stripId = GetStripIdFromArgument(arguments, customStripKey);
|
|
|
|
stateId = GetBehaviorStateFromArgument(arguments, customStateKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
BehaviorState ActionContext::GetBehaviorStateFromArgument(AMFArrayValue* arguments, const std::string& key) {
|
2023-05-13 22:22:00 +00:00
|
|
|
auto* stateIDValue = arguments->Get<double>(key);
|
2023-02-16 17:30:33 +00:00
|
|
|
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\"");
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
return static_cast<BehaviorState>(stateIDValue->GetValue());
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StripId ActionContext::GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key) {
|
2023-05-13 22:22:00 +00:00
|
|
|
auto* stripIdValue = arguments->Get<double>(key);
|
2023-02-16 17:30:33 +00:00
|
|
|
if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\"");
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
return static_cast<StripId>(stripIdValue->GetValue());
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|