diff options
Diffstat (limited to 'loader/scenery-traits.cpp')
-rw-r--r-- | loader/scenery-traits.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/loader/scenery-traits.cpp b/loader/scenery-traits.cpp index 99664541..84cc42d9 100644 --- a/loader/scenery-traits.cpp +++ b/loader/scenery-traits.cpp @@ -1 +1,55 @@ #include "scenery-traits.hpp" +#include "compat/assert.hpp" +#include "compat/vector-wrapper.hpp" +#include "atlas-loader-storage.hpp" +#include "scenery-cell.hpp" +#include "loader.hpp" +#include "anim-cell.hpp" +#include "src/tile-defs.hpp" +#include "src/anim-atlas.hpp" +#include "src/scenery.hpp" +#include "serialize/json-helper.hpp" +#include "serialize/anim.hpp" +#include "serialize/scenery.hpp" +#include <cr/Optional.h> +#include <Corrade/Containers/StringView.h> + +namespace floormat::loader_detail { + +using scenery_traits = atlas_loader_traits<scenery_proto>; +StringView scenery_traits::loader_name() { return "scenery_proto"_s; } +auto scenery_traits::atlas_of(const Cell& x) -> const scenery_proto& { return x.proto; } +auto scenery_traits::atlas_of(Cell& x) -> scenery_proto& { return x.proto; } +StringView scenery_traits::name_of(const Cell& x) { return x.name; } +String& scenery_traits::name_of(Cell& x) { return x.name; } + +void scenery_traits::atlas_list(Storage& s) +{ + fm_debug_assert(s.name_map.empty()); + s.cell_array = scenery_cell::load_atlases_from_json().vec; +} + +auto scenery_traits::make_invalid_atlas(Storage& s) -> Cell +{ + fm_debug_assert(!s.invalid_atlas); + auto proto = scenery_proto{}; + proto.atlas = loader.invalid_anim_atlas().atlas; + proto.bbox_size = Vector2ub{tile_size_xy/2}; + proto.subtype = generic_scenery_proto{false, true}; + return { .name = loader.INVALID, .proto = proto, }; +} + +auto scenery_traits::make_atlas(StringView name, const Cell& c) -> scenery_proto +{ + auto p = c.proto; + p.atlas = loader.anim_atlas(name, loader.SCENERY_PATH); + fm_debug_assert(p.atlas); + return p; +} + +auto scenery_traits::make_cell(StringView name) -> Optional<Cell> +{ + return { InPlace, Cell { .name = name, .proto = {}, } }; +} + +} // namespace floormat::loader_detail |