mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-13 10:58:07 +00:00
refactor: Rewrite BehaviorMessage classes to use member initialization, preferred member naming conventions, and const-ref getters (#1456)
* Split out BehaviorMessage class changes from PR #1452 * remove <string_view> inclusion in ActionContext.h * add the arguments nullptr check back in * remove redundant std::string constructor calls * Update AddStripMessage.cpp - change push_back to emplace_back
This commit is contained in:
@@ -4,27 +4,20 @@
|
||||
|
||||
#include "Amf3.h"
|
||||
|
||||
ActionContext::ActionContext() {
|
||||
stripId = 0;
|
||||
stateId = BehaviorState::HOME_STATE;
|
||||
ActionContext::ActionContext(const AMFArrayValue* arguments, const std::string& customStateKey, const std::string& customStripKey)
|
||||
: m_StripId{ GetStripIdFromArgument(arguments, customStripKey) }
|
||||
, m_StateId{ GetBehaviorStateFromArgument(arguments, customStateKey) } {
|
||||
}
|
||||
|
||||
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->Get<double>(key);
|
||||
BehaviorState ActionContext::GetBehaviorStateFromArgument(const AMFArrayValue* arguments, const std::string& key) const {
|
||||
const auto* const stateIDValue = arguments->Get<double>(key);
|
||||
if (!stateIDValue) throw std::invalid_argument("Unable to find behavior state from argument \"" + key + "\"");
|
||||
|
||||
return static_cast<BehaviorState>(stateIDValue->GetValue());
|
||||
}
|
||||
|
||||
StripId ActionContext::GetStripIdFromArgument(AMFArrayValue* arguments, const std::string& key) {
|
||||
auto* stripIdValue = arguments->Get<double>(key);
|
||||
StripId ActionContext::GetStripIdFromArgument(const AMFArrayValue* arguments, const std::string& key) const {
|
||||
const auto* const stripIdValue = arguments->Get<double>(key);
|
||||
if (!stripIdValue) throw std::invalid_argument("Unable to find strip ID from argument \"" + key + "\"");
|
||||
|
||||
return static_cast<StripId>(stripIdValue->GetValue());
|
||||
|
Reference in New Issue
Block a user