diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-01 13:14:40 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-01 13:14:40 -0500 |
commit | 362c332000a65acc060660dcb6bb0ec6f99cbafe (patch) | |
tree | b8f64b23c45e1e016ef708421830e83a0b4bc63c /tools/sprite_dumper/identifier.h | |
parent | e37026ea3b9d7b121aeb1fd38fe81ab82a1e2e33 (diff) | |
download | tanetane-362c332000a65acc060660dcb6bb0ec6f99cbafe.tar.gz tanetane-362c332000a65acc060660dcb6bb0ec6f99cbafe.tar.bz2 tanetane-362c332000a65acc060660dcb6bb0ec6f99cbafe.zip |
Tileset dumper can now export to Tiled
Diffstat (limited to 'tools/sprite_dumper/identifier.h')
-rw-r--r-- | tools/sprite_dumper/identifier.h | 59 |
1 files changed, 59 insertions, 0 deletions
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 @@ | |||
1 | #ifndef IDENTIFIER_H_D7EE5679 | ||
2 | #define IDENTIFIER_H_D7EE5679 | ||
3 | |||
4 | #include <map> | ||
5 | #include <vector> | ||
6 | |||
7 | template <typename T> | ||
8 | class identifier { | ||
9 | public: | ||
10 | |||
11 | using value_type = T; | ||
12 | |||
13 | private: | ||
14 | |||
15 | using vector_type = std::vector<value_type>; | ||
16 | |||
17 | public: | ||
18 | |||
19 | using key_type = typename vector_type::size_type; | ||
20 | |||
21 | key_type add(const value_type& val) | ||
22 | { | ||
23 | auto it = ids_.find(val); | ||
24 | |||
25 | if (it == std::end(ids_)) | ||
26 | { | ||
27 | key_type ret = ids_.size(); | ||
28 | ids_[val] = ret; | ||
29 | |||
30 | uniq_.push_back(val); | ||
31 | |||
32 | return ret; | ||
33 | } else { | ||
34 | return it->second; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | void compile() | ||
39 | { | ||
40 | ids_.clear(); | ||
41 | } | ||
42 | |||
43 | inline const value_type& get(key_type i) const | ||
44 | { | ||
45 | return uniq_.at(i); | ||
46 | } | ||
47 | |||
48 | inline key_type size() const | ||
49 | { | ||
50 | return uniq_.size(); | ||
51 | } | ||
52 | |||
53 | private: | ||
54 | |||
55 | std::map<value_type, key_type> ids_; | ||
56 | vector_type uniq_; | ||
57 | }; | ||
58 | |||
59 | #endif /* end of include guard: IDENTIFIER_H_D7EE5679 */ | ||