lyra-engine/examples/lua-scripting/scripts/test.lua

64 lines
1.5 KiB
Lua
Raw Normal View History

---Return the userdata's name from its metatable
---@param val userdata
---@return string
function udname(val)
return getmetatable(val).__name
end
function on_init()
2024-06-16 19:34:06 +00:00
--[[ local cube = world:request_res("../assets/cube-texture-embedded.gltf")
print("Loaded textured cube (" .. udname(cube) .. ")")
cube:wait_until_loaded()
local scenes = cube:scenes()
2024-06-16 19:34:06 +00:00
local cube_scene = scenes[1] ]]
2024-06-16 19:34:06 +00:00
print("creating vec3")
local v3 = Vec3.new(0, 0, -8.0)
print("creating Transform")
local pos = Transform.from_translation(v3)
print("created Transform")
2024-06-16 19:34:06 +00:00
print("spawning cube")
local e = world:spawn(pos)
print("spawned entity " .. tostring(e))
end
--[[ function on_first()
print("Lua's first function was called")
end
function on_pre_update()
print("Lua's pre-update function was called")
end ]]
function on_update()
--[[ ---@type number
local dt = world:resource(DeltaTime)
local act = world:resource(ActionHandler)
---@type number
local move_objs = act:get_axis("ObjectsMoveUpDown")
world:view(function (t)
if move_objs ~= nil then
t:translate(0, move_objs * 0.35 * dt, 0)
return t
end
end, Transform) ]]
---@type number
local dt = world:resource(DeltaTime)
world:view(function (t)
t:translate(0, 0.15 * dt, 0)
return t
end, Transform)
end
--[[ function on_post_update()
print("Lua's post-update function was called")
end
function on_last()
print("Lua's last function was called")
end ]]