mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
rigid_body type
This commit is contained in:
@@ -15,11 +15,22 @@
|
||||
namespace e2d
|
||||
{
|
||||
class rigid_body final {
|
||||
public:
|
||||
ENUM_HPP_CLASS_DECL(types, u8,
|
||||
(dynamic)
|
||||
(kinematic))
|
||||
public:
|
||||
rigid_body() = default;
|
||||
|
||||
rigid_body& type(types value) noexcept;
|
||||
[[nodiscard]] types type() const noexcept;
|
||||
private:
|
||||
types type_ = types::dynamic;
|
||||
};
|
||||
}
|
||||
|
||||
ENUM_HPP_REGISTER_TRAITS(e2d::rigid_body::types)
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
template <>
|
||||
@@ -47,3 +58,15 @@ namespace e2d
|
||||
void operator()(gcomponent<rigid_body>& c) const;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
inline rigid_body& rigid_body::type(types value) noexcept {
|
||||
type_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline rigid_body::types rigid_body::type() const noexcept {
|
||||
return type_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,68 @@
|
||||
}
|
||||
},
|
||||
"children" : [{
|
||||
"prototype" : "../prefabs/camera_prefab.json"
|
||||
"prototype" : "../prefabs/camera_prefab.json",
|
||||
"components" : {
|
||||
"named" : {
|
||||
"name" : "camera"
|
||||
}
|
||||
}
|
||||
},{
|
||||
"prototype" : "../prefabs/ship_prefab.json",
|
||||
"components" : {
|
||||
"named" : {
|
||||
"name" : "ship(1)"
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [0,0],
|
||||
"scale" : 1
|
||||
"rotation" : 1
|
||||
},
|
||||
"behaviour" : {
|
||||
"script" : "../scripts/sample_08/ship.lua"
|
||||
},
|
||||
"touchable" : {},
|
||||
"rigid_body" : {
|
||||
"type" : "dynamic"
|
||||
},
|
||||
"rect_collider" : {
|
||||
"size" : [66,113]
|
||||
}
|
||||
}
|
||||
},{
|
||||
"prototype" : "../prefabs/ship_prefab.json",
|
||||
"components" : {
|
||||
"named" : {
|
||||
"name" : "ship(2)"
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [45,100],
|
||||
"rotation" : 0
|
||||
},
|
||||
"behaviour" : {
|
||||
"script" : "../scripts/sample_08/ship.lua"
|
||||
},
|
||||
"touchable" : {},
|
||||
"rigid_body" : {
|
||||
"type" : "dynamic"
|
||||
},
|
||||
"rect_collider" : {
|
||||
"size" : [66,113]
|
||||
}
|
||||
}
|
||||
},{
|
||||
"components" : {
|
||||
"named" : {
|
||||
"name" : "floor"
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [0,-240]
|
||||
},
|
||||
"rigid_body" : {
|
||||
"type" : "kinematic"
|
||||
},
|
||||
"rect_collider" : {
|
||||
"size" : [320, 50]
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -6,13 +6,6 @@
|
||||
|
||||
---@class ship_meta
|
||||
|
||||
---@param meta ship_meta
|
||||
---@param go gobject
|
||||
local function update_ship_rotation(meta, go)
|
||||
local time = the_engine.time
|
||||
go.actor.node.rotation = time
|
||||
end
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
--
|
||||
-- meta
|
||||
@@ -24,13 +17,11 @@ local M = {}
|
||||
---@param meta ship_meta
|
||||
---@param go gobject
|
||||
function M.on_start(meta, go)
|
||||
meta.life_time = 5
|
||||
end
|
||||
|
||||
---@param meta ship_meta
|
||||
---@param go gobject
|
||||
function M.on_update(meta, go)
|
||||
update_ship_rotation(meta, go)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -13,6 +13,16 @@ namespace e2d
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"type" : { "$ref": "#/definitions/types" }
|
||||
},
|
||||
"definitions" : {
|
||||
"types" : {
|
||||
"type" : "string",
|
||||
"enum" : [
|
||||
"dynamic",
|
||||
"kinematic"
|
||||
]
|
||||
}
|
||||
}
|
||||
})json";
|
||||
|
||||
@@ -20,7 +30,15 @@ namespace e2d
|
||||
rigid_body& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(component, ctx);
|
||||
if ( ctx.root.HasMember("type") ) {
|
||||
rigid_body::types type = component.type();
|
||||
if ( !json_utils::try_parse_value(ctx.root["type"], type) ) {
|
||||
the<debug>().error("RIGID_BODY: Incorrect formatting of 'type' property");
|
||||
return false;
|
||||
}
|
||||
component.type(type);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,6 +56,10 @@ namespace e2d
|
||||
const char* component_inspector<rigid_body>::title = "rigid_body";
|
||||
|
||||
void component_inspector<rigid_body>::operator()(gcomponent<rigid_body>& c) const {
|
||||
E2D_UNUSED(c);
|
||||
if ( rigid_body::types type = c->type();
|
||||
imgui_utils::show_enum_combo_box("type", &type) )
|
||||
{
|
||||
c->type(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user