2020-12-24 13:48:22 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "raw_mouse_config.h"
|
|
|
|
|
#include "Emu/Io/MouseHandler.h"
|
|
|
|
|
|
2025-01-09 23:32:27 +01:00
|
|
|
LOG_CHANNEL(cfg_log, "CFG");
|
|
|
|
|
|
2024-05-20 14:43:17 +02:00
|
|
|
cfg::string& raw_mouse_config::get_button_by_index(int index)
|
|
|
|
|
{
|
|
|
|
|
switch (index)
|
|
|
|
|
{
|
|
|
|
|
case 0: return mouse_button_1;
|
|
|
|
|
case 1: return mouse_button_2;
|
|
|
|
|
case 2: return mouse_button_3;
|
|
|
|
|
case 3: return mouse_button_4;
|
|
|
|
|
case 4: return mouse_button_5;
|
|
|
|
|
case 5: return mouse_button_6;
|
|
|
|
|
case 6: return mouse_button_7;
|
|
|
|
|
case 7: return mouse_button_8;
|
|
|
|
|
default: fmt::throw_exception("Invalid index %d", index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 13:48:22 +01:00
|
|
|
cfg::string& raw_mouse_config::get_button(int code)
|
|
|
|
|
{
|
|
|
|
|
switch (code)
|
|
|
|
|
{
|
|
|
|
|
case CELL_MOUSE_BUTTON_1: return mouse_button_1;
|
|
|
|
|
case CELL_MOUSE_BUTTON_2: return mouse_button_2;
|
|
|
|
|
case CELL_MOUSE_BUTTON_3: return mouse_button_3;
|
|
|
|
|
case CELL_MOUSE_BUTTON_4: return mouse_button_4;
|
|
|
|
|
case CELL_MOUSE_BUTTON_5: return mouse_button_5;
|
|
|
|
|
case CELL_MOUSE_BUTTON_6: return mouse_button_6;
|
|
|
|
|
case CELL_MOUSE_BUTTON_7: return mouse_button_7;
|
|
|
|
|
case CELL_MOUSE_BUTTON_8: return mouse_button_8;
|
|
|
|
|
default: fmt::throw_exception("Invalid code %d", code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 22:12:26 +01:00
|
|
|
std::string raw_mouse_config::get_button_name(std::string_view value)
|
|
|
|
|
{
|
|
|
|
|
if (raw_mouse_button_map.contains(value))
|
|
|
|
|
{
|
|
|
|
|
return std::string(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string raw_mouse_config::get_button_name(s32 button_code)
|
|
|
|
|
{
|
|
|
|
|
for (const auto& [name, code] : raw_mouse_button_map)
|
|
|
|
|
{
|
|
|
|
|
if (code == button_code)
|
|
|
|
|
{
|
|
|
|
|
return std::string(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 13:48:22 +01:00
|
|
|
raw_mice_config::raw_mice_config()
|
|
|
|
|
{
|
|
|
|
|
for (u32 i = 0; i < ::size32(players); i++)
|
|
|
|
|
{
|
|
|
|
|
players.at(i) = std::make_shared<raw_mouse_config>(this, fmt::format("Player %d", i + 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool raw_mice_config::load()
|
|
|
|
|
{
|
|
|
|
|
m_mutex.lock();
|
|
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
|
const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id);
|
|
|
|
|
cfg_log.notice("Loading %s config: %s", cfg_id, cfg_name);
|
|
|
|
|
|
|
|
|
|
from_default();
|
|
|
|
|
|
|
|
|
|
if (fs::file cfg_file{ cfg_name, fs::read })
|
|
|
|
|
{
|
2024-11-05 22:34:38 +01:00
|
|
|
if (const std::string content = cfg_file.to_string(); !content.empty())
|
2020-12-24 13:48:22 +01:00
|
|
|
{
|
|
|
|
|
result = from_string(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_mutex.unlock();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_mutex.unlock();
|
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void raw_mice_config::save()
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard lock(m_mutex);
|
|
|
|
|
|
|
|
|
|
const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id);
|
|
|
|
|
cfg_log.notice("Saving %s config to '%s'", cfg_id, cfg_name);
|
|
|
|
|
|
|
|
|
|
if (!fs::create_path(fs::get_parent_dir(cfg_name)))
|
|
|
|
|
{
|
|
|
|
|
cfg_log.fatal("Failed to create path: %s (%s)", cfg_name, fs::g_tls_error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!cfg::node::save(cfg_name))
|
|
|
|
|
{
|
|
|
|
|
cfg_log.error("Failed to save %s config to '%s' (error=%s)", cfg_id, cfg_name, fs::g_tls_error);
|
|
|
|
|
}
|
2024-06-26 18:57:41 +02:00
|
|
|
|
|
|
|
|
reload_requested = true;
|
2020-12-24 13:48:22 +01:00
|
|
|
}
|