From ea9c5373a5eda4156c36c35987efb24594e476f5 Mon Sep 17 00:00:00 2001 From: Vankata453 <78196474+Vankata453@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:53:31 +0200 Subject: [PATCH] `ReaderMapping::write_compressed`: Remove custom `width` support --- src/object/tilemap.cpp | 2 +- src/util/writer.cpp | 39 +++++++++++---------------------------- src/util/writer.hpp | 2 +- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index 4ebc0d3459..195d90147d 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -211,7 +211,7 @@ TileMap::write_tiles(Writer& writer) const { writer.write("width", m_width); writer.write("height", m_height); - writer.write_compressed("tiles", m_tiles, m_width); + writer.write_compressed("tiles", m_tiles); } void diff --git a/src/util/writer.cpp b/src/util/writer.cpp index 4f096f40b2..888e622a57 100644 --- a/src/util/writer.cpp +++ b/src/util/writer.cpp @@ -249,54 +249,37 @@ Writer::write(const std::string& name, const sexp::Value& value) } void -Writer::write_compressed(const std::string& name, const std::vector& value, int width) +Writer::write_compressed(const std::string& name, const std::vector& value) { indent(); *out << '(' << name; - if (width > 0) - { - *out << "\n"; - indent(); - } - int count = 0; int repeater = 0; unsigned int repeated_value = 0; - for (const auto& i : value) + for (size_t i = 0; i < value.size(); ++i) { - const bool width_limit = (width > 0 && count >= width); - - ++count; - if (repeater > 0 && i == repeated_value) + if (repeater > 0 && value[i] == repeated_value) { ++repeater; } else - { - if (repeater > 1) - *out << -repeater << " " << repeated_value << (width_limit ? "" : " "); - else if (repeater == 1) - *out << repeated_value << (width_limit ? "" : " "); - - repeater = 1; - repeated_value = i; - } - - if (width > 0 && count >= width) { if (repeater > 1) *out << -repeater << " " << repeated_value; else if (repeater == 1) *out << repeated_value; - count = 0; - repeater = 0; - repeated_value = 0; + if (i != value.size() - 1) + *out << " "; - *out << "\n"; - indent(); + repeater = 1; + repeated_value = value[i]; } } + if (repeater > 1) + *out << " " << -repeater << " " << repeated_value; + else if (repeater == 1) + *out << " " << repeated_value; *out << ")\n"; } diff --git a/src/util/writer.hpp b/src/util/writer.hpp index 693e37b3cd..144ee947b2 100644 --- a/src/util/writer.hpp +++ b/src/util/writer.hpp @@ -51,7 +51,7 @@ class Writer final // add more write-functions when needed... // Writes vector by using negative integer values as repeaters for repeating values. - void write_compressed(const std::string& name, const std::vector& value, int width = 0); + void write_compressed(const std::string& name, const std::vector& value); void end_list(const std::string& listname);