16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

Editor settings for New/Legacy camera controll

This commit is contained in:
2026-06-16 23:53:01 +02:00
parent 1aac9b4e76
commit 3bed2212d7
9 changed files with 178 additions and 12 deletions

77
editor/editorSettings.cpp Normal file
View File

@@ -0,0 +1,77 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "editor/editorSettings.hpp"
#include "utilities/Logs.h"
#include <cstdlib>
#include <filesystem>
#include <fstream>
editorSettings EditorSettings;
namespace
{
namespace fs = std::filesystem;
fs::path settings_path()
{
#ifdef _WIN32
if (const char *appdata = std::getenv("APPDATA"))
return fs::path(appdata) / "MaSzyna" / "eu07_editor.ini";
#else
if (const char *home = std::getenv("HOME"))
return fs::path(home) / ".config" / "MaSzyna" / "eu07_editor.ini";
#endif
return fs::path("eu07_editor.ini");
}
const char *scheme_to_string(editorSettings::movement_scheme scheme)
{
return scheme == editorSettings::movement_scheme::legacy ? "legacy" : "wsad";
}
}
bool editorSettings::load()
{
const fs::path path = settings_path();
std::error_code ec;
if (!fs::exists(path, ec))
return false;
std::ifstream stream(path);
if (!stream.is_open())
return false;
std::string key, value;
while (stream >> key >> value)
{
if (key == "movement_scheme")
m_movement = (value == "legacy") ? movement_scheme::legacy : movement_scheme::wsad;
}
return true;
}
bool editorSettings::save()
{
const fs::path path = settings_path();
std::error_code ec;
fs::create_directories(path.parent_path(), ec);
std::ofstream stream(path, std::ios::trunc);
if (!stream.is_open())
{
ErrorLog("failed to save editor settings");
return false;
}
stream << "movement_scheme " << scheme_to_string(m_movement) << "\n";
return true;
}

26
editor/editorSettings.hpp Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
class editorSettings
{
public:
// camera movement key scheme in the editor
enum class movement_scheme
{
wsad, // new default: W/S/A/D + E/Q
legacy // old scheme: arrows + Page Up/Down
};
editorSettings() = default;
bool load();
bool save();
movement_scheme movement() const { return m_movement; }
void movement(movement_scheme scheme) { m_movement = scheme; }
private:
movement_scheme m_movement{movement_scheme::wsad};
};
// global editor settings instance
extern editorSettings EditorSettings;