summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--migration/20160906_0-mappings.cpp100
1 files changed, 95 insertions, 5 deletions
diff --git a/migration/20160906_0-mappings.cpp b/migration/20160906_0-mappings.cpp
index 0ff3095a..89c78a9d 100644
--- a/migration/20160906_0-mappings.cpp
+++ b/migration/20160906_0-mappings.cpp
@@ -1,14 +1,104 @@
#include "migration.hpp"
+#include "logic/mappings.hpp"
+#include "logic/main-settings.hpp"
+#include "options/group.hpp"
+
+#include <QPointF>
+#include <QList>
+
+#include <memory>
#include <QDebug>
using namespace migrations;
-struct foo : migration
+struct mappings_from_2_3_0_rc11 : migration
{
- const QString& unique_date() const override { qDebug() << "foo"; static QString ret(""); return ret; }
- bool should_run() const override { qDebug() << "bar"; return false; }
- bool run() override { return false; }
+ static QList<QList<QPointF>> get_old_splines()
+ {
+ QList<QList<QPointF>> ret;
+
+ static const char* names[] =
+ {
+ "tx", "tx_alt",
+ "ty", "ty_alt",
+ "tz", "tz_alt",
+ "rx", "rx_alt",
+ "ry", "ry_alt",
+ "rz", "rz_alt",
+ };
+
+ std::shared_ptr<QSettings> settings_ = options::group::ini_file();
+ QSettings& settings(*settings_);
+
+ for (const char* name : names)
+ {
+ QList<QPointF> points;
+
+ settings.beginGroup(QString("Curves-%1").arg(name));
+
+ const int max = settings.value("point-count", 0).toInt();
+
+ for (int i = 0; i < max; i++)
+ {
+ QPointF new_point(settings.value(QString("point-%1-x").arg(i), 0).toDouble(),
+ settings.value(QString("point-%1-y").arg(i), 0).toDouble());
+
+ points.append(new_point);
+ }
+
+ settings.endGroup();
+
+ ret.append(points);
+ }
+
+ return ret;
+ }
+
+ QString unique_date() const override { return "20160909_00"; }
+ QString name() const override { return "Migrate mappings to 2.3.0-rc12"; }
+
+ static Mappings get_new_mappings()
+ {
+ main_settings s;
+ return Mappings(std::vector<axis_opts*>{&s.a_x, &s.a_y, &s.a_z, &s.a_yaw, &s.a_pitch, &s.a_roll});
+ }
+
+ bool should_run() const override
+ {
+ Mappings m = get_new_mappings();
+
+ // run only if no new splines were set
+ for (int i = 0; i < 6; i++)
+ if (m(i).spline_main.get_point_count() || m(i).spline_alt.get_point_count())
+ return false;
+
+ // run only if old splines exist
+ for (const QList<QPointF>& points : get_old_splines())
+ if (points.size())
+ return true;
+
+ // no splines exit at all
+ return false;
+ }
+ void run() override
+ {
+ const QList<QList<QPointF>> old_mappings = get_old_splines();
+ Mappings m = get_new_mappings();
+
+ std::shared_ptr<QSettings> s_ = options::group::ini_file();
+ QSettings& s = *s_;
+
+ for (int i = 0; i < 12; i++)
+ {
+ spline& spl = (i % 2) == 0 ? m(i / 2).spline_main : m(i / 2).spline_alt;
+ spl.removeAllPoints();
+ const QList<QPointF>& points = old_mappings[i];
+ for (const QPointF& pt : points)
+ spl.addPoint(pt);
+ spl.save(s);
+ }
+ }
};
-OPENTRACK_MIGRATION(foo);
+OPENTRACK_MIGRATION(mappings_from_2_3_0_rc11);