atrooney-online-2/src/aoutils.cpp
TrickyLeifa c9f52b7223 Ported to CMake, ...
* Ported the project to CMake
  * Android and Mac support dropped for the time
being.
  * Tests, BASS and Discord-RPC are now options
* Restructured and reformated the project.
  * Merged `include` and `src`
  * Renamed `resource` to `data`
  * Renamed various files
  * External libraries headers are no longer included in `src`
  * Replaced header guards with #pragma once
  * Multiple refactors (keywords, headers)
  * Added Qt6 compatibility
* Removed various unused functions and headers
* Reworked AOPacket
  * When content is passed to AOPacket, it should be ensured that the content is already decoded.
  * Encoding/decoding are now static methods.
* Fixed various memory leaks
* Removed animation code for AOImage
  * AOImage is always using static images
* Simplified ChatLogPiece
2024-05-15 00:04:16 +02:00

89 lines
2.7 KiB
C++

#include "aoutils.h"
#include <QDebug>
#include <QMap>
#include <QPair>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QSettings>
void AOUtils::migrateEffects(QSettings &p_effects_ini)
{
qDebug() << "Migrating effects from file:" << p_effects_ini.fileName();
QMap<QString, QString> l_effect_map;
{
const QStringList l_key_list = p_effects_ini.childKeys();
for (const QString &i_key : l_key_list)
{
l_effect_map.insert(i_key, p_effects_ini.value(i_key).toString());
}
p_effects_ini.clear();
p_effects_ini.sync();
}
// update revision
p_effects_ini.beginGroup("version");
p_effects_ini.setValue("major", "2");
p_effects_ini.endGroup();
const QStringList l_property_list{
"sound",
"scaling",
"stretch",
"ignore_offset",
"under_chatbox",
};
const QMap<QString, QPair<QString, QString>> l_property_replacement_list{
{"under_chatbox", {"layer", "character"}},
};
QStringList l_key_list;
// Matches old effects.ini childKeys that are not the effect name, but a property that applies to an effect.
// This is due to the name also being used as a key to apply the sfx property.
// Example :
// realization_scaling - This would not be appended to the key_list as it matches scaling property.
// realization_alt - This would be appened as it contains an underscore, but not a property.
// hearts - This would be appended as it does not contain a property
const QRegularExpression l_regex(QStringLiteral("(\\w+)_(%1)$").arg(l_property_list.join("|")));
for (auto i = l_effect_map.begin(); i != l_effect_map.end(); i++)
{
if (l_regex.match(i.key()).hasMatch())
{
continue;
}
l_key_list.append(i.key());
}
int i = 0;
for (const QString &i_effect_key : qAsConst(l_key_list))
{
p_effects_ini.beginGroup(QString::number(i++));
p_effects_ini.setValue("name", i_effect_key);
p_effects_ini.setValue("sound", l_effect_map.value(i_effect_key));
p_effects_ini.setValue("cull", true);
p_effects_ini.setValue("layer", "character");
if (i_effect_key == "realization")
{
p_effects_ini.setValue("stretch", true);
p_effects_ini.setValue("layer", "chat");
}
for (const QString &i_property : l_property_list)
{
const QString l_property_key = QString("%1_%2").arg(i_effect_key, i_property);
if (l_effect_map.contains(l_property_key))
{
const QString l_property_value = l_effect_map.value(l_property_key);
const auto [l_converted_key, l_converted_value] = l_property_replacement_list.value(i_property, {i_property, l_property_value});
p_effects_ini.setValue(l_converted_key, l_converted_value);
}
}
p_effects_ini.endGroup();
}
p_effects_ini.sync();
}