diff options
-rw-r--r-- | compat/debug.cpp | 12 | ||||
-rw-r--r-- | compat/debug.hpp | 14 | ||||
-rw-r--r-- | wall-tileset-tool/main.cpp | 23 |
3 files changed, 27 insertions, 22 deletions
diff --git a/compat/debug.cpp b/compat/debug.cpp index a3c2ba25..0a77d298 100644 --- a/compat/debug.cpp +++ b/compat/debug.cpp @@ -8,11 +8,11 @@ namespace floormat::detail::corrade_debug { -Debug& operator<<(Debug& dbg, Colon) +Debug& operator<<(Debug& dbg, Colon box) { auto flags = dbg.flags(); dbg.setFlags(flags | Debug::Flag::NoSpace); - dbg << ":"; + dbg << StringView{&box.c, 1}; dbg.setFlags(flags); return dbg; } @@ -33,15 +33,13 @@ Debug::Flags quoted_begin(Debug& dbg, char c) auto flags = dbg.flags(); dbg << ""; dbg.setFlags(flags | Debug::Flag::NoSpace); - char buf[2] { c, '\0' }; - dbg << buf; + dbg << StringView{&c, 1}; return flags; } Debug& quoted_end(Debug& dbg, Debug::Flags flags, char c) { - char buf[2] { c, '\0' }; - dbg << buf; + dbg << StringView{&c, 1}; dbg.setFlags(flags); return dbg; } @@ -54,7 +52,7 @@ namespace floormat { using namespace floormat::detail::corrade_debug; -Colon colon() { return Colon{}; } +Colon colon(char c) { return Colon{c}; } ErrorString error_string(int error) { return { error }; } ErrorString error_string() { return { errno }; } diff --git a/compat/debug.hpp b/compat/debug.hpp index 56db4b0f..4de2e5ea 100644 --- a/compat/debug.hpp +++ b/compat/debug.hpp @@ -15,7 +15,7 @@ concept DebugPrintable = requires(Debug& dbg, const T& value) { namespace floormat::detail::corrade_debug { // ***** colon ***** -struct Colon {}; +struct Colon { char c; }; Debug& operator<<(Debug& dbg, Colon box); // ***** error string ***** @@ -23,15 +23,15 @@ struct ErrorString { int value; }; Debug& operator<<(Debug& dbg, ErrorString box); // ***** quoted ***** -template<typename T> struct Quoted { const T& value; }; +template<typename T> struct Quoted { const T& value; char c; }; Debug::Flags quoted_begin(Debug& dbg, char c); Debug& quoted_end(Debug& dbg, Debug::Flags flags, char c); template<typename T> Debug& operator<<(Debug& dbg, Quoted<T> box) { - Debug::Flags flags = quoted_begin(dbg, '\''); + Debug::Flags flags = quoted_begin(dbg, box.c); dbg << box.value; - return quoted_end(dbg, flags, '\''); + return quoted_end(dbg, flags, box.c); } } // namespace floormat::detail::corrade_debug @@ -42,9 +42,11 @@ template<typename T> Debug& operator<<(Debug& dbg, Quoted<T> box) namespace floormat { -floormat::detail::corrade_debug::Colon colon(); +floormat::detail::corrade_debug::Colon colon(char c = ':'); floormat::detail::corrade_debug::ErrorString error_string(int error); floormat::detail::corrade_debug::ErrorString error_string(); -template<DebugPrintable T> floormat::detail::corrade_debug::Quoted<T> quoted(const T& value) { return { value }; } + +template<DebugPrintable T> floormat::detail::corrade_debug::Quoted<T> quoted(const T& value, char c = '\'') { return { value, c }; } +template<DebugPrintable T> floormat::detail::corrade_debug::Quoted<T> quoted2(const T& value) { return { value, '"' }; } } // namespace floormat diff --git a/wall-tileset-tool/main.cpp b/wall-tileset-tool/main.cpp index 8fc463c8..ac4a7498 100644 --- a/wall-tileset-tool/main.cpp +++ b/wall-tileset-tool/main.cpp @@ -69,13 +69,15 @@ Direction& get_direction(wall_atlas_def& atlas, size_t i) return const_cast<Direction&>(get_direction(const_cast<const wall_atlas_def&>(atlas), i)); } -bool do_group(state st, size_t i, size_t j) +bool do_group(state st, size_t i, size_t j, Group& new_dir) { const wall_atlas_def& old_atlas = st.old_atlas; wall_atlas_def& new_atlas = st.new_atlas; const auto& old_dir = get_direction(old_atlas, (size_t)i); //auto& new_dir = get_direction(new_atlas, (size_t)i); + DBG << " group" << quoted2(Direction::groups[j].str); + return true; } @@ -83,7 +85,7 @@ bool do_direction(state& st, size_t i) { const auto name = wall_atlas::directions[i].name; auto& atlas = st.new_atlas; - DBG << "-" << name; + DBG << " direction" << quoted2(name); const auto& old_dir = get_direction(st.old_atlas, i); @@ -99,9 +101,9 @@ bool do_direction(state& st, size_t i) .passability = old_dir.passability, }; - for (auto [_str, _ptr, tag] : Direction::groups) + for (auto [_str, ptr, tag] : Direction::groups) { - if (!do_group(st, i, (size_t)tag)) + if (!do_group(st, i, (size_t)tag, dir.*ptr)) return false; } @@ -112,7 +114,7 @@ bool do_direction(state& st, size_t i) bool do_input_file(state& st) { - DBG << "input-file" << quoted(st.old_atlas.header.name); + DBG << "input" << quoted(st.old_atlas.header.name) << colon(',') << quoted(st.opts.input_file); fm_assert(!st.buffer.empty()); fm_assert(loader.check_atlas_name(st.old_atlas.header.name)); @@ -150,20 +152,23 @@ inline String fixsep(String str) Triple<options, Arguments, bool> parse_cmdline(int argc, const char* const* argv) noexcept { Corrade::Utility::Arguments args{}; - args.addOption('o', "output"s).setHelp("output"s, ""s, "DIR"s); + args.addOption('o', "output"s, "\0"_s).setHelp("output"s, ""_s, "DIR"s); args.addArgument("input.json"s); args.parse(argc, argv); options opts; - opts.output_dir = Path::join(loader.startup_directory(), fixsep(args.value<StringView>("output"))); opts.input_file = Path::join(loader.startup_directory(), fixsep(args.value<StringView>("input.json"))); opts.input_dir = Path::split(opts.input_file).first(); + if (auto val = args.value<StringView>("output"); val != "\0"_s) + opts.output_dir = Path::join(loader.startup_directory(), fixsep(args.value<StringView>("output"))); + else + opts.output_dir = opts.input_dir; if (opts.output_dir.isEmpty()) opts.output_dir = opts.input_dir; - DBG << "input-dir" << colon() << quoted(opts.input_dir); - DBG << "output-dir" << colon() << quoted(opts.output_dir); + //DBG << "input-dir" << opts.input_dir; + //DBG << "output-dir" << opts.output_dir; if (!Path::exists(opts.input_file)) Error{Error::Flag::NoSpace} << "fatal: input file '" << opts.input_file << "' doesn't exist"; |