mirror of https://github.com/OpenRCT2/OpenRCT2.git
Use interface for config enum
This commit is contained in:
parent
d8fae61e0c
commit
0542338d4d
|
@ -500,7 +500,7 @@ bool config_save_default()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool config_open_2(const utf8string path)
|
||||
static bool config_open_2(const utf8string path)
|
||||
{
|
||||
SDL_RWops *file;
|
||||
utf8string lineBuffer;
|
||||
|
|
|
@ -17,17 +17,19 @@
|
|||
#include <memory>
|
||||
#include "../core/Exception.hpp"
|
||||
#include "../interface/window.h"
|
||||
#include "../localisation/language.h"
|
||||
#include "../network/network.h"
|
||||
#include "IniReader.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../config.h"
|
||||
#include "../localisation/language.h"
|
||||
}
|
||||
|
||||
namespace Config
|
||||
{
|
||||
#pragma region Enums
|
||||
|
||||
static auto Enum_MeasurementFormat = ConfigEnum<sint32>(
|
||||
{
|
||||
ConfigEnumEntry<sint32>("IMPERIAL", MEASUREMENT_FORMAT_IMPERIAL),
|
||||
|
@ -64,12 +66,6 @@ namespace Config
|
|||
ConfigEnumEntry<sint32>("SUFFIX", CURRENCY_SUFFIX),
|
||||
});
|
||||
|
||||
static auto Enum_CurrencySymbolAffix = ConfigEnum<sint32>(
|
||||
{
|
||||
ConfigEnumEntry<sint32>("PREFIX", CURRENCY_PREFIX),
|
||||
ConfigEnumEntry<sint32>("SUFFIX", CURRENCY_SUFFIX),
|
||||
});
|
||||
|
||||
static auto Enum_DateFormat = ConfigEnum<sint32>(
|
||||
{
|
||||
ConfigEnumEntry<sint32>("DD/MM/YY", DATE_FORMAT_DMY),
|
||||
|
@ -91,9 +87,33 @@ namespace Config
|
|||
ConfigEnumEntry<sint32>("FAHRENHEIT", TEMPERATURE_FORMAT_F),
|
||||
});
|
||||
|
||||
static auto Enum_LanguageEnum = ConfigEnum<sint32>(
|
||||
/**
|
||||
* Config enum wrapping LanguagesDescriptors.
|
||||
*/
|
||||
static class LanguageConfigEnum final : public IConfigEnum<sint32>
|
||||
{
|
||||
});
|
||||
public:
|
||||
std::string GetName(sint32 value) const override
|
||||
{
|
||||
return LanguagesDescriptors[value].locale;
|
||||
}
|
||||
|
||||
sint32 GetValue(const std::string &key, sint32 defaultValue) const override
|
||||
{
|
||||
sint32 i = 0;
|
||||
for (const auto &langDesc : LanguagesDescriptors)
|
||||
{
|
||||
if (String::Equals(key.c_str(), langDesc.locale))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
} Enum_LanguageEnum;
|
||||
|
||||
#pragma endregion
|
||||
|
||||
static void ReadGeneral(IIniReader * reader)
|
||||
{
|
||||
|
@ -162,7 +182,7 @@ namespace Config
|
|||
model->last_save_landscape_directory = reader->GetCString("last_landscape_directory", nullptr);
|
||||
model->last_save_scenario_directory = reader->GetCString("last_scenario_directory", nullptr);
|
||||
model->last_save_track_directory = reader->GetCString("last_track_directory", nullptr);
|
||||
model->window_limit = reader->GetBoolean("window_limit", WINDOW_LIMIT_MAX);
|
||||
model->window_limit = reader->GetSint32("window_limit", WINDOW_LIMIT_MAX);
|
||||
model->zoom_to_cursor = reader->GetBoolean("zoom_to_cursor", true);
|
||||
model->render_weather_effects = reader->GetBoolean("render_weather_effects", true);
|
||||
model->render_weather_gloom = reader->GetBoolean("render_weather_gloom", true);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "../core/String.hpp"
|
||||
|
||||
template<typename T>
|
||||
struct ConfigEnumEntry
|
||||
struct ConfigEnumEntry final
|
||||
{
|
||||
std::string Key;
|
||||
T Value;
|
||||
|
@ -34,7 +34,15 @@ struct ConfigEnumEntry
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
class ConfigEnum
|
||||
interface IConfigEnum
|
||||
{
|
||||
virtual ~IConfigEnum() = default;
|
||||
virtual std::string GetName(T value) const abstract;
|
||||
virtual T GetValue(const std::string &key, T defaultValue) const abstract;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ConfigEnum final : public IConfigEnum<T>
|
||||
{
|
||||
private:
|
||||
std::vector<ConfigEnumEntry<T>> _entries;
|
||||
|
@ -45,9 +53,9 @@ public:
|
|||
_entries = entries;
|
||||
}
|
||||
|
||||
std::string GetName(T value)
|
||||
std::string GetName(T value) const override
|
||||
{
|
||||
for (const auto &entry : _entries) const
|
||||
for (const auto &entry : _entries)
|
||||
{
|
||||
if (entry.Value == value)
|
||||
{
|
||||
|
@ -57,7 +65,7 @@ public:
|
|||
return std::string();
|
||||
}
|
||||
|
||||
T GetValue(const std::string &key, T defaultValue) const
|
||||
T GetValue(const std::string &key, T defaultValue) const override
|
||||
{
|
||||
for (const auto &entry : _entries)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ interface IIniReader
|
|||
virtual bool TryGetString(const std::string &name, std::string * outValue) const abstract;
|
||||
|
||||
template<typename T>
|
||||
T GetEnum(const std::string &name, T defaultValue, const ConfigEnum<T> &configEnum) const
|
||||
T GetEnum(const std::string &name, T defaultValue, const IConfigEnum<T> &configEnum) const
|
||||
{
|
||||
std::string szValue;
|
||||
if (!TryGetString(name, &szValue))
|
||||
|
|
Loading…
Reference in New Issue