#include "loader/impl.hpp" #include "wall-info.hpp" #include "compat/assert.hpp" #include "compat/exception.hpp" #include "src/wall-atlas.hpp" #include "serialize/wall-atlas.hpp" #include "wall-info.hpp" #include "serialize/json-helper.hpp" #include "serialize/corrade-string.hpp" #include #include #include #include #include #include #include namespace floormat { NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(wall_info, name, descr) } // namespace floormat namespace floormat::loader_detail { std::shared_ptr loader_impl::get_wall_atlas(StringView name, StringView path) { auto def = wall_atlas_def::deserialize(""_s.join({path, ".json"_s})); auto tex = texture(""_s, path); auto atlas = std::make_shared(std::move(def), path, tex); return atlas; } const wall_info& loader_impl::wall_atlas(StringView name, StringView dir) { fm_soft_assert(check_atlas_name(name)); char buf[FILENAME_MAX]; auto path = make_atlas_path(buf, dir, name); auto it = wall_atlas_map.find(path); if (it == wall_atlas_map.end()) fm_throw("no such wall atlas '{}'"_cf, fmt::string_view{path.data(), path.size()}); fm_assert(it->second != nullptr); if (!it->second->atlas) { const_cast(it->second)->atlas = get_wall_atlas(it->second->name, path); } return *it->second; } void loader_impl::get_wall_atlas_list() { wall_atlas_array = json_helper::from_json>(Path::join(WALL_TILESET_PATH, "walls.json"_s)); wall_atlas_array.shrink_to_fit(); wall_atlas_map.clear(); wall_atlas_map.reserve(wall_atlas_array.size()*2); for (const auto& x : wall_atlas_array) { fm_soft_assert(check_atlas_name(x.name)); StringView name = x.name; wall_atlas_map[name] = &x; fm_debug_assert(name.data() == wall_atlas_map[name]->name.data()); } fm_assert(!wall_atlas_map.empty()); } ArrayView loader_impl::wall_atlas_list() { if (wall_atlas_map.empty()) get_wall_atlas_list(); return wall_atlas_array; } } // namespace floormat::loader_detail