diff --git a/headers/enduro2d/high/_all.hpp b/headers/enduro2d/high/_all.hpp index ab0f4180..54893b96 100644 --- a/headers/enduro2d/high/_all.hpp +++ b/headers/enduro2d/high/_all.hpp @@ -43,6 +43,7 @@ #include "components/scene.hpp" #include "components/spine_player.hpp" #include "components/sprite_renderer.hpp" +#include "components/touchable.hpp" #include "systems/flipbook_system.hpp" #include "systems/label_system.hpp" diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index c0e40ef4..9d87af01 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -63,6 +63,7 @@ namespace e2d class scene; class spine_player; class sprite_renderer; + class touchable; class flipbook_system; class label_system; diff --git a/headers/enduro2d/high/components/touchable.hpp b/headers/enduro2d/high/components/touchable.hpp new file mode 100644 index 00000000..bb71d300 --- /dev/null +++ b/headers/enduro2d/high/components/touchable.hpp @@ -0,0 +1,33 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "../_high.hpp" + +#include "../factory.hpp" + +namespace e2d +{ + class touchable final { + public: + touchable() = default; + }; + + template <> + class factory_loader final : factory_loader<> { + public: + static const char* schema_source; + + bool operator()( + touchable& component, + const fill_context& ctx) const; + + bool operator()( + asset_dependencies& dependencies, + const collect_context& ctx) const; + }; +} diff --git a/samples/bin/library/scripts/emmy/components/touchable.lua b/samples/bin/library/scripts/emmy/components/touchable.lua new file mode 100644 index 00000000..9d1e3fa0 --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/touchable.lua @@ -0,0 +1,6 @@ +---@class touchable +local touchable = { +} + +---@type touchable +_G.touchable = _G.touchable or touchable diff --git a/samples/bin/library/scripts/emmy/high/gobject.lua b/samples/bin/library/scripts/emmy/high/gobject.lua index c15f3d06..91452682 100644 --- a/samples/bin/library/scripts/emmy/high/gobject.lua +++ b/samples/bin/library/scripts/emmy/high/gobject.lua @@ -46,7 +46,10 @@ local gobject = { spine_player = nil, ---@type sprite_renderer - sprite_renderer = nil + sprite_renderer = nil, + + ---@type touchable + touchable = nil } ---@param self gobject diff --git a/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp b/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp index 675a6763..87d8f6af 100644 --- a/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp +++ b/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp @@ -29,6 +29,7 @@ namespace e2d::bindings::high void bind_scene(sol::state& l); void bind_spine_player(sol::state& l); void bind_sprite_renderer(sol::state& l); + void bind_touchable(sol::state& l); } namespace e2d::bindings @@ -53,5 +54,6 @@ namespace e2d::bindings high::bind_scene(l); high::bind_spine_player(l); high::bind_sprite_renderer(l); + high::bind_touchable(l); } } diff --git a/sources/enduro2d/high/bindings/high_binds/components/touchable_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/touchable_binds.cpp new file mode 100644 index 00000000..c3d8bb51 --- /dev/null +++ b/sources/enduro2d/high/bindings/high_binds/components/touchable_binds.cpp @@ -0,0 +1,54 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include "../_high_binds.hpp" + +#include +#include +#include + +namespace e2d::bindings::high +{ + void bind_touchable(sol::state& l) { + l.new_usertype>("touchable", + sol::no_constructor, + + "enable", [](gcomponent& c){ + c.owner().component>().remove(); + }, + + "disable", [](gcomponent& c){ + c.owner().component>().ensure(); + }, + + "enabled", sol::property( + [](const gcomponent& c) -> bool { + return !c.owner().component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.owner().component>().remove(); + } else { + c.owner().component>().ensure(); + } + } + ), + + "disabled", sol::property( + [](const gcomponent& c) -> bool { + return c.owner().component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.owner().component>().ensure(); + } else { + c.owner().component>().remove(); + } + } + ) + ); + } +} diff --git a/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp b/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp index bf8e8c28..c723fc27 100644 --- a/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace e2d::bindings::high { @@ -52,7 +53,8 @@ namespace e2d::bindings::high "renderer", sol::property([](gobject& go){ return component_wrapper{go}; }), "scene", sol::property([](gobject& go){ return component_wrapper{go}; }), "spine_player", sol::property([](gobject& go){ return component_wrapper{go}; }), - "sprite_renderer", sol::property([](gobject& go){ return component_wrapper{go}; }) + "sprite_renderer", sol::property([](gobject& go){ return component_wrapper{go}; }), + "touchable", sol::property([](gobject& go){ return component_wrapper{go}; }) ); } } diff --git a/sources/enduro2d/high/components/touchable.cpp b/sources/enduro2d/high/components/touchable.cpp new file mode 100644 index 00000000..6a17942a --- /dev/null +++ b/sources/enduro2d/high/components/touchable.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include + +namespace e2d +{ + const char* factory_loader::schema_source = R"json({ + "type" : "object", + "required" : [], + "additionalProperties" : false, + "properties" : { + } + })json"; + + bool factory_loader::operator()( + touchable& component, + const fill_context& ctx) const + { + E2D_UNUSED(component, ctx); + return true; + } + + bool factory_loader::operator()( + asset_dependencies& dependencies, + const collect_context& ctx) const + { + E2D_UNUSED(dependencies, ctx); + return true; + } +} diff --git a/sources/enduro2d/high/starter.cpp b/sources/enduro2d/high/starter.cpp index 7d5f637d..6ce88e0a 100644 --- a/sources/enduro2d/high/starter.cpp +++ b/sources/enduro2d/high/starter.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -195,7 +196,8 @@ namespace e2d .register_component("spine_player") .register_component>("spine_player_events") .register_component>("spine_player_commands") - .register_component("sprite_renderer"); + .register_component("sprite_renderer") + .register_component("touchable"); safe_module_initialize(); diff --git a/untests/bin/library/prefab.json b/untests/bin/library/prefab.json index d7a13d21..40d39e1d 100644 --- a/untests/bin/library/prefab.json +++ b/untests/bin/library/prefab.json @@ -1,5 +1,7 @@ { "components" : { + "touchable" : {}, + "rect_collider" : { "size" : [1,2], "pivot" : [2,4] diff --git a/untests/sources/untests_high/library.cpp b/untests/sources/untests_high/library.cpp index fd7814ec..e744c0b1 100644 --- a/untests/sources/untests_high/library.cpp +++ b/untests/sources/untests_high/library.cpp @@ -250,6 +250,8 @@ TEST_CASE("library"){ ecs::registry w; ecs::entity e = w.create_entity(prefab_res->content().prototype()); + REQUIRE(e.exists_component()); + REQUIRE(e.exists_component()); REQUIRE(e.get_component().size() == v2f(1.f,2.f)); REQUIRE(e.get_component().pivot() == v2f(2.f,4.f));