From 362c332000a65acc060660dcb6bb0ec6f99cbafe Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 1 Feb 2021 13:14:40 -0500 Subject: Tileset dumper can now export to Tiled --- tools/sprite_dumper/identifier.h | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tools/sprite_dumper/identifier.h (limited to 'tools/sprite_dumper/identifier.h') diff --git a/tools/sprite_dumper/identifier.h b/tools/sprite_dumper/identifier.h new file mode 100644 index 0000000..74d83ce --- /dev/null +++ b/tools/sprite_dumper/identifier.h @@ -0,0 +1,59 @@ +#ifndef IDENTIFIER_H_D7EE5679 +#define IDENTIFIER_H_D7EE5679 + +#include +#include + +template +class identifier { +public: + + using value_type = T; + +private: + + using vector_type = std::vector; + +public: + + using key_type = typename vector_type::size_type; + + key_type add(const value_type& val) + { + auto it = ids_.find(val); + + if (it == std::end(ids_)) + { + key_type ret = ids_.size(); + ids_[val] = ret; + + uniq_.push_back(val); + + return ret; + } else { + return it->second; + } + } + + void compile() + { + ids_.clear(); + } + + inline const value_type& get(key_type i) const + { + return uniq_.at(i); + } + + inline key_type size() const + { + return uniq_.size(); + } + +private: + + std::map ids_; + vector_type uniq_; +}; + +#endif /* end of include guard: IDENTIFIER_H_D7EE5679 */ -- cgit 1.4.1