From 01c6604fef366d4ecf3abd697fa26815438b726e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 16 Oct 2022 11:41:17 +0200 Subject: a --- main/editor.cpp | 17 +++++++++++++++++ main/editor.hpp | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'main') 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 #include @@ -25,6 +26,22 @@ void tile_type::load_atlases() _atlases[name] = std::move(atlas); } } +std::shared_ptr 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_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 atlas(Containers::StringView str); + std::shared_ptr maybe_atlas(Containers::StringView str); + std::shared_ptr 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> _atlases; + std::map> _atlases; void load_atlases(); }; -- cgit v1.2.3