dummy rigid_body component

This commit is contained in:
2019-11-29 09:07:25 +07:00
parent 7b6615b767
commit b80cdeb0e7
12 changed files with 153 additions and 0 deletions

View File

@@ -40,6 +40,7 @@
#include "components/model_renderer.hpp"
#include "components/named.hpp"
#include "components/renderer.hpp"
#include "components/rigid_body.hpp"
#include "components/scene.hpp"
#include "components/spine_player.hpp"
#include "components/sprite_renderer.hpp"

View File

@@ -60,6 +60,7 @@ namespace e2d
class model_renderer;
class named;
class renderer;
class rigid_body;
class scene;
class spine_player;
class sprite_renderer;

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 rigid_body final {
public:
rigid_body() = default;
};
template <>
class factory_loader<rigid_body> final : factory_loader<> {
public:
static const char* schema_source;
bool operator()(
rigid_body& component,
const fill_context& ctx) const;
bool operator()(
asset_dependencies& dependencies,
const collect_context& ctx) const;
};
}

View File

@@ -0,0 +1,19 @@
---@class rigid_body
local rigid_body = {
---@type boolean
enabled = true,
---@type boolean
disabled = false
}
---@overload fun(self: rigid_body)
---@param self rigid_body
function rigid_body.enable(self) end
---@overload fun(self: rigid_body)
---@param self rigid_body
function rigid_body.disable(self) end
---@type rigid_body
_G.rigid_body = _G.rigid_body or rigid_body

View File

@@ -39,6 +39,9 @@ local gobject = {
---@type renderer
renderer = nil,
---@type rigid_body
rigid_body = nil,
---@type scene
scene = nil,

View File

@@ -26,6 +26,7 @@ namespace e2d::bindings::high
void bind_model_renderer(sol::state& l);
void bind_named(sol::state& l);
void bind_renderer(sol::state& l);
void bind_rigid_body(sol::state& l);
void bind_scene(sol::state& l);
void bind_spine_player(sol::state& l);
void bind_sprite_renderer(sol::state& l);
@@ -51,6 +52,7 @@ namespace e2d::bindings
high::bind_model_renderer(l);
high::bind_named(l);
high::bind_renderer(l);
high::bind_rigid_body(l);
high::bind_scene(l);
high::bind_spine_player(l);
high::bind_sprite_renderer(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/disabled.hpp>
#include <enduro2d/high/components/rigid_body.hpp>
namespace e2d::bindings::high
{
void bind_rigid_body(sol::state& l) {
l.new_usertype<gcomponent<rigid_body>>("rigid_body",
sol::no_constructor,
"enable", [](gcomponent<rigid_body>& c){
c.owner().component<disabled<rigid_body>>().remove();
},
"disable", [](gcomponent<rigid_body>& c){
c.owner().component<disabled<rigid_body>>().ensure();
},
"enabled", sol::property(
[](const gcomponent<rigid_body>& c) -> bool {
return !c.owner().component<disabled<rigid_body>>().exists();
},
[](gcomponent<rigid_body>& c, bool yesno){
if ( yesno ) {
c.owner().component<disabled<rigid_body>>().remove();
} else {
c.owner().component<disabled<rigid_body>>().ensure();
}
}
),
"disabled", sol::property(
[](const gcomponent<rigid_body>& c) -> bool {
return c.owner().component<disabled<rigid_body>>().exists();
},
[](gcomponent<rigid_body>& c, bool yesno){
if ( yesno ) {
c.owner().component<disabled<rigid_body>>().ensure();
} else {
c.owner().component<disabled<rigid_body>>().remove();
}
}
)
);
}
}

View File

@@ -17,6 +17,7 @@
#include <enduro2d/high/components/model_renderer.hpp>
#include <enduro2d/high/components/named.hpp>
#include <enduro2d/high/components/renderer.hpp>
#include <enduro2d/high/components/rigid_body.hpp>
#include <enduro2d/high/components/scene.hpp>
#include <enduro2d/high/components/spine_player.hpp>
#include <enduro2d/high/components/sprite_renderer.hpp>
@@ -51,6 +52,7 @@ namespace e2d::bindings::high
"model_renderer", sol::property([](gobject& go){ return component_wrapper<model_renderer>{go}; }),
"named", sol::property([](gobject& go){ return component_wrapper<named>{go}; }),
"renderer", sol::property([](gobject& go){ return component_wrapper<renderer>{go}; }),
"rigid_body", sol::property([](gobject& go){ return component_wrapper<rigid_body>{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}; }),

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

View File

@@ -23,6 +23,7 @@
#include <enduro2d/high/components/model_renderer.hpp>
#include <enduro2d/high/components/named.hpp>
#include <enduro2d/high/components/renderer.hpp>
#include <enduro2d/high/components/rigid_body.hpp>
#include <enduro2d/high/components/scene.hpp>
#include <enduro2d/high/components/spine_player.hpp>
#include <enduro2d/high/components/sprite_renderer.hpp>
@@ -195,6 +196,7 @@ namespace e2d
.register_component<model_renderer>("model_renderer")
.register_component<named>("named")
.register_component<renderer>("renderer")
.register_component<rigid_body>("rigid_body")
.register_component<scene>("scene")
.register_component<spine_player>("spine_player")
.register_component<events<spine_player_events::event>>("spine_player_events")

View File

@@ -1,5 +1,6 @@
{
"components" : {
"rigid_body" : {},
"touchable" : {},
"rect_collider" : {

View File

@@ -250,6 +250,7 @@ TEST_CASE("library"){
ecs::registry w;
ecs::entity e = w.create_entity(prefab_res->content().prototype());
REQUIRE(e.exists_component<rigid_body>());
REQUIRE(e.exists_component<touchable>());
REQUIRE(e.exists_component<rect_collider>());