mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
dummy touchable component
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace e2d
|
||||
class scene;
|
||||
class spine_player;
|
||||
class sprite_renderer;
|
||||
class touchable;
|
||||
|
||||
class flipbook_system;
|
||||
class label_system;
|
||||
|
||||
33
headers/enduro2d/high/components/touchable.hpp
Normal file
33
headers/enduro2d/high/components/touchable.hpp
Normal 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;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
---@class touchable
|
||||
local touchable = {
|
||||
}
|
||||
|
||||
---@type touchable
|
||||
_G.touchable = _G.touchable or touchable
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <enduro2d/high/components/scene.hpp>
|
||||
#include <enduro2d/high/components/spine_player.hpp>
|
||||
#include <enduro2d/high/components/sprite_renderer.hpp>
|
||||
#include <enduro2d/high/components/touchable.hpp>
|
||||
|
||||
namespace e2d::bindings::high
|
||||
{
|
||||
@@ -52,7 +53,8 @@ namespace e2d::bindings::high
|
||||
"renderer", sol::property([](gobject& go){ return component_wrapper<renderer>{go}; }),
|
||||
"scene", sol::property([](gobject& go){ return component_wrapper<scene>{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}; })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
34
sources/enduro2d/high/components/touchable.cpp
Normal file
34
sources/enduro2d/high/components/touchable.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <enduro2d/high/components/scene.hpp>
|
||||
#include <enduro2d/high/components/spine_player.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/label_system.hpp>
|
||||
@@ -195,7 +196,8 @@ namespace e2d
|
||||
.register_component<spine_player>("spine_player")
|
||||
.register_component<events<spine_player_events::event>>("spine_player_events")
|
||||
.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>();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"components" : {
|
||||
"touchable" : {},
|
||||
|
||||
"rect_collider" : {
|
||||
"size" : [1,2],
|
||||
"pivot" : [2,4]
|
||||
|
||||
@@ -250,6 +250,8 @@ TEST_CASE("library"){
|
||||
ecs::registry w;
|
||||
ecs::entity e = w.create_entity(prefab_res->content().prototype());
|
||||
|
||||
REQUIRE(e.exists_component<touchable>());
|
||||
|
||||
REQUIRE(e.exists_component<rect_collider>());
|
||||
REQUIRE(e.get_component<rect_collider>().size() == v2f(1.f,2.f));
|
||||
REQUIRE(e.get_component<rect_collider>().pivot() == v2f(2.f,4.f));
|
||||
|
||||
Reference in New Issue
Block a user