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:
jadebenn
2024-02-18 00:38:26 -06:00
committed by GitHub
parent c7b3d9e817
commit b6af92ef81
46 changed files with 362 additions and 341 deletions

View File

@@ -63,7 +63,7 @@ void ControlBehaviors::SendBehaviorListToClient(const ControlBehaviorContext& co
// TODO This is also supposed to serialize the state of the behaviors in progress but those aren't implemented yet
void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& context) {
if (!context) return;
BehaviorMessageBase behaviorMsg(context.arguments);
BehaviorMessageBase behaviorMsg{ context.arguments };
context.modelComponent->VerifyBehaviors();
AMFArrayValue behavior;
@@ -71,8 +71,8 @@ void ControlBehaviors::SendBehaviorBlocksToClient(ControlBehaviorContext& contex
GameMessages::SendUIMessageServerToSingleClient(context.modelOwner, context.modelOwner->GetSystemAddress(), "UpdateBehaviorBlocks", behavior);
}
void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) {
UpdateActionMessage updateActionMessage(arguments);
void ControlBehaviors::UpdateAction(const AMFArrayValue* arguments) {
UpdateActionMessage updateActionMessage{ arguments };
auto blockDefinition = GetBlockInfo(updateActionMessage.GetAction().GetType());
if (!blockDefinition) {
@@ -95,18 +95,18 @@ void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) {
}
}
void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress& sysAddr, AMFArrayValue* arguments, std::string command, Entity* modelOwner) {
void ControlBehaviors::ProcessCommand(Entity* modelEntity, AMFArrayValue* arguments, std::string& command, Entity* modelOwner) {
if (!isInitialized || !modelEntity || !modelOwner || !arguments) return;
auto* modelComponent = modelEntity->GetComponent<ModelComponent>();
auto* const modelComponent = modelEntity->GetComponent<ModelComponent>();
if (!modelComponent) return;
ControlBehaviorContext context(arguments, modelComponent, modelOwner);
ControlBehaviorContext context{ arguments, modelComponent, modelOwner };
if (command == "sendBehaviorListToClient") {
SendBehaviorListToClient(context);
} else if (command == "modelTypeChanged") {
auto* modelType = arguments->Get<double>("ModelType");
auto* const modelType = arguments->Get<double>("ModelType");
if (!modelType) return;
modelEntity->SetVar<int>(u"modelType", modelType->GetValue());
@@ -131,7 +131,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress&
} else if (command == "rearrangeStrip") {
context.modelComponent->HandleControlBehaviorsMsg<RearrangeStripMessage>(arguments);
} else if (command == "add") {
AddMessage msg(context.arguments);
AddMessage msg{ context.arguments };
context.modelComponent->AddBehavior(msg);
SendBehaviorListToClient(context);
} else if (command == "removeActions") {
@@ -144,7 +144,7 @@ void ControlBehaviors::ProcessCommand(Entity* modelEntity, const SystemAddress&
} else if (command == "sendBehaviorBlocksToClient") {
SendBehaviorBlocksToClient(context);
} else if (command == "moveToInventory") {
MoveToInventoryMessage msg(arguments);
MoveToInventoryMessage msg{ arguments };
context.modelComponent->MoveToInventory(msg);
auto* characterComponent = modelOwner->GetComponent<CharacterComponent>();
if (!characterComponent) return;
@@ -239,7 +239,7 @@ ControlBehaviors::ControlBehaviors() {
if (values) {
auto* value = values->FirstChildElement("Value");
while (value) {
if (value->GetText() == blockDefinition.GetDefaultValue()) blockDefinition.GetDefaultValue() = std::to_string(blockDefinition.GetMaximumValue());
if (value->GetText() == blockDefinition.GetDefaultValue()) blockDefinition.SetDefaultValue(std::to_string(blockDefinition.GetMaximumValue()));
blockDefinition.SetMaximumValue(blockDefinition.GetMaximumValue() + 1);
value = value->NextSiblingElement("Value");
}
@@ -283,7 +283,7 @@ ControlBehaviors::ControlBehaviors() {
}
}
std::optional<BlockDefinition> ControlBehaviors::GetBlockInfo(const BlockName& blockName) {
std::optional<BlockDefinition> ControlBehaviors::GetBlockInfo(const std::string& blockName) {
auto blockDefinition = blockTypes.find(blockName);
return blockDefinition != blockTypes.end() ? std::optional(blockDefinition->second) : std::nullopt;
}