From eccebd48ac6c311023052386155d685dadfef202 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 22 Feb 2021 17:39:57 -0500 Subject: Modified map/tileset dumper to coalesce tilesets Multiple map IDs can be provided now and their tilesets will be combined. --- tools/sprite_dumper/identifier.h | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'tools/sprite_dumper/identifier.h') diff --git a/tools/sprite_dumper/identifier.h b/tools/sprite_dumper/identifier.h index 74d83ce..4aac943 100644 --- a/tools/sprite_dumper/identifier.h +++ b/tools/sprite_dumper/identifier.h @@ -5,6 +5,15 @@ #include template +class DefaultKeyExtract { +public: + + const T& operator()(const T& val) const { + return val; + } +}; + +template > class identifier { public: @@ -12,20 +21,21 @@ public: private: + using key_type = std::remove_reference_t>; using vector_type = std::vector; public: - using key_type = typename vector_type::size_type; + using id_type = typename vector_type::size_type; - key_type add(const value_type& val) + id_type add(const value_type& val) { - auto it = ids_.find(val); + auto it = ids_.find(KeyExtract()(val)); if (it == std::end(ids_)) { - key_type ret = ids_.size(); - ids_[val] = ret; + id_type ret = ids_.size(); + ids_[KeyExtract()(val)] = ret; uniq_.push_back(val); @@ -40,19 +50,19 @@ public: ids_.clear(); } - inline const value_type& get(key_type i) const + inline const value_type& get(id_type i) const { return uniq_.at(i); } - inline key_type size() const + inline id_type size() const { return uniq_.size(); } private: - std::map ids_; + std::map ids_; vector_type uniq_; }; -- cgit 1.4.1