'dynamic' namespace refactor + sensitivity is a NumberSetting now
This commit is contained in:
@@ -608,7 +608,7 @@ void WorldFiles::removePack(const World* world, const std::string& id) {
|
||||
if (name.find(prefix) != 0)
|
||||
continue;
|
||||
auto value = blocks->getValueWriteable(i);
|
||||
*value->value.str = "core:air";
|
||||
value->value = "core:air";
|
||||
}
|
||||
|
||||
auto items = root->list("items");
|
||||
@@ -617,7 +617,7 @@ void WorldFiles::removePack(const World* world, const std::string& id) {
|
||||
if (name.find(prefix) != 0)
|
||||
continue;
|
||||
auto value = items->getValueWriteable(i);
|
||||
*value->value.str = "core:empty";
|
||||
value->value = "core:empty";
|
||||
}
|
||||
files::write_json(getIndicesFile(), root.get());
|
||||
}
|
||||
|
||||
@@ -9,7 +9,33 @@
|
||||
#include "../coders/toml.h"
|
||||
#include "../coders/json.h"
|
||||
|
||||
#include "../data/dynamic.h"
|
||||
SettingsHandler::SettingsHandler(EngineSettings& settings) {
|
||||
map.emplace("audio.volume-master", &settings.audio.volumeMaster);
|
||||
map.emplace("audio.volume-regular", &settings.audio.volumeRegular);
|
||||
map.emplace("audio.volume-ui", &settings.audio.volumeUI);
|
||||
map.emplace("audio.volume-ambient", &settings.audio.volumeAmbient);
|
||||
map.emplace("audio.volume-music", &settings.audio.volumeMusic);
|
||||
|
||||
map.emplace("camera.sensitivity", &settings.camera.sensitivity);
|
||||
}
|
||||
|
||||
dynamic::Value SettingsHandler::getValue(std::string name) const {
|
||||
using dynamic::valtype;
|
||||
|
||||
auto found = map.find(name);
|
||||
if (found == map.end()) {
|
||||
return dynamic::Value(valtype::none, 0);
|
||||
}
|
||||
auto setting = found->second;
|
||||
if (auto number = dynamic_cast<NumberSetting<float>*>(setting)) {
|
||||
return dynamic::Value(valtype::number, number->get());
|
||||
} else if (auto number = dynamic_cast<NumberSetting<double>*>(setting)) {
|
||||
return dynamic::Value(valtype::number, number->get());
|
||||
}
|
||||
|
||||
return dynamic::Value(valtype::none, 0);
|
||||
}
|
||||
|
||||
|
||||
toml::Wrapper* create_wrapper(EngineSettings& settings) {
|
||||
std::unique_ptr<toml::Wrapper> wrapper (new toml::Wrapper());
|
||||
@@ -38,7 +64,7 @@ toml::Wrapper* create_wrapper(EngineSettings& settings) {
|
||||
camera.add("fov-effects", &settings.camera.fovEvents);
|
||||
camera.add("fov", &settings.camera.fov);
|
||||
camera.add("shaking", &settings.camera.shaking);
|
||||
camera.add("sensitivity", &settings.camera.sensitivity);
|
||||
camera.add("sensitivity", &*settings.camera.sensitivity);
|
||||
|
||||
toml::Section& graphics = wrapper->add("graphics");
|
||||
graphics.add("gamma", &settings.graphics.gamma);
|
||||
|
||||
+11
-1
@@ -2,14 +2,24 @@
|
||||
#define FILES_SETTINGS_IO_H_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "../settings.h"
|
||||
#include "../data/dynamic.h"
|
||||
|
||||
namespace toml {
|
||||
class Wrapper;
|
||||
}
|
||||
|
||||
class SettingsHandler {
|
||||
std::unordered_map<std::string, Setting*> map;
|
||||
public:
|
||||
SettingsHandler(EngineSettings& settings);
|
||||
|
||||
dynamic::Value getValue(std::string name) const;
|
||||
};
|
||||
|
||||
extern std::string write_controls();
|
||||
extern toml::Wrapper* create_wrapper(EngineSettings& settings);
|
||||
extern void load_controls(std::string filename, std::string source);
|
||||
|
||||
#endif // FILES_SETTINGS_IO_H_
|
||||
#endif // FILES_SETTINGS_IO_H_
|
||||
|
||||
Reference in New Issue
Block a user