summaryrefslogtreecommitdiffhomepage
path: root/loader/atlas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'loader/atlas.cpp')
-rw-r--r--loader/atlas.cpp68
1 files changed, 39 insertions, 29 deletions
diff --git a/loader/atlas.cpp b/loader/atlas.cpp
index 555a2b02..b39bc8f5 100644
--- a/loader/atlas.cpp
+++ b/loader/atlas.cpp
@@ -42,8 +42,45 @@ bool loader_::check_atlas_name(StringView str) noexcept
return true;
}
+std::shared_ptr<class anim_atlas>
+loader_::get_anim_atlas(StringView path) noexcept(false)
+{
+
+ auto anim_info = deserialize_anim_def(path + ".json");
+
+ for (anim_group& group : anim_info.groups)
+ {
+ if (!group.mirror_from.isEmpty())
+ {
+ auto it = std::find_if(anim_info.groups.cbegin(), anim_info.groups.cend(),
+ [&](const anim_group& x) { return x.name == group.mirror_from; });
+ if (it == anim_info.groups.cend())
+ fm_throw("can't find group '{}' to mirror from '{}'"_cf, group.mirror_from, group.name);
+ group.frames = array(arrayView(it->frames));
+ for (anim_frame& f : group.frames)
+ f.ground = Vector2i((Int)f.size[0] - f.ground[0], f.ground[1]);
+ }
+ }
+
+ auto tex = texture(""_s, path);
+
+ fm_soft_assert(!anim_info.object_name.isEmpty());
+ fm_soft_assert(anim_info.pixel_size.product() > 0);
+ fm_soft_assert(!anim_info.groups.isEmpty());
+ fm_soft_assert(anim_info.nframes > 0);
+ fm_soft_assert(anim_info.nframes == 1 || anim_info.fps > 0);
+ const auto size = tex.pixels().size();
+ const auto width = size[1], height = size[0];
+ fm_soft_assert(anim_info.pixel_size[0] == width && anim_info.pixel_size[1] == height);
+
+ auto atlas = std::make_shared<class anim_atlas>(path, tex, std::move(anim_info));
+ return atlas;
+}
+
} // namespace floormat
+
+
namespace floormat::loader_detail {
ArrayView<const String> loader_impl::anim_atlas_list()
@@ -56,6 +93,7 @@ ArrayView<const String> loader_impl::anim_atlas_list()
std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView dir) noexcept(false)
{
+ fm_soft_assert(check_atlas_name(name));
fm_soft_assert(!dir || dir[dir.size()-1] == '/');
char buf[FILENAME_MAX];
auto path = make_atlas_path(buf, dir, name);
@@ -64,35 +102,7 @@ std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView
return it->second;
else
{
- fm_soft_assert(check_atlas_name(name));
- auto anim_info = deserialize_anim(path + ".json");
-
- for (anim_group& group : anim_info.groups)
- {
- if (!group.mirror_from.isEmpty())
- {
- auto it = std::find_if(anim_info.groups.cbegin(), anim_info.groups.cend(),
- [&](const anim_group& x) { return x.name == group.mirror_from; });
- if (it == anim_info.groups.cend())
- fm_throw("can't find group '{}' to mirror from '{}'"_cf, group.mirror_from, group.name);
- group.frames = array(arrayView(it->frames));
- for (anim_frame& f : group.frames)
- f.ground = Vector2i((Int)f.size[0] - f.ground[0], f.ground[1]);
- }
- }
-
- auto tex = texture(""_s, path);
-
- fm_soft_assert(!anim_info.object_name.isEmpty());
- fm_soft_assert(anim_info.pixel_size.product() > 0);
- fm_soft_assert(!anim_info.groups.isEmpty());
- fm_soft_assert(anim_info.nframes > 0);
- fm_soft_assert(anim_info.nframes == 1 || anim_info.fps > 0);
- const auto size = tex.pixels().size();
- const auto width = size[1], height = size[0];
- fm_soft_assert(anim_info.pixel_size[0] == width && anim_info.pixel_size[1] == height);
-
- auto atlas = std::make_shared<class anim_atlas>(path, tex, std::move(anim_info));
+ auto atlas = get_anim_atlas(path);
return anim_atlas_map[atlas->name()] = atlas;
}
}