diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-21 22:53:38 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-21 22:53:38 +0100 |
commit | 356c4d50b6b06bbfcc4332868ff77407b338b6eb (patch) | |
tree | 403c7b1e3e1fa294c7458d3f45ed1cd9ded7a145 /test | |
parent | 9c6b9ae8b4cced28f610fc5b37590bfc5814a7ce (diff) |
a
Diffstat (limited to 'test')
-rw-r--r-- | test/wall-atlas.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/test/wall-atlas.cpp b/test/wall-atlas.cpp index 47dc64ac..fd4d6f82 100644 --- a/test/wall-atlas.cpp +++ b/test/wall-atlas.cpp @@ -91,10 +91,49 @@ struct wall_atlas_ bool operator==(const wall_atlas_&) const noexcept = default; Info header; - Array<Direction> directions; + std::array<Direction, 4> directions = {}; Array<Frame> frames; }; +[[nodiscard]] wall_atlas_ read_from_file(StringView filename, bool do_checks = true) +{ + wall_atlas_ atlas; + + const auto jroot = json_helper::from_json_(filename); + atlas.header = read_info_header(jroot); + + if (do_checks) + { + const Info header_defaults; + fm_assert(atlas.header.name != header_defaults.name); + fm_assert(atlas.header.depth != header_defaults.depth); + } + + bool got_any_directions = false; + for (const auto& [_, curdir] : wall_atlas::directions) + { + auto i = (size_t)curdir; + atlas.directions[i] = read_direction_metadata(jroot, curdir); + got_any_directions = true; + } + if (do_checks) + fm_assert(got_any_directions); + + atlas.frames = read_all_frames(jroot); + + if (do_checks) + { + constexpr Frame frame_defaults; + constexpr Group group_defaults; + + fm_assert(!atlas.frames.isEmpty()); + fm_assert(atlas.frames[0].offset != frame_defaults.offset); + fm_assert(atlas.directions[(size_t)Direction_::W].side.pixel_size != group_defaults.pixel_size); + } + + return atlas; +} + void write_to_temp_file() { const auto filename = temp_filename(); |