added save and load of keysmap in keymapper

This commit is contained in:
Lendemor 2018-05-20 19:59:13 +02:00
parent 13add53503
commit 7b91e32361
2 changed files with 15 additions and 1 deletions

View File

@ -5,9 +5,13 @@
#include "SparrowInput/input.h"
#include "defaultkeysmap.h"
#include <iostream>
#include <fstream>
#include <cereal/cereal.hpp>
#include <cereal/archives/json.hpp>
KeyMapper::KeyMapper() :
m_enabled(false),
m_keymap_file("keymap.json"),
m_waiting_for_input(-1)
{
// mapping between action numerical value and text value
@ -190,8 +194,17 @@ void KeyMapper::gui()
getEngine().getInput()->updateKeyBindings();
}
//save
if(ImGui::Button("Save Keymap")){
std::ofstream os(m_keymap_file);
cereal::JSONOutputArchive output(os);
output(m_keysmap);
}
//load
if(ImGui::Button("Load Keymap")){
std::ifstream is(m_keymap_file);
cereal::JSONInputArchive input(is);
// input(m_keysmap);
}
ImGui::End();
}

View File

@ -11,6 +11,7 @@ class KeyMapper : public SceneNode
bool m_enabled;
int m_selected_context;
IKeysMap m_keysmap;
std::string m_keymap_file;
std::map<int,std::string> m_mouse_buttons;
std::map<int,std::string> m_keyboard_keys;