mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 04:51:49 +00:00
add standard components test
This commit is contained in:
parent
e0e5faa4a8
commit
c54be7b2b1
6 changed files with 46 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
35
res/modules/internal/stdcomp.lua
Normal file
35
res/modules/internal/stdcomp.lua
Normal file
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue