tidy-fix automàtic (sense naming)
This commit is contained in:
+119
-55
@@ -1,5 +1,6 @@
|
||||
#include "game/options.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@@ -58,16 +59,21 @@ namespace Options {
|
||||
auto yaml = fkyaml::node::deserialize(content);
|
||||
if (yaml.contains("game")) {
|
||||
const auto& node = yaml["game"];
|
||||
if (node.contains("habitacio_inicial"))
|
||||
if (node.contains("habitacio_inicial")) {
|
||||
game.habitacio_inicial = node["habitacio_inicial"].get_value<int>();
|
||||
if (node.contains("piramide_inicial"))
|
||||
}
|
||||
if (node.contains("piramide_inicial")) {
|
||||
game.piramide_inicial = node["piramide_inicial"].get_value<int>();
|
||||
if (node.contains("vides"))
|
||||
}
|
||||
if (node.contains("vides")) {
|
||||
game.vides = node["vides"].get_value<int>();
|
||||
if (node.contains("diamants_inicial"))
|
||||
}
|
||||
if (node.contains("diamants_inicial")) {
|
||||
game.diamants_inicial = node["diamants_inicial"].get_value<int>();
|
||||
if (node.contains("diners_inicial"))
|
||||
}
|
||||
if (node.contains("diners_inicial")) {
|
||||
game.diners_inicial = node["diners_inicial"].get_value<int>();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (const fkyaml::exception& e) {
|
||||
@@ -80,7 +86,9 @@ namespace Options {
|
||||
// com a punt d'entrada únic per als callsites legacy del menú; el cos
|
||||
// ja no toca jail_audio directament.
|
||||
void applyAudio() {
|
||||
if (::Audio::get() == nullptr) return;
|
||||
if (::Audio::get() == nullptr) {
|
||||
return;
|
||||
}
|
||||
::Audio::get()->enable(audio.enabled);
|
||||
::Audio::get()->enableMusic(audio.music.enabled);
|
||||
::Audio::get()->enableSound(audio.sound.enabled);
|
||||
@@ -91,114 +99,148 @@ namespace Options {
|
||||
// --- Funcions helper de càrrega ---
|
||||
|
||||
static void loadAudioConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("audio")) return;
|
||||
if (!yaml.contains("audio")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["audio"];
|
||||
|
||||
if (node.contains("enabled"))
|
||||
if (node.contains("enabled")) {
|
||||
audio.enabled = node["enabled"].get_value<bool>();
|
||||
}
|
||||
|
||||
if (node.contains("volume"))
|
||||
if (node.contains("volume")) {
|
||||
audio.volume = node["volume"].get_value<float>();
|
||||
}
|
||||
|
||||
if (node.contains("music")) {
|
||||
const auto& music = node["music"];
|
||||
if (music.contains("enabled"))
|
||||
if (music.contains("enabled")) {
|
||||
audio.music.enabled = music["enabled"].get_value<bool>();
|
||||
if (music.contains("volume"))
|
||||
}
|
||||
if (music.contains("volume")) {
|
||||
audio.music.volume = music["volume"].get_value<float>();
|
||||
}
|
||||
}
|
||||
|
||||
if (node.contains("sound")) {
|
||||
const auto& sound = node["sound"];
|
||||
if (sound.contains("enabled"))
|
||||
if (sound.contains("enabled")) {
|
||||
audio.sound.enabled = sound["enabled"].get_value<bool>();
|
||||
if (sound.contains("volume"))
|
||||
}
|
||||
if (sound.contains("volume")) {
|
||||
audio.sound.volume = sound["volume"].get_value<float>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadVideoConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("video")) return;
|
||||
if (!yaml.contains("video")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["video"];
|
||||
|
||||
if (node.contains("gpu_acceleration"))
|
||||
if (node.contains("gpu_acceleration")) {
|
||||
video.gpu_acceleration = node["gpu_acceleration"].get_value<bool>();
|
||||
if (node.contains("shader_enabled"))
|
||||
}
|
||||
if (node.contains("shader_enabled")) {
|
||||
video.shader_enabled = node["shader_enabled"].get_value<bool>();
|
||||
if (node.contains("supersampling"))
|
||||
}
|
||||
if (node.contains("supersampling")) {
|
||||
video.supersampling = node["supersampling"].get_value<bool>();
|
||||
}
|
||||
if (node.contains("scaling_mode")) {
|
||||
auto s = node["scaling_mode"].get_value<std::string>();
|
||||
if (s == "disabled")
|
||||
if (s == "disabled") {
|
||||
video.scaling_mode = ScalingMode::DISABLED;
|
||||
else if (s == "stretch")
|
||||
} else if (s == "stretch") {
|
||||
video.scaling_mode = ScalingMode::STRETCH;
|
||||
else if (s == "letterbox")
|
||||
} else if (s == "letterbox") {
|
||||
video.scaling_mode = ScalingMode::LETTERBOX;
|
||||
else if (s == "overscan")
|
||||
} else if (s == "overscan") {
|
||||
video.scaling_mode = ScalingMode::OVERSCAN;
|
||||
else
|
||||
} else {
|
||||
video.scaling_mode = ScalingMode::INTEGER;
|
||||
}
|
||||
}
|
||||
if (node.contains("vsync"))
|
||||
if (node.contains("vsync")) {
|
||||
video.vsync = node["vsync"].get_value<bool>();
|
||||
if (node.contains("aspect_ratio_4_3"))
|
||||
}
|
||||
if (node.contains("aspect_ratio_4_3")) {
|
||||
video.aspect_ratio_4_3 = node["aspect_ratio_4_3"].get_value<bool>();
|
||||
}
|
||||
if (node.contains("texture_filter")) {
|
||||
auto s = node["texture_filter"].get_value<std::string>();
|
||||
video.texture_filter = (s == "linear") ? TextureFilter::LINEAR : TextureFilter::NEAREST;
|
||||
}
|
||||
if (node.contains("downscale_algo"))
|
||||
if (node.contains("downscale_algo")) {
|
||||
video.downscale_algo = node["downscale_algo"].get_value<int>();
|
||||
}
|
||||
if (node.contains("internal_resolution")) {
|
||||
video.internal_resolution = node["internal_resolution"].get_value<int>();
|
||||
if (video.internal_resolution < 1) video.internal_resolution = 1;
|
||||
video.internal_resolution = std::max(video.internal_resolution, 1);
|
||||
}
|
||||
if (node.contains("current_shader"))
|
||||
if (node.contains("current_shader")) {
|
||||
video.current_shader = node["current_shader"].get_value<std::string>();
|
||||
if (node.contains("current_postfx_preset"))
|
||||
}
|
||||
if (node.contains("current_postfx_preset")) {
|
||||
video.current_postfx_preset = node["current_postfx_preset"].get_value<std::string>();
|
||||
if (node.contains("current_crtpi_preset"))
|
||||
}
|
||||
if (node.contains("current_crtpi_preset")) {
|
||||
video.current_crtpi_preset = node["current_crtpi_preset"].get_value<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
static void loadRenderInfoFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("render_info")) return;
|
||||
if (!yaml.contains("render_info")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["render_info"];
|
||||
|
||||
if (node.contains("position")) {
|
||||
auto pos = node["position"].get_value<std::string>();
|
||||
if (pos == "top")
|
||||
if (pos == "top") {
|
||||
render_info.position = RenderInfoPosition::TOP;
|
||||
else if (pos == "bottom")
|
||||
} else if (pos == "bottom") {
|
||||
render_info.position = RenderInfoPosition::BOTTOM;
|
||||
else
|
||||
} else {
|
||||
render_info.position = RenderInfoPosition::OFF;
|
||||
}
|
||||
}
|
||||
if (node.contains("show_time"))
|
||||
if (node.contains("show_time")) {
|
||||
render_info.show_time = node["show_time"].get_value<bool>();
|
||||
if (node.contains("text_color"))
|
||||
}
|
||||
if (node.contains("text_color")) {
|
||||
render_info.text_color = static_cast<Uint32>(node["text_color"].get_value<uint64_t>());
|
||||
if (node.contains("shadow_color"))
|
||||
}
|
||||
if (node.contains("shadow_color")) {
|
||||
render_info.shadow_color = static_cast<Uint32>(node["shadow_color"].get_value<uint64_t>());
|
||||
}
|
||||
}
|
||||
|
||||
static void loadWindowConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("window")) return;
|
||||
if (!yaml.contains("window")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["window"];
|
||||
|
||||
if (node.contains("zoom"))
|
||||
if (node.contains("zoom")) {
|
||||
window.zoom = node["zoom"].get_value<int>();
|
||||
if (node.contains("fullscreen"))
|
||||
}
|
||||
if (node.contains("fullscreen")) {
|
||||
window.fullscreen = node["fullscreen"].get_value<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: carrega una SDL_Scancode des d'un string (nom SDL de la tecla).
|
||||
static void loadScancodeField(const fkyaml::node& node, const std::string& key, SDL_Scancode& target) {
|
||||
if (!node.contains(key)) return;
|
||||
if (!node.contains(key)) {
|
||||
return;
|
||||
}
|
||||
auto name = node[key].get_value<std::string>();
|
||||
SDL_Scancode sc = SDL_GetScancodeFromName(name.c_str());
|
||||
if (sc != SDL_SCANCODE_UNKNOWN) target = sc;
|
||||
if (sc != SDL_SCANCODE_UNKNOWN) {
|
||||
target = sc;
|
||||
}
|
||||
}
|
||||
|
||||
static void loadControlsFromYaml(const fkyaml::node& yaml) {
|
||||
@@ -212,15 +254,20 @@ namespace Options {
|
||||
}
|
||||
|
||||
static void loadGameConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("game")) return;
|
||||
if (!yaml.contains("game")) {
|
||||
return;
|
||||
}
|
||||
const auto& node = yaml["game"];
|
||||
|
||||
if (node.contains("use_new_logo"))
|
||||
if (node.contains("use_new_logo")) {
|
||||
game.use_new_logo = node["use_new_logo"].get_value<bool>();
|
||||
if (node.contains("show_title_credits"))
|
||||
}
|
||||
if (node.contains("show_title_credits")) {
|
||||
game.show_title_credits = node["show_title_credits"].get_value<bool>();
|
||||
if (node.contains("show_preload"))
|
||||
}
|
||||
if (node.contains("show_preload")) {
|
||||
game.show_preload = node["show_preload"].get_value<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
// Carrega les opcions des del fitxer configurat
|
||||
@@ -334,10 +381,11 @@ namespace Options {
|
||||
file << "render_info:\n";
|
||||
{
|
||||
const char* pos = "off";
|
||||
if (render_info.position == RenderInfoPosition::TOP)
|
||||
if (render_info.position == RenderInfoPosition::TOP) {
|
||||
pos = "top";
|
||||
else if (render_info.position == RenderInfoPosition::BOTTOM)
|
||||
} else if (render_info.position == RenderInfoPosition::BOTTOM) {
|
||||
pos = "bottom";
|
||||
}
|
||||
file << " position: " << pos << " # off/top/bottom\n";
|
||||
}
|
||||
file << " show_time: " << (render_info.show_time ? "true" : "false") << "\n";
|
||||
@@ -438,7 +486,9 @@ namespace Options {
|
||||
if (yaml.contains("presets")) {
|
||||
for (const auto& p : yaml["presets"]) {
|
||||
PostFXPreset preset;
|
||||
if (p.contains("name")) preset.name = p["name"].get_value<std::string>();
|
||||
if (p.contains("name")) {
|
||||
preset.name = p["name"].get_value<std::string>();
|
||||
}
|
||||
parseFloatField(p, "vignette", preset.vignette);
|
||||
parseFloatField(p, "scanlines", preset.scanlines);
|
||||
parseFloatField(p, "chroma", preset.chroma);
|
||||
@@ -497,7 +547,9 @@ namespace Options {
|
||||
if (yaml.contains("presets")) {
|
||||
for (const auto& p : yaml["presets"]) {
|
||||
CrtPiPreset preset;
|
||||
if (p.contains("name")) preset.name = p["name"].get_value<std::string>();
|
||||
if (p.contains("name")) {
|
||||
preset.name = p["name"].get_value<std::string>();
|
||||
}
|
||||
parseFloatField(p, "scanline_weight", preset.scanline_weight);
|
||||
parseFloatField(p, "scanline_gap_brightness", preset.scanline_gap_brightness);
|
||||
parseFloatField(p, "bloom_factor", preset.bloom_factor);
|
||||
@@ -506,24 +558,36 @@ namespace Options {
|
||||
parseFloatField(p, "mask_brightness", preset.mask_brightness);
|
||||
parseFloatField(p, "curvature_x", preset.curvature_x);
|
||||
parseFloatField(p, "curvature_y", preset.curvature_y);
|
||||
if (p.contains("mask_type")) try {
|
||||
if (p.contains("mask_type")) {
|
||||
try {
|
||||
preset.mask_type = p["mask_type"].get_value<int>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_scanlines")) try {
|
||||
}
|
||||
if (p.contains("enable_scanlines")) {
|
||||
try {
|
||||
preset.enable_scanlines = p["enable_scanlines"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_multisample")) try {
|
||||
}
|
||||
if (p.contains("enable_multisample")) {
|
||||
try {
|
||||
preset.enable_multisample = p["enable_multisample"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_gamma")) try {
|
||||
}
|
||||
if (p.contains("enable_gamma")) {
|
||||
try {
|
||||
preset.enable_gamma = p["enable_gamma"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_curvature")) try {
|
||||
}
|
||||
if (p.contains("enable_curvature")) {
|
||||
try {
|
||||
preset.enable_curvature = p["enable_curvature"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
if (p.contains("enable_sharper")) try {
|
||||
}
|
||||
if (p.contains("enable_sharper")) {
|
||||
try {
|
||||
preset.enable_sharper = p["enable_sharper"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
crtpi_presets.push_back(preset);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user