From a9e9e4fd0f969785ed4c6de3eb48b536d4aa53ab Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Mon, 6 Apr 2020 22:06:14 +0200 Subject: [PATCH] added some converter functions --- ScStwLibraries/ScStw.cpp | 37 +++++++++++++++++++++++++++++++++++++ ScStwLibraries/ScStw.hpp | 13 +++++++++++++ 2 files changed, 50 insertions(+) diff --git a/ScStwLibraries/ScStw.cpp b/ScStwLibraries/ScStw.cpp index a9bf9bb..bcfa78c 100644 --- a/ScStwLibraries/ScStw.cpp +++ b/ScStwLibraries/ScStw.cpp @@ -2,3 +2,40 @@ const char *ScStw::SOCKET_MESSAGE_START_KEY = ""; const char *ScStw::SOCKET_MESSAGE_END_KEY = ""; + +const QMap ScStw::baseStationSettings = { + {"ReadySoundEnable", ScStw::ReadySoundEnableSetting}, + {"ReadySoundDelay", ScStw::ReadySoundDelaySetting}, + {"AtYourMarksSoundEnable", ScStw::AtYourMarksSoundEnableSetting}, + {"AtYourMarksSoundDelay", ScStw::AtYourMarksSoundDelaySetting}, + {"SoundVolume", ScStw::SoundVolumeSetting} +}; + +ScStw::BaseStationSetting ScStw::baseStationSettingFromString(QString s) { + if(!ScStw::baseStationSettings.contains(s)) + return ScStw::InvalidSetting; + + return ScStw::baseStationSettings[s]; +} + +QString ScStw::baseStationSettingToString(ScStw::BaseStationSetting s) { + for(QString key: ScStw::baseStationSettings.keys()) { + if(ScStw::baseStationSettings[key] == s) + return key; + } + return "Invalid"; +} + +ScStw::BaseStationSetting ScStw::baseStationSettingfromInt(int i) { + if(i < 0 || i > 4) + return InvalidSetting; + else + return BaseStationSetting(i); +} + +ScStw::SignalKey ScStw::signalKeyFromInt(int i) { + if(i < 9000 || i > 9003) + return InvalidSignal; + else + return SignalKey(i); +} diff --git a/ScStwLibraries/ScStw.hpp b/ScStwLibraries/ScStw.hpp index 97f98a2..9ca0759 100644 --- a/ScStwLibraries/ScStw.hpp +++ b/ScStwLibraries/ScStw.hpp @@ -2,6 +2,7 @@ #define SCSTW_HPP #include +#include class ScStw : public QObject { Q_OBJECT @@ -14,6 +15,7 @@ public: Q_ENUM(RaceState) enum SignalKey { + InvalidSignal = -1, RaceStateChanged = 9000, TimersChanged = 9001, ExtensionsChanged = 9002, @@ -25,6 +27,7 @@ public: Q_ENUM(NextStartAction) enum BaseStationSetting { + InvalidSetting = -1, ReadySoundEnableSetting, ReadySoundDelaySetting, AtYourMarksSoundEnableSetting, @@ -46,6 +49,16 @@ public: static const char* SOCKET_MESSAGE_START_KEY; static const char* SOCKET_MESSAGE_END_KEY; + static const QMap baseStationSettings; + + static BaseStationSetting baseStationSettingfromInt(int i); + + static BaseStationSetting baseStationSettingFromString(QString s); + + static QString baseStationSettingToString(BaseStationSetting s); + + static SignalKey signalKeyFromInt(int i); + private: ScStw() : QObject(nullptr) {}; };