Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
map_settings_manager.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include <string>
23#include "settings.h"
24
25struct NoiseParams;
26struct 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*/
46public:
47 MapSettingsManager(const std::string &map_meta_path);
49
50 // Finalized map generation parameters
52
53 bool getMapSetting(const std::string &name, std::string *value_out) const;
54
55 bool getMapSettingNoiseParams(const std::string &name,
56 NoiseParams *value_out) const;
57
58 // Note: Map config becomes read-only after makeMapgenParams() gets called
59 // (i.e. mapgen_params is non-NULL). Attempts to set map config after
60 // params have been finalized will result in failure.
61 bool setMapSetting(const std::string &name,
62 const std::string &value, bool override_meta = false);
63
64 bool setMapSettingNoiseParams(const std::string &name,
65 const NoiseParams *value, bool override_meta = false);
66
67 bool loadMapMeta();
68 bool saveMapMeta();
70
71private:
72 std::string m_map_meta_path;
73
77};
Definition: map_settings_manager.h:45
bool loadMapMeta()
Definition: map_settings_manager.cpp:97
Settings * m_defaults
Definition: map_settings_manager.h:75
bool setMapSetting(const std::string &name, const std::string &value, bool override_meta=false)
Definition: map_settings_manager.cpp:67
bool getMapSettingNoiseParams(const std::string &name, NoiseParams *value_out) const
Definition: map_settings_manager.cpp:59
bool setMapSettingNoiseParams(const std::string &name, const NoiseParams *value, bool override_meta=false)
Definition: map_settings_manager.cpp:82
~MapSettingsManager()
Definition: map_settings_manager.cpp:44
MapgenParams * makeMapgenParams()
Definition: map_settings_manager.cpp:145
MapgenParams * mapgen_params
Definition: map_settings_manager.h:51
Settings * m_map_settings
Definition: map_settings_manager.h:76
std::string m_map_meta_path
Definition: map_settings_manager.h:72
bool getMapSetting(const std::string &name, std::string *value_out) const
Definition: map_settings_manager.cpp:52
SettingsHierarchy m_hierarchy
Definition: map_settings_manager.h:74
bool saveMapMeta()
Definition: map_settings_manager.cpp:116
Definition: settings.h:73
Definition: settings.h:124
Definition: mapgen.h:129
Definition: noise.h:119