diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-09 23:50:14 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-10 01:08:25 +0100 |
commit | 7b544078eb0e7cad58bd6fc5251a3c185c9bb082 (patch) | |
tree | 7bb4b1ac1b9eeeaef5ff300df4c76543bd932013 | |
parent | c7caf58e53975ad0f1d2da88708697c7b1bb5c32 (diff) |
loader: add invalid wall atlas to the list
-rw-r--r-- | editor/imgui-editors.cpp | 2 | ||||
-rw-r--r-- | editor/wall-editor.cpp | 8 | ||||
-rw-r--r-- | loader/wall-traits.cpp | 14 |
3 files changed, 22 insertions, 2 deletions
diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp index efb37426..3b884a19 100644 --- a/editor/imgui-editors.cpp +++ b/editor/imgui-editors.cpp @@ -45,7 +45,7 @@ StringView scenery_name(StringView, const vobj_& vobj) { return vobj.descr; } StringView scenery_name(StringView, const wall_cell* w) { return w->name; } std::shared_ptr<anim_atlas> get_atlas(const scenery_& sc) { return sc.proto.atlas; } std::shared_ptr<anim_atlas> get_atlas(const vobj_& vobj) { return vobj.factory->atlas(); } -std::shared_ptr<wall_atlas> get_atlas(const wall_cell* w) { return loader.wall_atlas(w->name); } +std::shared_ptr<wall_atlas> get_atlas(const wall_cell* w) { return w->atlas; } Vector2ui get_size(const auto&, anim_atlas& atlas) { return atlas.frame(atlas.first_rotation(), 0).size; } Vector2ui get_size(const auto&, wall_atlas& atlas) { auto sz = atlas.image_size(); return { std::max(1u, std::min(sz.y()*3/2, sz.x())), sz.y() }; } bool is_selected(const scenery_editor& ed, const scenery_& sc) { return ed.is_item_selected(sc); } diff --git a/editor/wall-editor.cpp b/editor/wall-editor.cpp index 681397a5..1d2e7cb3 100644 --- a/editor/wall-editor.cpp +++ b/editor/wall-editor.cpp @@ -51,7 +51,15 @@ void wall_editor::load_atlases() { fm_assert(_atlases.empty()); for (const auto& wa : loader.wall_atlas_list()) + { + if (wa.name != loader.INVALID) [[likely]] + (void)loader.wall_atlas(wa.name); + else + loader.make_invalid_wall_atlas(); + fm_assert(wa.atlas); _atlases[wa.name] = &wa; + } + fm_assert(!_atlases.empty()); } diff --git a/loader/wall-traits.cpp b/loader/wall-traits.cpp index 8f1c2e23..f51974bc 100644 --- a/loader/wall-traits.cpp +++ b/loader/wall-traits.cpp @@ -27,12 +27,24 @@ void wall_traits::ensure_atlases_loaded(Storage& st) return; fm_assert(st.name_map.empty()); + constexpr bool add_invalid = true; + st.cell_array = wall_cell::load_atlases_from_json().vec; st.name_map.reserve(st.cell_array.size()); + fm_assert(!st.cell_array.empty()); + fm_assert(st.name_map.empty()); + + if constexpr(add_invalid) + { + for (auto& x : st.cell_array) + fm_soft_assert(x.name != loader.INVALID); + st.cell_array.push_back(make_invalid_atlas(st)); + } for (auto& c : st.cell_array) { - fm_soft_assert(c.name != "<invalid>"_s); + if constexpr(!add_invalid) + fm_soft_assert(c.name != "<invalid>"_s); fm_soft_assert(loader.check_atlas_name(c.name)); StringView name = c.name; st.name_map[name] = &c; |