Skip to content

Commit

Permalink
solve the problem of nxengine#282
Browse files Browse the repository at this point in the history
  • Loading branch information
s0587670 authored and s0587670 committed Jun 14, 2024
1 parent 58cf086 commit e48ccb4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@

#include "settings.h"
#include "json.hpp" // Für die Handhabung von JSON in C++
#include <fstream>
#include <iostream>

using json = nlohmann::json;

std::map<std::string, std::string> keyboardBindings;
std::map<std::string, std::string> gamepadBindings;

void loadSettings() {
std::ifstream i("config.json");
if (!i.is_open()) {
std::cerr << "Fehler: Konnte config.json nicht öffnen" << std::endl;
return;
}
json config;
i >> config;
keyboardBindings = config["keyboard"].get<std::map<std::string, std::string>>();
gamepadBindings = config["gamepad"].get<std::map<std::string, std::string>>();
}

void saveSettings() {
json config;
config["keyboard"] = keyboardBindings;
config["gamepad"] = gamepadBindings;
std::ofstream o("config.json");
if (!o.is_open()) {
std::cerr << "Fehler: Konnte config.json nicht zum Schreiben öffnen" << std::endl;
return;
}
o << config.dump(4);
}

#include "ResourceManager.h"
#include "common/misc.h"
Expand Down Expand Up @@ -149,3 +181,4 @@ bool settings_save(Settings *setfile)
fclose(fp);
return 0;
}

0 comments on commit e48ccb4

Please sign in to comment.