This repository has been archived by the owner on Jul 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Configuration.h
174 lines (155 loc) · 5.85 KB
/
Configuration.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//////////////////////////////////////////////////////////////////////////////
// This file is part of the LibreMaple MMORPG client //
// Copyright © 2018-2019 LibreMaple Team //
// //
// 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 <http://www.gnu.org/licenses/>. //
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "Template/Point.h"
#include "cpptoml.h"
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
namespace jrc
{
//! Manages the "settings.toml" file which contains configurations set by user
//! behavior.
//!
//! The format of this `struct` is in 1:1 correspondence with the format of the
//! "settings.toml".
//!
//! TODO: Almost all of this code can be generated based on the default
//! "settings.toml".
struct Configuration : public Singleton<Configuration> {
//! Initialize settings using defaults, and then load as much as possible
//! from "settings.toml".
Configuration() noexcept;
//! Automatically save on destruction.
~Configuration() noexcept override;
//! Load all settings. If anything is missing, the defaults are used. Can
//! be used for reloading.
//!
//! **Throws** cpptoml exceptions.
void load() noexcept(false);
//! Save the current settings.
void save() const noexcept;
enum class PositionOf {
KEY_CONFIG,
STATS,
INVENTORY,
EQUIP_INVENTORY,
SKILLBOOK,
CHANGE_CHANNEL,
GAME_SETTINGS,
SYSTEM_SETTINGS
};
[[nodiscard]] Point<std::int16_t> get_position_of(PositionOf po) const
noexcept;
void set_position_of(PositionOf po, Point<std::int16_t> pos) noexcept;
//////////////// Data layout ////////////////
struct Network {
std::string ip = "127.0.0.1";
std::uint16_t port = 8484;
};
struct Video {
bool fullscreen = false;
bool vsync = true;
bool low_quality = false;
};
struct Fonts {
std::string normal = "../fonts/Roboto/Roboto-Regular.ttf";
std::string bold = "../fonts/Roboto/Roboto-Bold.ttf";
};
struct Audio {
struct Volume // Volumes are in percentages.
{
std::uint8_t sound_effects = 50;
std::uint8_t music = 50;
};
bool sound_effects = true;
bool music = true;
Volume volume;
};
struct Account {
std::string account_name = "";
std::uint8_t world = 0;
std::uint8_t channel = 0;
std::uint8_t character = 0;
bool save_login = false;
};
struct Ui {
struct Position {
Point<std::int16_t> key_config = {150, 150};
Point<std::int16_t> stats = {100, 150};
Point<std::int16_t> inventory = {300, 150};
Point<std::int16_t> equip_inventory = {250, 150};
Point<std::int16_t> skillbook = {50, 150};
Point<std::int16_t> change_channel = {350, 300};
Point<std::int16_t> game_settings = {450, 250};
Point<std::int16_t> system_settings = {350, 150};
};
std::uint8_t hp_alert = 20;
std::uint8_t mp_alert = 20;
bool shake_screen = true;
bool simple_minimap = false;
Position position;
};
struct Character {
struct GameSettings {
//! whispers = true
//! friend_invites = true
//! chat_invites = true
//! trade_requests = true
//! party_invites = true
//! sidekick_invites = true
//! expedition_invites = true
//! guild_chat = true
//! guild_invites = true
//! alliance_chat = true
//! alliance_invites = true
//! family_invites = true
//! follow = true
std::uint16_t flags = 0b00011111'11111111;
};
GameSettings game_settings;
};
// Data members are reordered here for compactness (blame the ABI).
Network network;
Fonts fonts;
Account account;
std::unordered_map<std::string, Character> characters;
Video video;
Audio audio;
Ui ui;
//! Gets a reference to the character-specific configuration for the
//! character identified by name. **Inserts a new character with the**
//! **default configuration if there isn't already one with the specified**
//! **name**.
[[nodiscard]] Character& get_character(const std::string& name) noexcept;
private:
//! Helper function for getting `Point`s out of TOML arrays. Converts the
//! `std::vector`'s elements into a `Point` of another type by using
//! `static_cast` on the elements.
template<typename T>
static std::optional<Point<T>>
vec_to_point(const std::vector<std::int64_t>& vec) noexcept
{
if (vec.size() != 2) {
return {};
}
return {{static_cast<T>(vec[0]), static_cast<T>(vec[1])}};
}
};
} // namespace jrc