mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-23 14:03:34 +00:00
d138b7b878
* Make case consistent * How modular can you go? Holy modular * Add comments * Initialize values
32 lines
1.1 KiB
C++
32 lines
1.1 KiB
C++
#include "ActionContext.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "AMFFormat.h"
|
|
|
|
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) {
|
|
auto* stateIDValue = arguments->FindValue<AMFDoubleValue>(key);
|
|
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\"");
|
|
|
|
return static_cast<BehaviorState>(stateIDValue->GetDoubleValue());
|
|
}
|
|
|
|
StripId ActionContext::GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key) {
|
|
auto* stripIdValue = arguments->FindValue<AMFDoubleValue>(key);
|
|
if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\"");
|
|
|
|
return static_cast<StripId>(stripIdValue->GetDoubleValue());
|
|
}
|