From b2992a75af5af0a35eb7e7b180ba3d66341518aa Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 9 Apr 2023 14:40:16 +0200 Subject: editor: add entity metadata inheritance --- editor/inspect-types.cpp | 101 ++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 50 deletions(-) (limited to 'editor') diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index 5b02acde..63335e88 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -8,81 +8,80 @@ #include "chunk.hpp" #include -//#define TEST_STR - -#ifdef TEST_STR -#include -static Corrade::Containers::String my_str; -#endif - namespace floormat::entities { template<> -struct entity_accessors { +struct entity_accessors { static constexpr auto accessors() { - using entity = Entity; + using E = Entity; return std::tuple{ - entity::type::field{"id"_s, - [](const scenery& x) { return x.id; }, - [](scenery&, uint64_t) {}, + E::type::field{"id"_s, + [](const entity& x) { return x.id; }, + [](entity&, object_id) {}, constantly(field_status::readonly), }, - entity::type::field{"atlas"_s, - [](const scenery& x) { return loader.strip_prefix(x.atlas->name()); }, - [](scenery&, StringView) {}, + E::type::field{"atlas"_s, + [](const entity& x) { return loader.strip_prefix(x.atlas->name()); }, + [](entity&, StringView) {}, constantly(field_status::readonly), }, - entity::type::field{"rotation"_s, - [](const scenery& x) { return x.r; }, - [](scenery& x, rotation r) { x.rotate(x.index(), r); }, + E::type::field{"rotation"_s, + [](const entity& x) { return x.r; }, + [](entity& x, rotation r) { x.rotate(x.index(), r); }, }, - entity::type::field{"frame"_s, - [](const scenery& x) { return x.frame; }, - [](scenery& x, uint16_t value) { x.frame = value; }, - [](const scenery& x) { return constraints::range{0, !x.atlas ? uint16_t(0) : uint16_t(x.atlas->info().nframes-1)}; } + E::type::field{"frame"_s, + [](const entity& x) { return x.frame; }, + [](entity& x, uint16_t value) { x.frame = value; }, + [](const entity& x) { return constraints::range{0, !x.atlas ? uint16_t(0) : uint16_t(x.atlas->info().nframes-1)}; } }, - entity::type::field{"offset"_s, - [](const scenery& x) { return x.offset; }, - [](scenery& x, Vector2b value) { x.set_bbox(value, x.bbox_offset, x.bbox_size, x.pass); }, + E::type::field{"offset"_s, + [](const entity& x) { return x.offset; }, + [](entity& x, Vector2b value) { x.set_bbox(value, x.bbox_offset, x.bbox_size, x.pass); }, constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)}) }, - entity::type::field{"pass-mode"_s, - [](const scenery& x) { return x.pass; }, - [](scenery& x, pass_mode value) { x.set_bbox(x.offset, x.bbox_offset, x.bbox_size, value); } + E::type::field{"pass-mode"_s, + [](const entity& x) { return x.pass; }, + [](entity& x, pass_mode value) { x.set_bbox(x.offset, x.bbox_offset, x.bbox_size, value); } }, - entity::type::field{"bbox-offset"_s, - [](const scenery& x) { return x.bbox_offset; }, - [](scenery& x, Vector2b value) { x.set_bbox(x.offset, value, x.bbox_size, x.pass); }, - [](const scenery& x) { return x.pass == pass_mode::pass ? field_status::readonly : field_status::enabled; }, + E::type::field{"bbox-offset"_s, + [](const entity& x) { return x.bbox_offset; }, + [](entity& x, Vector2b value) { x.set_bbox(x.offset, value, x.bbox_size, x.pass); }, + [](const entity& x) { return x.pass == pass_mode::pass ? field_status::readonly : field_status::enabled; }, }, - entity::type::field{"bbox-size"_s, - [](const scenery& x) { return x.bbox_size; }, - [](scenery& x, Vector2ub value) { x.set_bbox(x.offset, x.bbox_offset, value, x.pass); }, - [](const scenery& x) { return x.pass == pass_mode::pass ? field_status::readonly : field_status::enabled; }, + E::type::field{"bbox-size"_s, + [](const entity& x) { return x.bbox_size; }, + [](entity& x, Vector2ub value) { x.set_bbox(x.offset, x.bbox_offset, value, x.pass); }, + [](const entity& x) { return x.pass == pass_mode::pass ? field_status::readonly : field_status::enabled; }, }, - entity::type::field{"interactive"_s, + }; + } +}; + +template<> +struct entity_accessors { + static constexpr auto accessors() + { + using E = Entity; + auto tuple0 = entity_accessors::accessors(); + auto tuple = std::tuple{ + E::type::field{"interactive"_s, [](const scenery& x) { return x.interactive; }, [](scenery& x, bool value) { x.interactive = value; } }, -#ifdef TEST_STR - entity::type::field{"string"_s, - [](const scenery&) { return my_str; }, - [](scenery&, String value) { my_str = std::move_to(value); }, - constantly(constraints::max_length{8}), - }, -#endif }; + return std::tuple_cat(tuple0, tuple); } }; template struct has_anim_atlas : std::false_type {}; -template<> struct has_anim_atlas : std::true_type { - static const anim_atlas& get_atlas(const scenery& x) { +template<> struct has_anim_atlas : std::true_type { + static const anim_atlas& get_atlas(const entity& x) { fm_assert(x.atlas); return *x.atlas; } }; +template<> struct has_anim_atlas : has_anim_atlas {}; using enum_pair = std::pair; template struct enum_values; @@ -136,13 +135,12 @@ struct enum_values : std::false_type { } }; -template<> -bool inspect_type(scenery& x) +template bool inspect_type(T& x) { bool ret = false; visit_tuple([&](const auto& field) { using type = typename std::decay_t::FieldType; - using enum_type = enum_values; + using enum_type = enum_values; if constexpr(enum_type::value) { constexpr auto list = enum_type::get(); @@ -153,8 +151,11 @@ bool inspect_type(scenery& x) const auto& list = enum_type::get(x); ret |= inspect_field(&x, field.erased(), list); } - }, entity_metadata::accessors); + }, entity_metadata::accessors); return ret; } +template bool inspect_type(entity&); +template bool inspect_type(scenery&); + } // namespace floormat::entities -- cgit v1.2.3