2023-02-16 17:30:33 +00:00
|
|
|
#include "Action.h"
|
2024-01-03 13:34:38 +00:00
|
|
|
#include "Amf3.h"
|
2023-02-16 17:30:33 +00:00
|
|
|
|
2024-05-18 09:05:55 +00:00
|
|
|
#include "tinyxml2.h"
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
Action::Action(const AMFArrayValue& arguments) {
|
|
|
|
for (const auto& [paramName, paramValue] : arguments.GetAssociative()) {
|
2024-01-03 13:34:38 +00:00
|
|
|
if (paramName == "Type") {
|
|
|
|
if (paramValue->GetValueType() != eAmf::String) continue;
|
2024-11-19 02:45:24 +00:00
|
|
|
m_Type = static_cast<AMFStringValue*>(paramValue.get())->GetValue();
|
2023-02-16 17:30:33 +00:00
|
|
|
} else {
|
2024-02-18 06:38:26 +00:00
|
|
|
m_ValueParameterName = paramName;
|
2023-02-16 17:30:33 +00:00
|
|
|
// Message is the only known string parameter
|
2024-02-18 06:38:26 +00:00
|
|
|
if (m_ValueParameterName == "Message") {
|
2024-01-03 13:34:38 +00:00
|
|
|
if (paramValue->GetValueType() != eAmf::String) continue;
|
2024-11-19 02:45:24 +00:00
|
|
|
m_ValueParameterString = static_cast<AMFStringValue*>(paramValue.get())->GetValue();
|
2023-02-16 17:30:33 +00:00
|
|
|
} else {
|
2024-01-03 13:34:38 +00:00
|
|
|
if (paramValue->GetValueType() != eAmf::Double) continue;
|
2024-11-19 02:45:24 +00:00
|
|
|
m_ValueParameterDouble = static_cast<AMFDoubleValue*>(paramValue.get())->GetValue();
|
2023-02-16 17:30:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-03 13:34:38 +00:00
|
|
|
|
|
|
|
void Action::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
|
2024-02-18 06:38:26 +00:00
|
|
|
auto* const actionArgs = args.PushArray();
|
|
|
|
actionArgs->Insert("Type", m_Type);
|
2024-01-03 13:34:38 +00:00
|
|
|
|
2024-02-18 06:38:26 +00:00
|
|
|
if (m_ValueParameterName.empty()) return;
|
2024-01-03 13:34:38 +00:00
|
|
|
|
2024-02-18 06:38:26 +00:00
|
|
|
if (m_ValueParameterName == "Message") {
|
|
|
|
actionArgs->Insert(m_ValueParameterName, m_ValueParameterString);
|
2024-01-03 13:34:38 +00:00
|
|
|
} else {
|
2024-02-18 06:38:26 +00:00
|
|
|
actionArgs->Insert(m_ValueParameterName, m_ValueParameterDouble);
|
2024-01-03 13:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-18 09:05:55 +00:00
|
|
|
|
|
|
|
void Action::Serialize(tinyxml2::XMLElement& action) const {
|
|
|
|
action.SetAttribute("Type", m_Type.c_str());
|
|
|
|
|
|
|
|
if (m_ValueParameterName.empty()) return;
|
|
|
|
|
2024-05-18 10:36:29 +00:00
|
|
|
action.SetAttribute("ValueParameterName", m_ValueParameterName.c_str());
|
|
|
|
|
2024-05-18 09:05:55 +00:00
|
|
|
if (m_ValueParameterName == "Message") {
|
2024-05-18 10:36:29 +00:00
|
|
|
action.SetAttribute("Value", m_ValueParameterString.c_str());
|
2024-05-18 09:05:55 +00:00
|
|
|
} else {
|
2024-05-18 10:36:29 +00:00
|
|
|
action.SetAttribute("Value", m_ValueParameterDouble);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Action::Deserialize(const tinyxml2::XMLElement& action) {
|
|
|
|
const char* type = nullptr;
|
|
|
|
action.QueryAttribute("Type", &type);
|
|
|
|
if (!type) {
|
|
|
|
LOG("No type found for an action?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Type = type;
|
|
|
|
|
|
|
|
const char* valueParameterName = nullptr;
|
|
|
|
action.QueryAttribute("ValueParameterName", &valueParameterName);
|
|
|
|
if (valueParameterName) {
|
|
|
|
m_ValueParameterName = valueParameterName;
|
|
|
|
|
|
|
|
if (m_ValueParameterName == "Message") {
|
|
|
|
const char* value = nullptr;
|
|
|
|
action.QueryAttribute("Value", &value);
|
|
|
|
if (value) {
|
|
|
|
m_ValueParameterString = value;
|
|
|
|
} else {
|
|
|
|
LOG("No value found for an action message?");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
action.QueryDoubleAttribute("Value", &m_ValueParameterDouble);
|
|
|
|
}
|
2024-05-18 09:05:55 +00:00
|
|
|
}
|
|
|
|
}
|