dummy touchable component

This commit is contained in:
2019-11-29 03:42:33 +07:00
parent 0ca555a8c5
commit dc0d0ea965
12 changed files with 145 additions and 3 deletions

View File

@@ -43,6 +43,7 @@
#include "components/scene.hpp" #include "components/scene.hpp"
#include "components/spine_player.hpp" #include "components/spine_player.hpp"
#include "components/sprite_renderer.hpp" #include "components/sprite_renderer.hpp"
#include "components/touchable.hpp"
#include "systems/flipbook_system.hpp" #include "systems/flipbook_system.hpp"
#include "systems/label_system.hpp" #include "systems/label_system.hpp"

View File

@@ -63,6 +63,7 @@ namespace e2d
class scene; class scene;
class spine_player; class spine_player;
class sprite_renderer; class sprite_renderer;
class touchable;
class flipbook_system; class flipbook_system;
class label_system; class label_system;

View File

@@ -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<touchable> 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;
};
}

View File

@@ -0,0 +1,6 @@
---@class touchable
local touchable = {
}
---@type touchable
_G.touchable = _G.touchable or touchable

View File

@@ -46,7 +46,10 @@ local gobject = {
spine_player = nil, spine_player = nil,
---@type sprite_renderer ---@type sprite_renderer
sprite_renderer = nil sprite_renderer = nil,
---@type touchable
touchable = nil
} }
---@param self gobject ---@param self gobject

View File

@@ -29,6 +29,7 @@ namespace e2d::bindings::high
void bind_scene(sol::state& l); void bind_scene(sol::state& l);
void bind_spine_player(sol::state& l); void bind_spine_player(sol::state& l);
void bind_sprite_renderer(sol::state& l); void bind_sprite_renderer(sol::state& l);
void bind_touchable(sol::state& l);
} }
namespace e2d::bindings namespace e2d::bindings
@@ -53,5 +54,6 @@ namespace e2d::bindings
high::bind_scene(l); high::bind_scene(l);
high::bind_spine_player(l); high::bind_spine_player(l);
high::bind_sprite_renderer(l); high::bind_sprite_renderer(l);
high::bind_touchable(l);
} }
} }

View File

@@ -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 <enduro2d/high/gobject.hpp>
#include <enduro2d/high/components/touchable.hpp>
#include <enduro2d/high/components/disabled.hpp>
namespace e2d::bindings::high
{
void bind_touchable(sol::state& l) {
l.new_usertype<gcomponent<touchable>>("touchable",
sol::no_constructor,
"enable", [](gcomponent<touchable>& c){
c.owner().component<disabled<touchable>>().remove();
},
"disable", [](gcomponent<touchable>& c){
c.owner().component<disabled<touchable>>().ensure();
},
"enabled", sol::property(
[](const gcomponent<touchable>& c) -> bool {
return !c.owner().component<disabled<touchable>>().exists();
},
[](gcomponent<touchable>& c, bool yesno){
if ( yesno ) {
c.owner().component<disabled<touchable>>().remove();
} else {
c.owner().component<disabled<touchable>>().ensure();
}
}
),
"disabled", sol::property(
[](const gcomponent<touchable>& c) -> bool {
return c.owner().component<disabled<touchable>>().exists();
},
[](gcomponent<touchable>& c, bool yesno){
if ( yesno ) {
c.owner().component<disabled<touchable>>().ensure();
} else {
c.owner().component<disabled<touchable>>().remove();
}
}
)
);
}
}

View File

@@ -20,6 +20,7 @@
#include <enduro2d/high/components/scene.hpp> #include <enduro2d/high/components/scene.hpp>
#include <enduro2d/high/components/spine_player.hpp> #include <enduro2d/high/components/spine_player.hpp>
#include <enduro2d/high/components/sprite_renderer.hpp> #include <enduro2d/high/components/sprite_renderer.hpp>
#include <enduro2d/high/components/touchable.hpp>
namespace e2d::bindings::high namespace e2d::bindings::high
{ {
@@ -52,7 +53,8 @@ namespace e2d::bindings::high
"renderer", sol::property([](gobject& go){ return component_wrapper<renderer>{go}; }), "renderer", sol::property([](gobject& go){ return component_wrapper<renderer>{go}; }),
"scene", sol::property([](gobject& go){ return component_wrapper<scene>{go}; }), "scene", sol::property([](gobject& go){ return component_wrapper<scene>{go}; }),
"spine_player", sol::property([](gobject& go){ return component_wrapper<spine_player>{go}; }), "spine_player", sol::property([](gobject& go){ return component_wrapper<spine_player>{go}; }),
"sprite_renderer", sol::property([](gobject& go){ return component_wrapper<sprite_renderer>{go}; }) "sprite_renderer", sol::property([](gobject& go){ return component_wrapper<sprite_renderer>{go}; }),
"touchable", sol::property([](gobject& go){ return component_wrapper<touchable>{go}; })
); );
} }
} }

View File

@@ -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 <enduro2d/high/components/touchable.hpp>
namespace e2d
{
const char* factory_loader<touchable>::schema_source = R"json({
"type" : "object",
"required" : [],
"additionalProperties" : false,
"properties" : {
}
})json";
bool factory_loader<touchable>::operator()(
touchable& component,
const fill_context& ctx) const
{
E2D_UNUSED(component, ctx);
return true;
}
bool factory_loader<touchable>::operator()(
asset_dependencies& dependencies,
const collect_context& ctx) const
{
E2D_UNUSED(dependencies, ctx);
return true;
}
}

View File

@@ -26,6 +26,7 @@
#include <enduro2d/high/components/scene.hpp> #include <enduro2d/high/components/scene.hpp>
#include <enduro2d/high/components/spine_player.hpp> #include <enduro2d/high/components/spine_player.hpp>
#include <enduro2d/high/components/sprite_renderer.hpp> #include <enduro2d/high/components/sprite_renderer.hpp>
#include <enduro2d/high/components/touchable.hpp>
#include <enduro2d/high/systems/flipbook_system.hpp> #include <enduro2d/high/systems/flipbook_system.hpp>
#include <enduro2d/high/systems/label_system.hpp> #include <enduro2d/high/systems/label_system.hpp>
@@ -195,7 +196,8 @@ namespace e2d
.register_component<spine_player>("spine_player") .register_component<spine_player>("spine_player")
.register_component<events<spine_player_events::event>>("spine_player_events") .register_component<events<spine_player_events::event>>("spine_player_events")
.register_component<commands<spine_player_commands::command>>("spine_player_commands") .register_component<commands<spine_player_commands::command>>("spine_player_commands")
.register_component<sprite_renderer>("sprite_renderer"); .register_component<sprite_renderer>("sprite_renderer")
.register_component<touchable>("touchable");
safe_module_initialize<luasol>(); safe_module_initialize<luasol>();

View File

@@ -1,5 +1,7 @@
{ {
"components" : { "components" : {
"touchable" : {},
"rect_collider" : { "rect_collider" : {
"size" : [1,2], "size" : [1,2],
"pivot" : [2,4] "pivot" : [2,4]

View File

@@ -250,6 +250,8 @@ TEST_CASE("library"){
ecs::registry w; ecs::registry w;
ecs::entity e = w.create_entity(prefab_res->content().prototype()); ecs::entity e = w.create_entity(prefab_res->content().prototype());
REQUIRE(e.exists_component<touchable>());
REQUIRE(e.exists_component<rect_collider>()); REQUIRE(e.exists_component<rect_collider>());
REQUIRE(e.get_component<rect_collider>().size() == v2f(1.f,2.f)); REQUIRE(e.get_component<rect_collider>().size() == v2f(1.f,2.f));
REQUIRE(e.get_component<rect_collider>().pivot() == v2f(2.f,4.f)); REQUIRE(e.get_component<rect_collider>().pivot() == v2f(2.f,4.f));