From abecc37c17f4415b003927dbf4519cbb635e69ed Mon Sep 17 00:00:00 2001 From: James De Ricco Date: Fri, 19 Jul 2024 12:25:49 -0400 Subject: [PATCH] Extract item_process_music_help into its own file --- src/editor/object_settings.cpp | 44 +------------------ ...u_filesystem_item_processor_music_help.cpp | 44 +++++++++++++++++++ ...u_filesystem_item_processor_music_help.hpp | 11 +++++ 3 files changed, 57 insertions(+), 42 deletions(-) create mode 100644 src/gui/menu_filesystem_item_processor_music_help.cpp create mode 100644 src/gui/menu_filesystem_item_processor_music_help.hpp diff --git a/src/editor/object_settings.cpp b/src/editor/object_settings.cpp index 6666996d91f..3555eac2a54 100644 --- a/src/editor/object_settings.cpp +++ b/src/editor/object_settings.cpp @@ -19,9 +19,7 @@ #include #include -#include "audio/sound_file.hpp" -#include "fmt/format.h" -#include "util/file_system.hpp" +#include "gui/menu_filesystem_item_processor_music_help.hpp" #include "util/gettext.hpp" #include "video/color.hpp" @@ -298,45 +296,7 @@ ObjectSettings::add_music(const std::string& text, std::string* value_ptr, std::optional default_value, unsigned int flags) { - auto item_processor = [](MenuItem& item, const std::string& file_path, bool in_basedir) - { - std::unique_ptr sound_file; - try { - sound_file = load_sound_file(file_path); - } catch (...) { - item.set_help(""); - return; - } - - const std::vector& authors = sound_file->m_authors; - const std::string& license = sound_file->m_license; - const std::string& title = sound_file->m_title; - - if (title.empty() && authors.empty() && license.empty()) { - item.set_help(""); - return; - } - - const std::string filename = FileSystem::basename(file_path); - const std::string title_or_filename_line = title.empty() ? filename : "\"" + title + "\""; // assumes path is just a filename - - std::string author_lines = ""; - - for (const std::string& author : authors) { - author_lines.append("\n" + fmt::format(fmt::runtime(_("Author") +": {}"), author)); - } - - const std::string license_line = fmt::format(fmt::runtime(_("License") + ": {}"), license); - - const std::string help_text = - title_or_filename_line - + author_lines - + (license.empty() ? "" : "\n" + license_line); - - item.set_help(help_text); - }; - - add_file(text, value_ptr, key, std::move(default_value), {".music"}, {"/music"}, false, flags, item_processor); + add_file(text, value_ptr, key, std::move(default_value), {".music"}, {"/music"}, false, flags, item_processor_music_help); } void diff --git a/src/gui/menu_filesystem_item_processor_music_help.cpp b/src/gui/menu_filesystem_item_processor_music_help.cpp new file mode 100644 index 00000000000..cc149b3b562 --- /dev/null +++ b/src/gui/menu_filesystem_item_processor_music_help.cpp @@ -0,0 +1,44 @@ +#include "gui/menu_filesystem_item_processor_music_help.hpp" + +#include "fmt/format.h" +#include "util/file_system.hpp" +#include "util/gettext.hpp" + +void item_processor_music_help(MenuItem& menu_item, const std::string& file_path, bool in_basedir) { + std::unique_ptr sound_file; + try { + sound_file = load_sound_file(file_path); + } catch (...) { + menu_item.set_help(""); + return; + } + + const std::vector& authors = sound_file->m_authors; + const std::string& license = sound_file->m_license; + const std::string& title = sound_file->m_title; + + if (title.empty() && authors.empty() && license.empty()) { + menu_item.set_help(""); + return; + } + + const std::string filename = FileSystem::basename(file_path); + const std::string title_or_filename_line = title.empty() ? filename : "\"" + title + "\""; // assumes path is just a filename + + std::string author_lines = ""; + + for (const std::string& author : authors) { + author_lines.append("\n" + fmt::format(fmt::runtime(_("Author") +": {}"), author)); + } + + const std::string license_line = fmt::format(fmt::runtime(_("License") + ": {}"), license); + + const std::string help_text = + title_or_filename_line + + author_lines + + (license.empty() ? "" : "\n" + license_line); + + menu_item.set_help(help_text); +} + +/* EOF */ diff --git a/src/gui/menu_filesystem_item_processor_music_help.hpp b/src/gui/menu_filesystem_item_processor_music_help.hpp new file mode 100644 index 00000000000..c5c854e5af0 --- /dev/null +++ b/src/gui/menu_filesystem_item_processor_music_help.hpp @@ -0,0 +1,11 @@ +#ifndef HEADER_SUPERTUX_GUI_MENU_FILESYSTEM_ITEM_PROCESSOR_MUSIC_HELP_HPP +#define HEADER_SUPERTUX_GUI_MENU_FILESYSTEM_ITEM_PROCESSOR_MUSIC_HELP_HPP + +#include "audio/sound_file.hpp" +#include "gui/menu_item.hpp" + +void item_processor_music_help(MenuItem& menu_item, const std::string& file_path, bool in_basedir); + +#endif + +/* EOF */