summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-16 11:41:17 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-16 11:41:17 +0200
commit01c6604fef366d4ecf3abd697fa26815438b726e (patch)
treecea3a557ca6a17b0e899f93adfaf32fd45c707cb /main
parenta6bb7a8338abb294096743fddd55f11aa239aa57 (diff)
a
Diffstat (limited to 'main')
-rw-r--r--main/editor.cpp17
-rw-r--r--main/editor.hpp5
2 files changed, 20 insertions, 2 deletions
diff --git a/main/editor.cpp b/main/editor.cpp
index 4b291ea6..a83100c2 100644
--- a/main/editor.cpp
+++ b/main/editor.cpp
@@ -2,6 +2,7 @@
#include "serialize/json-helper.hpp"
#include "serialize/tile-atlas.hpp"
#include "src/loader.hpp"
+#include "compat/assert.hpp"
#include <filesystem>
#include <vector>
@@ -25,6 +26,22 @@ void tile_type::load_atlases()
_atlases[name] = std::move(atlas);
}
}
+std::shared_ptr<tile_atlas> tile_type::maybe_atlas(Containers::StringView str)
+{
+ auto it = _atlases.find(str);
+ if (it == _atlases.end())
+ return nullptr;
+ else
+ return it->second;
+}
+
+std::shared_ptr<tile_atlas> tile_type::atlas(Containers::StringView str)
+{
+ if (auto ptr = maybe_atlas(str); ptr)
+ return ptr;
+ else
+ ABORT("no such atlas: %s", str.cbegin());
+}
editor_state::editor_state()
{
diff --git a/main/editor.hpp b/main/editor.hpp
index 993d057a..a971f821 100644
--- a/main/editor.hpp
+++ b/main/editor.hpp
@@ -14,7 +14,8 @@ enum class editor_mode : unsigned char {
struct tile_type final
{
tile_type(Containers::StringView name);
- std::shared_ptr<struct tile_atlas> atlas(Containers::StringView str);
+ std::shared_ptr<tile_atlas> maybe_atlas(Containers::StringView str);
+ std::shared_ptr<tile_atlas> atlas(Containers::StringView str);
auto begin() & { return _atlases.begin(); }
auto end() & { return _atlases.end(); }
auto begin() const&& { return _atlases.cbegin(); }
@@ -25,7 +26,7 @@ struct tile_type final
private:
std::string _name;
- std::map<std::string, std::shared_ptr<struct tile_atlas>> _atlases;
+ std::map<std::string, std::shared_ptr<tile_atlas>> _atlases;
void load_atlases();
};