summaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
Diffstat (limited to 'loader')
-rw-r--r--loader/atlas.cpp14
-rw-r--r--loader/impl.hpp3
-rw-r--r--loader/json.cpp10
-rw-r--r--loader/loader.hpp6
4 files changed, 26 insertions, 7 deletions
diff --git a/loader/atlas.cpp b/loader/atlas.cpp
index f285d3b1..1354e922 100644
--- a/loader/atlas.cpp
+++ b/loader/atlas.cpp
@@ -14,15 +14,25 @@
namespace floormat::loader_detail {
-std::shared_ptr<tile_atlas> loader_impl::tile_atlas(StringView name, Vector2ub size) noexcept(false)
+std::shared_ptr<tile_atlas> loader_impl::tile_atlas(StringView name, Vector2ub size, Optional<pass_mode> pass) noexcept(false)
{
fm_soft_assert(check_atlas_name(name));
- const emplacer e{[&] { return std::make_shared<struct tile_atlas>(name, texture(IMAGE_PATH, name), size); }};
+ const emplacer e{[&] { return std::make_shared<struct tile_atlas>(name, texture(IMAGE_PATH, name), size, pass); }};
auto atlas = tile_atlas_map.try_emplace(name, e).first->second;
+ fm_soft_assert(!pass || pass == atlas->pass_mode());
return atlas;
}
+std::shared_ptr<struct tile_atlas> loader_impl::tile_atlas(StringView filename) noexcept(false)
+{
+ fm_assert(!tile_atlas_map.empty());
+ auto it = tile_atlas_map.find(filename);
+ if (it == tile_atlas_map.end())
+ fm_throw("no such tile atlas '{}'"_cf, filename.data());
+ return it->second;
+}
+
ArrayView<String> loader_impl::anim_atlas_list()
{
if (anim_atlases.empty())
diff --git a/loader/impl.hpp b/loader/impl.hpp
index c50cb1d7..673460aa 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -30,7 +30,8 @@ struct loader_impl final : loader_
StringView shader(StringView filename) noexcept override;
Trade::ImageData2D texture(StringView prefix, StringView filename) noexcept(false);
- std::shared_ptr<struct tile_atlas> tile_atlas(StringView filename, Vector2ub size) noexcept(false) override;
+ std::shared_ptr<struct tile_atlas> tile_atlas(StringView filename, Vector2ub size, Optional<pass_mode> pass) noexcept(false) override;
+ std::shared_ptr<struct tile_atlas> tile_atlas(StringView filename) noexcept(false) override;
ArrayView<String> anim_atlas_list() override;
std::shared_ptr<struct anim_atlas> anim_atlas(StringView name, StringView dir) noexcept(false) override;
const std::vector<serialized_scenery>& sceneries() override;
diff --git a/loader/json.cpp b/loader/json.cpp
index dbe21d50..7e6aae68 100644
--- a/loader/json.cpp
+++ b/loader/json.cpp
@@ -1,6 +1,7 @@
#include "impl.hpp"
#include "compat/assert.hpp"
#include "compat/exception.hpp"
+#include "src/tile-atlas.hpp"
#include "serialize/json-helper.hpp"
#include "serialize/anim.hpp"
#include "serialize/tile-atlas.hpp"
@@ -52,9 +53,14 @@ const scenery_proto& loader_impl::scenery(StringView name) noexcept(false)
namespace floormat {
-std::vector<std::shared_ptr<struct tile_atlas>> loader_::tile_atlases(StringView filename)
+std::vector<std::shared_ptr<struct tile_atlas>> loader_::tile_atlases(StringView filename, pass_mode p)
{
- return json_helper::from_json<std::vector<std::shared_ptr<struct tile_atlas>>>(Path::join(loader_::IMAGE_PATH, filename));
+ auto vec = json_helper::from_json<std::vector<std::shared_ptr<struct tile_atlas>>>(
+ Path::join(loader_::IMAGE_PATH, filename));
+ for (auto& x : vec)
+ if (!x->pass_mode())
+ x->set_pass_mode(p);
+ return vec;
}
} // namespace floormat
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 8883ed8a..1189a02d 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include "src/pass-mode.hpp"
#include <memory>
#include <vector>
#include <Corrade/Containers/StringView.h>
@@ -15,12 +16,13 @@ struct scenery_proto;
struct loader_
{
virtual StringView shader(StringView filename) noexcept = 0;
- virtual std::shared_ptr<struct tile_atlas> tile_atlas(StringView filename, Vector2ub size) noexcept(false) = 0;
+ virtual std::shared_ptr<struct tile_atlas> tile_atlas(StringView filename, Vector2ub size, Optional<pass_mode> pass) noexcept(false) = 0;
+ virtual std::shared_ptr<struct tile_atlas> tile_atlas(StringView filename) noexcept(false) = 0;
virtual ArrayView<String> anim_atlas_list() = 0;
virtual std::shared_ptr<struct anim_atlas> anim_atlas(StringView name, StringView dir = ANIM_PATH) noexcept(false) = 0;
static void destroy();
static loader_& default_loader() noexcept;
- static std::vector<std::shared_ptr<struct tile_atlas>> tile_atlases(StringView filename);
+ static std::vector<std::shared_ptr<struct tile_atlas>> tile_atlases(StringView filename, pass_mode p);
virtual const std::vector<serialized_scenery>& sceneries() = 0;
virtual const scenery_proto& scenery(StringView name) noexcept(false) = 0;