diff options
| -rw-r--r-- | anim-crop-tool/main.cpp | 6 | ||||
| -rw-r--r-- | anim/scenery.json | 2 | ||||
| -rw-r--r-- | editor/scenery-editor.cpp | 43 | ||||
| -rw-r--r-- | editor/scenery-editor.hpp | 17 | ||||
| -rw-r--r-- | editor/scenery-json.cpp | 14 | ||||
| -rw-r--r-- | editor/tile-editor.cpp | 7 | ||||
| -rw-r--r-- | loader/json.cpp | 17 | ||||
| -rw-r--r-- | loader/loader.hpp | 4 | ||||
| -rw-r--r-- | serialize/scenery.cpp | 22 | ||||
| -rw-r--r-- | serialize/scenery.hpp | 9 | ||||
| -rw-r--r-- | src/anim-atlas.cpp | 26 | ||||
| -rw-r--r-- | src/anim-atlas.hpp | 3 |
12 files changed, 118 insertions, 52 deletions
diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index 5b6fa31e..fdb58e43 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -234,12 +234,10 @@ static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char* { if (str.isEmpty()) return false; - if (str[0] == '.' || str[0] == '\\' || str[0] == '/') + if (str.findAny("\\<>&;:'\" ") || str.find("/.")) return false; - if (str.find('"') || str.find('\'')) + if (str[0] == '.' || str[0] == '/') return false; - if (str.find("/.") || str.find("\\.")) - return false; // NOLINT(readability-simplify-boolean-expr) return true; } diff --git a/anim/scenery.json b/anim/scenery.json new file mode 100644 index 00000000..0d4f101c --- /dev/null +++ b/anim/scenery.json @@ -0,0 +1,2 @@ +[ +] diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index c8f9f910..612bfb78 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -15,37 +15,33 @@ scenery_editor::scenery_editor() noexcept void scenery_editor::set_rotation(rotation_ r) { - _selected.frame.r = r; + if (_selected.proto.atlas) + { + (void)_selected.proto.atlas->group(r); + _selected.proto.frame.r = r; + } } rotation_ scenery_editor::rotation() const { - return _selected.frame.r; + return _selected.proto.frame.r; } void scenery_editor::next_rotation() { - // todo - auto r_1 = (rotation_t)_selected.frame.r + 1; - auto rot = (rotation_)r_1; - if (rot >= rotation_COUNT) - rot = (rotation_)0; - _selected.frame.r = rot; + if (auto& proto = _selected.proto; proto.atlas) + proto.frame.r = proto.atlas->next_rotation_from(proto.frame.r); } void scenery_editor::prev_rotation() { - if (_selected.frame.r == (rotation_)0) - _selected.frame.r = (rotation_)((rotation_t)rotation_COUNT - 1); - else - _selected.frame.r = (rotation_)((rotation_t)_selected.frame.r - 1); + if (auto& proto = _selected.proto; proto.atlas) + proto.frame.r = proto.atlas->prev_rotation_from(proto.frame.r); } -//return atlas == _selected.atlas && r == _selected.s.r && frame == _selected.s.frame; - -void scenery_editor::select_tile(const scenery_proto& proto) +void scenery_editor::select_tile(const scenery_& s) { - _selected = proto; + _selected = s; } void scenery_editor::clear_selection() @@ -53,26 +49,19 @@ void scenery_editor::clear_selection() _selected = {}; } -const scenery_proto& scenery_editor::get_selected() +auto scenery_editor::get_selected() -> const scenery_& { return _selected; } bool scenery_editor::is_atlas_selected(const std::shared_ptr<anim_atlas>& atlas) const { - return _selected.atlas == atlas; -} - -bool scenery_editor::is_item_selected(const scenery_proto& proto) const -{ - return _selected == proto; + return atlas == _selected.proto.atlas; } -void scenery_editor::load_atlases() +bool scenery_editor::is_item_selected(const scenery_& s) const { - _atlases.clear(); - for (StringView str : loader.anim_atlas_list()) - _atlases[str] = loader.anim_atlas(str); + return s.name == _selected.name && s.proto.atlas == _selected.proto.atlas; } } // namespace floormat diff --git a/editor/scenery-editor.hpp b/editor/scenery-editor.hpp index b461fd0c..521353fa 100644 --- a/editor/scenery-editor.hpp +++ b/editor/scenery-editor.hpp @@ -2,7 +2,7 @@ #include "src/scenery.hpp" #include <map> #include <memory> -#include <Corrade/Containers/StringView.h> +#include <Corrade/Containers/String.h> namespace floormat { @@ -10,7 +10,10 @@ struct anim_atlas; struct scenery_editor final { - using frame_t = scenery::frame_t; + struct scenery_ { + String name, descr; + scenery_proto proto; + }; scenery_editor() noexcept; @@ -19,17 +22,17 @@ struct scenery_editor final void next_rotation(); void prev_rotation(); - void select_tile(const scenery_proto& proto); + void select_tile(const scenery_& s); void clear_selection(); - const scenery_proto& get_selected(); + const scenery_& get_selected(); bool is_atlas_selected(const std::shared_ptr<anim_atlas>& atlas) const; - bool is_item_selected(const scenery_proto& proto) const; + bool is_item_selected(const scenery_& s) const; private: void load_atlases(); - std::map<StringView, std::shared_ptr<anim_atlas>> _atlases; - scenery_proto _selected; + std::map<String, scenery_> _atlases; + scenery_ _selected; }; } // namespace floormat diff --git a/editor/scenery-json.cpp b/editor/scenery-json.cpp new file mode 100644 index 00000000..a6756512 --- /dev/null +++ b/editor/scenery-json.cpp @@ -0,0 +1,14 @@ +#include "scenery-editor.hpp" +#include "serialize/scenery.hpp" +#include "loader/loader.hpp" + +namespace floormat { + +void scenery_editor::load_atlases() +{ + _atlases.clear(); + for (auto& s : loader.sceneries()) + _atlases[s.name] = scenery_{s.name, s.descr, s.proto}; +} + +} // namespace floormat diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp index 4ae54d86..d944f47f 100644 --- a/editor/tile-editor.cpp +++ b/editor/tile-editor.cpp @@ -4,23 +4,20 @@ #include "keys.hpp" #include "loader/loader.hpp" #include "random.hpp" -#include "serialize/json-helper.hpp" -#include "serialize/tile-atlas.hpp" #include <Corrade/Containers/PairStl.h> #include <Corrade/Utility/Path.h> namespace floormat { -tile_editor::tile_editor(editor_mode mode, StringView name) : _name{ name}, _mode{ mode} +tile_editor::tile_editor(editor_mode mode, StringView name) : _name{name}, _mode{ mode} { load_atlases(); } void tile_editor::load_atlases() { - using atlas_array = std::vector<std::shared_ptr<tile_atlas>>; const auto filename = _name + ".json"; - for (auto& atlas : json_helper::from_json<atlas_array>(Path::join(loader_::IMAGE_PATH, filename))) + for (const auto& atlas : loader.tile_atlases(filename)) { const auto [name, _ext] = Path::splitExtension(atlas->name()); auto& [_, vec] = _permutation; diff --git a/loader/json.cpp b/loader/json.cpp index 1a30a66b..7ee661f7 100644 --- a/loader/json.cpp +++ b/loader/json.cpp @@ -1,6 +1,9 @@ #include "impl.hpp" #include "serialize/json-helper.hpp" #include "serialize/anim.hpp" +#include "serialize/tile-atlas.hpp" +#include "serialize/scenery.hpp" +#include <Corrade/Utility/Path.h> namespace floormat::loader_detail { @@ -10,3 +13,17 @@ anim_def loader_impl::deserialize_anim(StringView filename) } } // namespace floormat::loader_detail + +namespace floormat { + +std::vector<std::shared_ptr<struct tile_atlas>> loader_::tile_atlases(StringView filename) +{ + return json_helper::from_json<std::vector<std::shared_ptr<struct tile_atlas>>>(Path::join(loader_::IMAGE_PATH, filename)); +} + +std::vector<Serialize::serialized_scenery> loader_::sceneries() +{ + return json_helper::from_json<std::vector<Serialize::serialized_scenery>>(Path::join(ANIM_PATH, "scenery.json")); +} + +} // namespace floormat diff --git a/loader/loader.hpp b/loader/loader.hpp index e3f306ea..1c15ac43 100644 --- a/loader/loader.hpp +++ b/loader/loader.hpp @@ -2,11 +2,13 @@ #include <memory> namespace Magnum { using Vector2ub = Math::Vector2<unsigned char>; } +namespace floormat::Serialize { struct serialized_scenery; } namespace floormat { struct tile_atlas; struct anim_atlas; +struct scenery_proto; struct loader_ { @@ -16,6 +18,8 @@ struct loader_ virtual std::shared_ptr<struct anim_atlas> anim_atlas(StringView name) = 0; static void destroy(); static loader_& default_loader() noexcept; + static std::vector<std::shared_ptr<struct tile_atlas>> tile_atlases(StringView filename); + static std::vector<Serialize::serialized_scenery> sceneries(); loader_(const loader_&) = delete; loader_& operator=(const loader_&) = delete; diff --git a/serialize/scenery.cpp b/serialize/scenery.cpp index 8bff3d69..984b11bc 100644 --- a/serialize/scenery.cpp +++ b/serialize/scenery.cpp @@ -3,6 +3,7 @@ #include "compat/assert.hpp" #include "loader/loader.hpp" #include "serialize/corrade-string.hpp" +#include "serialize/json-helper.hpp" #include <array> #include <Corrade/Containers/StringStlView.h> #include <nlohmann/json.hpp> @@ -10,6 +11,7 @@ namespace { using namespace floormat; +using namespace floormat::Serialize; constexpr struct { scenery_type value = scenery_type::none; @@ -55,10 +57,6 @@ StringView foo_to_string(auto type, const T(&map)[N], const char* desc) } // namespace -namespace floormat { - -} // namespace floormat - namespace nlohmann { void adl_serializer<scenery_type>::to_json(json& j, const scenery_type val) @@ -131,6 +129,22 @@ void adl_serializer<scenery_proto>::from_json(const json& j, scenery_proto& val) } } +void adl_serializer<serialized_scenery>::to_json(json& j, const serialized_scenery& val) +{ + fm_assert(val.proto.atlas); + j = val.proto; + const auto name = !val.name.isEmpty() ? StringView{val.name} : val.proto.atlas->name(); + j["name"] = name; + j["description"] = val.descr; +} +void adl_serializer<serialized_scenery>::from_json(const json& j, serialized_scenery& val) +{ + val = {}; + val.proto = j; + val.name = j["name"]; + if (j.contains("description")) + val.descr = j["description"]; +} } // namespace nlohmann diff --git a/serialize/scenery.hpp b/serialize/scenery.hpp index 190a4d2a..e3eb977a 100644 --- a/serialize/scenery.hpp +++ b/serialize/scenery.hpp @@ -1,16 +1,15 @@ #pragma once #include "src/scenery.hpp" #include <vector> -#include <Corrade/Containers/StringView.h> +#include <Corrade/Containers/String.h> #include <nlohmann/json_fwd.hpp> namespace floormat::Serialize { -struct serialized_scenery final { - StringView name, descr; +struct serialized_scenery final +{ + String name, descr; scenery_proto proto; - - static std::vector<serialized_scenery> deserialize(StringView filename); }; } // namespace floormat::Serialize diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index e8d4bd9b..f75b1679 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -137,4 +137,30 @@ BitArrayView anim_atlas::bitmask() const return _bitmask; } +rotation anim_atlas::next_rotation_from(rotation r) const noexcept +{ + constexpr auto count = std::size_t(rotation_COUNT); + fm_assert(r < rotation_COUNT); + for (auto i = std::size_t(r)+1; i < count; i++) + if (_group_indices[i] != 0xff) + return rotation(i); + for (std::size_t i = 0; i < count; i++) + if (_group_indices[i] != 0xff) + return rotation(i); + fm_abort("where did the rotations go?!"); +} + +rotation anim_atlas::prev_rotation_from(rotation r) const noexcept +{ + using ssize = std::make_signed_t<std::size_t>; + constexpr auto count = ssize(rotation_COUNT); + for (auto i = ssize(r)-1; i >= 0; i--) + if (_group_indices[std::size_t(i)] != 0xff) + return rotation(i); + for (auto i = count-1; i >= 0; i--) + if (_group_indices[std::size_t(i)] != 0xff) + return rotation(i); + fm_abort("where did the rotations go?!"); +} + } // namespace floormat diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp index b25ff489..f64e4e01 100644 --- a/src/anim-atlas.hpp +++ b/src/anim-atlas.hpp @@ -35,6 +35,9 @@ struct anim_atlas final BitArrayView bitmask() const; + [[nodiscard]] rotation next_rotation_from(rotation r) const noexcept; + [[nodiscard]] rotation prev_rotation_from(rotation r) const noexcept; + fm_DECLARE_DELETED_COPY_ASSIGNMENT(anim_atlas); private: |
