Fix bone-attached entities (#10015)
[oweals/minetest.git] / src / map_settings_manager.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include <string>
23
24 class Settings;
25 struct NoiseParams;
26 struct MapgenParams;
27
28 /*
29         MapSettingsManager is a centralized object for management (creating,
30         loading, storing, saving, etc.) of config settings related to the Map.
31
32         It has two phases: the initial r/w "gather and modify settings" state, and
33         the final r/o "read and save settings" state.
34
35         The typical use case is, in order, as follows:
36         - Create a MapSettingsManager object
37         - Try to load map metadata into it from the metadata file
38         - Manually view and modify the current configuration as desired through a
39           Settings-like interface
40         - When all modifications are finished, create a 'Parameters' object
41           containing the finalized, active parameters.  This could be passed along
42           to whichever Map-related objects that may require it.
43         - Save these active settings to the metadata file when requested
44 */
45 class MapSettingsManager {
46 public:
47         MapSettingsManager(Settings *user_settings,
48                 const std::string &map_meta_path);
49         ~MapSettingsManager();
50
51         // Finalized map generation parameters
52         MapgenParams *mapgen_params = nullptr;
53
54         bool getMapSetting(const std::string &name, std::string *value_out);
55
56         bool getMapSettingNoiseParams(
57                 const std::string &name, NoiseParams *value_out);
58
59         // Note: Map config becomes read-only after makeMapgenParams() gets called
60         // (i.e. mapgen_params is non-NULL).  Attempts to set map config after
61         // params have been finalized will result in failure.
62         bool setMapSetting(const std::string &name,
63                 const std::string &value, bool override_meta = false);
64
65         bool setMapSettingNoiseParams(const std::string &name,
66                 const NoiseParams *value, bool override_meta = false);
67
68         bool loadMapMeta();
69         bool saveMapMeta();
70         MapgenParams *makeMapgenParams();
71
72 private:
73         std::string m_map_meta_path;
74         Settings *m_map_settings;
75         Settings *m_user_settings;
76 };