diff --git a/src/app/commands/cmd_crop.cpp b/src/app/commands/cmd_crop.cpp index 03a80498f..e73b05b0d 100644 --- a/src/app/commands/cmd_crop.cpp +++ b/src/app/commands/cmd_crop.cpp @@ -104,12 +104,7 @@ AutocropSpriteCommand::AutocropSpriteCommand() void AutocropSpriteCommand::onLoadParams(const app::Params& params) { - m_byGrid = false; - if (params.has_param("byGrid")) { - std::string isByGrid = params.get("byGrid"); - if (isByGrid == "true") - m_byGrid = true; - } + m_byGrid = params.get_as("byGrid"); } bool AutocropSpriteCommand::onEnabled(Context* context) diff --git a/src/app/commands/cmd_flatten_layers.cpp b/src/app/commands/cmd_flatten_layers.cpp index cf28e5675..0a0487ac5 100644 --- a/src/app/commands/cmd_flatten_layers.cpp +++ b/src/app/commands/cmd_flatten_layers.cpp @@ -44,8 +44,7 @@ FlattenLayersCommand::FlattenLayersCommand() void FlattenLayersCommand::onLoadParams(const Params& params) { - std::string visibleOnly = params.get("visibleOnly"); - m_visibleOnly = (visibleOnly == "true"); + m_visibleOnly = params.get_as("visibleOnly"); } bool FlattenLayersCommand::onEnabled(Context* context) diff --git a/src/app/commands/cmd_new_layer.cpp b/src/app/commands/cmd_new_layer.cpp index 8e486bcb3..148a28a6a 100644 --- a/src/app/commands/cmd_new_layer.cpp +++ b/src/app/commands/cmd_new_layer.cpp @@ -79,17 +79,17 @@ void NewLayerCommand::onLoadParams(const Params& params) { m_name = params.get("name"); m_type = Type::Layer; - if (params.get("group") == "true") + if (params.get_as("group")) m_type = Type::Group; - else if (params.get("reference") == "true") + else if (params.get_as("reference")) m_type = Type::ReferenceLayer; - m_ask = (params.get("ask") == "true"); - m_fromFile = (params.get("from-file") == "true"); + m_ask = params.get_as("ask"); + m_fromFile = params.get_as("from-file"); m_place = Place::AfterActiveLayer; - if (params.get("top") == "true") + if (params.get_as("top")) m_place = Place::Top; - else if (params.get("before") == "true") + else if (params.get_as("before")) m_place = Place::BeforeActiveLayer; } diff --git a/src/app/commands/cmd_open_file.cpp b/src/app/commands/cmd_open_file.cpp index 3edac0934..43a9a5234 100644 --- a/src/app/commands/cmd_open_file.cpp +++ b/src/app/commands/cmd_open_file.cpp @@ -85,8 +85,8 @@ void OpenFileCommand::onLoadParams(const Params& params) { m_filename = params.get("filename"); m_folder = params.get("folder"); // Initial folder - m_repeatCheckbox = (params.get("repeat_checkbox") == "true"); - m_oneFrame = (params.get("oneframe") == "true"); + m_repeatCheckbox = params.get_as("repeat_checkbox"); + m_oneFrame = params.get_as("oneframe"); std::string sequence = params.get("sequence"); if (m_oneFrame || sequence == "skip") diff --git a/src/app/commands/cmd_palette_editor.cpp b/src/app/commands/cmd_palette_editor.cpp index dc3523798..3c356e934 100644 --- a/src/app/commands/cmd_palette_editor.cpp +++ b/src/app/commands/cmd_palette_editor.cpp @@ -45,7 +45,7 @@ void PaletteEditorCommand::onLoadParams(const Params& params) m_edit = (params.empty() || params.get("edit") == "switch" || - params.get("switch") == "true"); // "switch" for backward compatibility + params.get_as("switch")); // "switch" for backward compatibility m_popup = (!params.get("popup").empty()); m_background = (params.get("popup") == "background"); } diff --git a/src/app/commands/cmd_save_file.cpp b/src/app/commands/cmd_save_file.cpp index e8bf16ea8..feb3355fb 100644 --- a/src/app/commands/cmd_save_file.cpp +++ b/src/app/commands/cmd_save_file.cpp @@ -115,8 +115,7 @@ void SaveFileBaseCommand::onLoadParams(const Params& params) std::string useUI = params.get("useUI"); m_useUI = (useUI.empty() || (useUI == "true")); - std::string ignoreEmpty = params.get("ignoreEmpty"); - m_ignoreEmpty = (ignoreEmpty == "true"); + m_ignoreEmpty = params.get_as("ignoreEmpty"); } // Returns true if there is a current sprite to save. diff --git a/src/app/commands/cmd_timeline.cpp b/src/app/commands/cmd_timeline.cpp index 0eb9ac2fe..f31aadb14 100644 --- a/src/app/commands/cmd_timeline.cpp +++ b/src/app/commands/cmd_timeline.cpp @@ -44,17 +44,9 @@ TimelineCommand::TimelineCommand() void TimelineCommand::onLoadParams(const Params& params) { - std::string open_str = params.get("open"); - if (open_str == "true") m_open = true; - else m_open = false; - - std::string close_str = params.get("close"); - if (close_str == "true") m_close = true; - else m_close = false; - - std::string switch_str = params.get("switch"); - if (switch_str == "true") m_switch = true; - else m_switch = false; + m_open = params.get_as("open"); + m_close = params.get_as("close"); + m_switch = params.get_as("switch"); } void TimelineCommand::onExecute(Context* context) diff --git a/src/app/commands/params.h b/src/app/commands/params.h index df4d2ee55..8a4a6452d 100644 --- a/src/app/commands/params.h +++ b/src/app/commands/params.h @@ -72,6 +72,17 @@ namespace app { Map m_params; }; + template<> + inline const bool Params::get_as(const char* name) const { + bool value = false; + auto it = m_params.find(name); + if (it != m_params.end()) { + value = (it->second == "1" || + it->second == "true"); + } + return value; + } + } // namespace app #endif