Make ControlBehavior messages far more modular (#991)

* Make case consistent

* How modular can you go?

Holy modular

* Add comments

* Initialize values
This commit is contained in:
David Markowitz
2023-02-16 09:30:33 -08:00
committed by GitHub
parent 484488e47d
commit d138b7b878
38 changed files with 461 additions and 438 deletions

View File

@@ -1,38 +1,15 @@
#include "UpdateActionMessage.h"
UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) {
type = "";
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
auto* actionAsArray = arguments->FindValue<AMFArrayValue>("action");
if (!actionAsArray) return;
for (auto& typeValueMap : actionAsArray->GetAssociativeMap()) {
if (typeValueMap.first == "Type") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
type = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
valueParameterName = typeValueMap.first;
// Message is the only known string parameter
if (valueParameterName == "Message") {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFString) continue;
valueParameterString = static_cast<AMFStringValue*>(typeValueMap.second)->GetStringValue();
} else {
if (typeValueMap.second->GetValueType() != AMFValueType::AMFDouble) continue;
valueParameterDouble = static_cast<AMFDoubleValue*>(typeValueMap.second)->GetDoubleValue();
}
}
}
#include "Action.h"
behaviorID = GetBehaviorIDFromArgument(arguments);
UpdateActionMessage::UpdateActionMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
actionContext = ActionContext(arguments);
auto* actionIndexValue = arguments->FindValue<AMFDoubleValue>("actionIndex");
if (!actionIndexValue) return;
auto* actionValue = arguments->FindValue<AMFArrayValue>("action");
if (!actionValue) return;
actionIndex = static_cast<uint32_t>(actionIndexValue->GetDoubleValue());
action = Action(actionValue);
actionIndex = GetActionIndexFromArgument(arguments);
stripID = GetStripIDFromArgument(arguments);
stateID = GetBehaviorStateFromArgument(arguments);
Game::logger->LogDebug("UpdateActionMessage", "t %s vpn %s vps %s vpd %f bhId %i acnNdx %i stpId %i sttId %i", type.c_str(), valueParameterName.c_str(), valueParameterString.c_str(), valueParameterDouble, behaviorID, actionIndex, stripID, stateID);
Game::logger->LogDebug("UpdateActionMessage", "type %s valueParameterName %s valueParameterString %s valueParameterDouble %f behaviorId %i actionIndex %i stripId %i stateId %i", action.GetType().c_str(), action.GetValueParameterName().c_str(), action.GetValueParameterString().c_str(), action.GetValueParameterDouble(), behaviorId, actionIndex, actionContext.GetStripId(), actionContext.GetStateId());
}