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,56 +1,25 @@
#include "AddStripMessage.h"
AddStripMessage::AddStripMessage(AMFArrayValue* arguments) {
#include "Action.h"
AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
actionContext = ActionContext(arguments);
position = StripUiPosition(arguments);
auto* strip = arguments->FindValue<AMFArrayValue>("strip");
if (!strip) return;
auto* actions = strip->FindValue<AMFArrayValue>("actions");
if (!actions) return;
auto* uiArray = arguments->FindValue<AMFArrayValue>("ui");
if (!uiArray) return;
for (uint32_t actionNumber = 0; actionNumber < actions->GetDenseValueSize(); actionNumber++) {
auto* actionValue = actions->GetValueAt<AMFArrayValue>(actionNumber);
if (!actionValue) continue;
auto* xPositionValue = uiArray->FindValue<AMFDoubleValue>("x");
if (!xPositionValue) return;
actionsToAdd.push_back(Action(actionValue));
xPosition = xPositionValue->GetDoubleValue();
auto* yPositionValue = uiArray->FindValue<AMFDoubleValue>("y");
if (!yPositionValue) return;
yPosition = yPositionValue->GetDoubleValue();
stripId = GetStripIDFromArgument(arguments);
stateId = GetBehaviorStateFromArgument(arguments);
behaviorId = GetBehaviorIDFromArgument(arguments);
type = "";
valueParameterName = "";
valueParameterString = "";
valueParameterDouble = 0.0;
for (uint32_t position = 0; position < actions->GetDenseValueSize(); position++) {
auto* actionAsArray = actions->GetValueAt<AMFArrayValue>(position);
if (!actionAsArray) continue;
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();
}
}
}
Game::logger->LogDebug("AddStripMessage", "x %f y %f stpId %i sttId %i bhId %i t %s vpn %s vps %s vpd %f", xPosition, yPosition, stripId, stateId, behaviorId, type.c_str(), valueParameterName.c_str(), valueParameterString.c_str(), valueParameterDouble);
Game::logger->LogDebug("AddStripMessage", "xPosition %f yPosition %f stripId %i stateId %i behaviorId %i t %s valueParameterName %s valueParameterString %s valueParameterDouble %f", position.GetX(), position.GetY(), actionContext.GetStripId(), actionContext.GetStateId(), behaviorId, actionsToAdd.back().GetType().c_str(), actionsToAdd.back().GetValueParameterName().c_str(), actionsToAdd.back().GetValueParameterString().c_str(), actionsToAdd.back().GetValueParameterDouble());
}
Game::logger->Log("AddStripMessage", "number of actions %i", actionsToAdd.size());
}