diff options
| author | Crystalwarrior <Varsash@Gmail.com> | 2022-07-27 22:43:50 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-27 21:43:50 +0200 |
| commit | f40b3d162da708e77bea2836701b867060ce9f6d (patch) | |
| tree | 40145b6fedce55623372326ac5933cde5f477ee5 /src/aoutils.cpp | |
| parent | b9e9e029778e3feb63bfab47157e46496cbcbafa (diff) | |
Code to support effects ini version 2 (#813)
* Code to support effects ini version 2
* Update theme commit
* Get it to actually work properly
* Rework effect loading code
* Added auto-migration to new format
* Reorganised code for improved readability and clarity
* Add functional checks for operation to not run into missing file issues
* Minor logic fix
* Add debug message
* Trim any empty items from the list
* Add mandatory culling
* See https://discord.com/channels/278529040497770496/323377366997008394/998661402669617233
* Reworked implementation
* Resolve warning of temporary container allocation
* Unbreak what I broke last commit
* Also make it a QStringLiteral to cheat clazy.
* Set default layer
* Ignore that for realization, that one covers the screen.
* Document migration regex
* This should clarify the ambiguity of its functionality and reason why it exists.
Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com>
Co-authored-by: TrickyLeifa <date.epoch@gmail.com>
Diffstat (limited to 'src/aoutils.cpp')
| -rw-r--r-- | src/aoutils.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/aoutils.cpp b/src/aoutils.cpp new file mode 100644 index 00000000..ee2e90b3 --- /dev/null +++ b/src/aoutils.cpp @@ -0,0 +1,87 @@ +#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(); +} |
