add standard components test
This commit is contained in:
@@ -7,5 +7,6 @@ function on_despawn(eid)
|
||||
end
|
||||
|
||||
function on_grounded(eid)
|
||||
Transform.set_rot(eid, mat4.rotate({0, 1, 0}, math.random()*360))
|
||||
local entity = stdcomp.new_Entity(eid) -- test
|
||||
entity.transform:set_rot(mat4.rotate({0, 1, 0}, math.random()*360))
|
||||
end
|
||||
|
||||
@@ -8,8 +8,8 @@ function on_hud_open()
|
||||
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
|
||||
local eid = entity.spawn("base:drop", ppos)
|
||||
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
||||
Rigidbody.set_vel(eid, vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
|
||||
Transform.set_rot(eid,
|
||||
__rigidbody.set_vel(eid, vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
|
||||
__transform.set_rot(eid,
|
||||
mat4.rotate(mat4.rotate(mat4.rotate({0, 1, 0}, math.random() * 360),
|
||||
{1, 0, 0}, math.random() * 360), {0, 0, 1}, math.random() * 360))
|
||||
end)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
-- Standard components OOP wrappers (__index tables of metatables)
|
||||
|
||||
local Transform = {__index={
|
||||
get_pos=function(self) return __transform.get_pos(self.eid) end,
|
||||
set_pos=function(self, v) return __transform.set_pos(self.eid, v) end,
|
||||
get_rot=function(self) return __transform.get_rot(self.eid) end,
|
||||
set_rot=function(self, m) return __transform.set_rot(self.eid, m) end,
|
||||
}}
|
||||
|
||||
function new_Transform(eid)
|
||||
return setmetatable({eid=eid}, Transform)
|
||||
end
|
||||
|
||||
local Rigidbody = {__index={
|
||||
is_enabled=function(self) return __rigidbody.is_enabled(self.eid) end,
|
||||
set_enabled=function(self, f) return __rigidbody.set_enabled(self.eid, f) end,
|
||||
get_vel=function(self) return __rigidbody.get_vel(self.eid) end,
|
||||
set_vel=function(self, v) return __rigidbody.set_vel(self.eid, v) end,
|
||||
get_size=function(self) return __rigidbody.get_size(self.eid) end,
|
||||
}}
|
||||
|
||||
function new_Rigidbody(eid)
|
||||
return setmetatable({eid=eid}, Rigidbody)
|
||||
end
|
||||
|
||||
-- Entity class
|
||||
|
||||
local Entity = {__index={}}
|
||||
|
||||
return {new_Entity = function(eid)
|
||||
local entity = setmetatable({eid=eid}, Entity)
|
||||
entity.transform = new_Transform(eid)
|
||||
entity.rigidbody = new_Rigidbody(eid)
|
||||
return entity
|
||||
end}
|
||||
@@ -303,6 +303,8 @@ function file.readlines(path)
|
||||
return lines
|
||||
end
|
||||
|
||||
stdcomp = require "core:internal/stdcomp"
|
||||
|
||||
-- Deprecated functions
|
||||
block_index = block.index
|
||||
block_name = block.name
|
||||
|
||||
Reference in New Issue
Block a user