87 lines
2.1 KiB
Lua
87 lines
2.1 KiB
Lua
local is_window_setup = false
|
|
|
|
---Return the userdata's name from its metatable.
|
|
---
|
|
---Returns nil if the userdata doesn't have a metatable.
|
|
---@param val userdata
|
|
---@return string|nil
|
|
function udname(val)
|
|
local tbl = debug.getmetatable(val)
|
|
|
|
if tbl == nil then
|
|
return nil
|
|
end
|
|
|
|
return tbl.__name
|
|
end
|
|
|
|
|
|
function on_init()
|
|
local cube = world:request_asset("../assets/cube-texture-embedded.gltf") --[[@as GltfHandle]]
|
|
print("Loaded textured cube (" .. udname(cube) .. ")")
|
|
|
|
cube:wait_until_loaded()
|
|
local scenes = cube:scenes()
|
|
local cube_scene = scenes[1]
|
|
|
|
local pos = Transform.from_translation(Vec3.new(0, 0, -8.0))
|
|
|
|
local e = world:spawn(pos, cube_scene)
|
|
print("spawned entity " .. tostring(e))
|
|
end
|
|
|
|
function on_first()
|
|
if not is_window_setup then
|
|
world:view(
|
|
---@param w Window
|
|
function (w)
|
|
if w.cursor_grab == CursorGrabMode.NONE then
|
|
w.cursor_grab = CursorGrabMode.LOCKED
|
|
w.cursor_visible = false
|
|
return w
|
|
else
|
|
is_window_setup = true
|
|
print("Window setup")
|
|
end
|
|
end, Window
|
|
)
|
|
end
|
|
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(
|
|
---@param t Transform
|
|
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 ]] |