#include "anim-traits.hpp" #include "atlas-loader-storage.hpp" #include "anim-cell.hpp" #include "src/anim-atlas.hpp" #include "src/tile-defs.hpp" #include "loader.hpp" #include "compat/exception.hpp" #include #include #include #include #include #include namespace floormat::loader_detail { using anim_traits = atlas_loader_traits; StringView anim_traits::loader_name() { return "anim_atlas"_s; } auto anim_traits::atlas_of(const Cell& x) -> const std::shared_ptr& { return x.atlas; } auto anim_traits::atlas_of(Cell& x) -> std::shared_ptr& { return x.atlas; } StringView anim_traits::name_of(const Cell& x) { return x.name; } StringView anim_traits::name_of(const Atlas& x) { return x.name(); } String& anim_traits::name_of(Cell& x) { return x.name; } void anim_traits::ensure_atlases_loaded(Storage& s) { fm_debug_assert(s.name_map.empty()); s.cell_array = {}; s.name_map[loader.INVALID] = -1uz; } auto anim_traits::make_invalid_atlas(Storage& s) -> Pointer { fm_debug_assert(!s.invalid_atlas); constexpr auto size = Vector2ui{tile_size_xy*3/4}; constexpr auto ground = Vector2i(size/2); auto frame = anim_frame { .ground = ground, .offset = {}, .size = size, }; auto groups = Array{ValueInit, 1}; groups[0] = anim_group { .name = "n"_s, .frames = array({ frame }), }; auto def = anim_def { .object_name = loader.INVALID, .anim_name = loader.INVALID, .groups = Utility::move(groups), .pixel_size = size, .scale = anim_scale::fixed{size.x(), true}, .nframes = 1, }; auto atlas = std::make_shared(loader.INVALID, loader.make_error_texture(size), std::move(def)); auto info = anim_cell { .atlas = atlas, .name = loader.INVALID, }; return Pointer{ InPlace, Utility::move(info) }; } auto anim_traits::make_atlas(StringView name, const Cell& c) -> std::shared_ptr { return {}; // todo } auto anim_traits::make_cell(StringView name) -> Optional { return { InPlace, Cell{ .atlas = {}, .name = name, } }; } } // namespace floormat::loader_detail