forked from AttorneyOnline/AO2-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoutils.cpp
More file actions
88 lines (77 loc) · 2.74 KB
/
aoutils.cpp
File metadata and controls
88 lines (77 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#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();
}