////////////////////////////////////////////////////////////////////////////// // This file is part of the Journey MMORPG client // // Copyright © 2015-2016 Daniel Allendorf // // // // This program is free software: you can redistribute it and/or modify // // it under the terms of the GNU Affero General Public License as // // published by the Free Software Foundation, either version 3 of the // // License, or (at your option) any later version. // // // // This program is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU Affero General Public License for more details. // // // // You should have received a copy of the GNU Affero General Public License // // along with this program. If not, see . // ////////////////////////////////////////////////////////////////////////////// #pragma once #include "Template/Point.h" #include "Template/Singleton.h" #include "Template/TypeMap.h" #include "Util/Misc.h" #include #include #include #include namespace jrc { // Manages the 'Settings' file which contains configurations set by user behaviour. class Configuration : public Singleton { public: // Add the settings which will be used and load them. Configuration(); // Save. ~Configuration(); // Load all settings. If something is missing, set the default value. Can be used for reloading. void load(); // Save the current settings. void save() const; // Base class for an entry in the settings file. class Entry { protected: Entry(const char* n, const char* v) : name(n), value(v) {} std::string name; std::string value; private: friend class Configuration; std::string to_string() const { return name + " = " + value; } }; // Setting which converts to a bool. class BoolEntry : public Entry { public: void save(bool b); bool load() const; protected: using Entry::Entry; }; // Setting which uses the raw string. class StringEntry : public Entry { public: void save(std::string str); std::string load() const; protected: using Entry::Entry; }; // Setting which converts to a Point. class PointEntry : public Entry { public: void save(Point p); Point load() const; protected: using Entry::Entry; }; // Setting which converts to an integer type. template class IntegerEntry : public Entry { public: void save(T num) { value = std::to_string(num); } T load() const { return string_conversion::or_zero(value); } protected: using Entry::Entry; }; // Setting which converts to a byte. class ByteEntry : public IntegerEntry { protected: using IntegerEntry::IntegerEntry; }; // Setting which converts to a short. class ShortEntry : public IntegerEntry { protected: using IntegerEntry::IntegerEntry; }; // Setting which converts to an int. class IntEntry : public IntegerEntry { protected: using IntegerEntry::IntegerEntry; }; // Setting which converts to a long. class LongEntry : public IntegerEntry { protected: using IntegerEntry::IntegerEntry; }; private: template friend struct Setting; const char* FILENAME = "Settings"; TypeMap settings; }; // IP Adress which the client will connect to. struct MapleStoryServerIp : public Configuration::StringEntry { MapleStoryServerIp() : StringEntry("MapleStoryServerIp", "127.0.0.1") {} }; // Port which the client will connect to. struct MapleStoryServerPort : public Configuration::StringEntry { MapleStoryServerPort() : StringEntry("MapleStoryServerPort", "8484") {} }; // WebSocket Proxy IP struct ProxyIP : public Configuration::StringEntry { ProxyIP() : StringEntry("ProxyIP", "") {} }; // WebSocket Proxy Port struct ProxyPort : public Configuration::StringEntry { ProxyPort() : StringEntry("ProxyPort", "8080") {} }; // WebSocket / WSS protocol struct AssetsServerProtocol : public Configuration::StringEntry { AssetsServerProtocol() : StringEntry("AssetsServerProtocol", "ws") {} }; // Wether to start in fullscreen mode. struct Fullscreen : public Configuration::BoolEntry { Fullscreen() : BoolEntry("Fullscreen", "false") {} }; // Wether to use vsync. struct VSync : public Configuration::BoolEntry { VSync() : BoolEntry("VSync", "true") {} }; // The normal font which will be used. struct FontPathNormal : public Configuration::StringEntry { FontPathNormal() : StringEntry("FontPathNormal", "/fonts/Arial/Arial.ttf") {} }; // The bold font which will be used. struct FontPathBold : public Configuration::StringEntry { FontPathBold() : StringEntry("FontPathBold", "/fonts/Arial/Arial-Bold.ttf") {} }; // Music Volume, a number from 0 to 100. struct BGMVolume : public Configuration::ByteEntry { BGMVolume() : ByteEntry("BGMVolume", "50") {} }; // Sound Volume, a number from 0 to 100. struct SFXVolume : public Configuration::ByteEntry { SFXVolume() : ByteEntry("SFXVolume", "50") {} }; // Wether to save the last used account name. struct SaveLogin : public Configuration::BoolEntry { SaveLogin() : BoolEntry("SaveLogin", "false") {} }; // The last used account name. struct DefaultAccount : public Configuration::StringEntry { DefaultAccount() : StringEntry("Account", "") {} }; // The last used world. struct DefaultWorld : public Configuration::ByteEntry { DefaultWorld() : ByteEntry("World", "0") {} }; // The last used channel. struct DefaultChannel : public Configuration::ByteEntry { DefaultChannel() : ByteEntry("Channel", "0") {} }; // The last used character. struct DefaultCharacter : public Configuration::ByteEntry { DefaultCharacter() : ByteEntry("Character", "0") {} }; // The default position of the character stats inventory. struct PosSTATS : public Configuration::PointEntry { PosSTATS() : PointEntry("PosSTATS", "(100,150)") {} }; // The default position of the equip inventory. struct PosEQINV : public Configuration::PointEntry { PosEQINV() : PointEntry("PosEQINV", "(250,150)") {} }; // The default position of the item inventory. struct PosINV : public Configuration::PointEntry { PosINV() : PointEntry("PosINV", "(300,150)") {} }; // The default position of the skill inventory. struct PosSKILL : public Configuration::PointEntry { PosSKILL() : PointEntry("PosSKILL", "(50,150)") {} }; struct PosKEYCONFIG : public Configuration::PointEntry { PosKEYCONFIG() : PointEntry("PosKEYCONFIG", "(144,144)") {} }; // The default position of the quest log. struct PosQUEST : public Configuration::PointEntry { PosQUEST() : PointEntry("PosQUEST", "(200,100)") {} }; struct PosQUESTHELPER : public Configuration::PointEntry { // Unset positions use the screen's right edge on first opening. PosQUESTHELPER() : PointEntry("PosQUESTHELPER", "(-1,-1)") {} }; struct PosPARTY : public Configuration::PointEntry { PosPARTY() : PointEntry("PosPARTY", "(160,120)") {} }; struct PosMAP : public Configuration::PointEntry { PosMAP() : PointEntry("PosMAP", "(124,2)") {} }; struct PosMINIMAP : public Configuration::PointEntry { PosMINIMAP() : PointEntry("PosMINIMAP", "(0,0)") {} }; struct MiniMapType : public Configuration::ByteEntry { MiniMapType() : ByteEntry("MiniMapType", "2") {} }; struct MiniMapSimpleMode : public Configuration::BoolEntry { MiniMapSimpleMode() : BoolEntry("MiniMapSimpleMode", "false") {} }; struct MiniMapDefaultHelpers : public Configuration::BoolEntry { MiniMapDefaultHelpers() : BoolEntry("MiniMapDefaultHelpers", "false") {} }; // Can be used to access settings. template struct Setting { // Access a setting. static T& get() { static_assert( std::is_base_of::value, "template parameter T for Setting must inherit from Configuration::Entry." ); auto* entry = Configuration::get().settings.get(); if (entry) { return *entry; } else { static T defaultentry; return defaultentry; } } }; }