2024-10-03 01:29:13 +00:00
|
|
|
HAS_SETUP_WINDOW = false
|
|
|
|
|
2024-09-29 19:59:48 +00:00
|
|
|
---Return the userdata's name from its metatable.
|
|
|
|
---
|
|
|
|
---Returns nil if the userdata doesn't have a metatable.
|
2024-04-27 04:52:47 +00:00
|
|
|
---@param val userdata
|
2024-09-29 19:59:48 +00:00
|
|
|
---@return string|nil
|
2024-04-27 04:52:47 +00:00
|
|
|
function udname(val)
|
2024-09-29 19:59:48 +00:00
|
|
|
local tbl = debug.getmetatable(val)
|
|
|
|
|
|
|
|
if tbl == nil then
|
|
|
|
return nil
|
2024-09-28 16:32:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return tbl.__name
|
2024-04-27 04:52:47 +00:00
|
|
|
end
|
2024-09-28 16:32:37 +00:00
|
|
|
|
2024-04-27 04:52:47 +00:00
|
|
|
|
|
|
|
function on_init()
|
|
|
|
local cube = world:request_res("../assets/cube-texture-embedded.gltf")
|
|
|
|
print("Loaded textured cube (" .. udname(cube) .. ")")
|
|
|
|
|
2024-09-29 19:59:48 +00:00
|
|
|
cube:wait_until_loaded()
|
2024-04-27 04:52:47 +00:00
|
|
|
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)
|
2024-09-29 19:59:48 +00:00
|
|
|
print("spawned entity " .. tostring(e))
|
2024-04-27 04:52:47 +00:00
|
|
|
end
|
|
|
|
|
2024-10-03 01:29:13 +00:00
|
|
|
function on_first()
|
|
|
|
if not HAS_SETUP_WINDOW then
|
|
|
|
world:view(function (w)
|
|
|
|
if w.cursor_grab == CursorGrabMode.NONE then
|
|
|
|
w.cursor_grab = CursorGrabMode.LOCKED
|
|
|
|
w.cursor_visible = false
|
|
|
|
return w
|
|
|
|
else
|
|
|
|
HAS_SETUP_WINDOW = true
|
|
|
|
print("Window setup")
|
|
|
|
end
|
|
|
|
end, Window)
|
|
|
|
end
|
2024-04-27 04:52:47 +00:00
|
|
|
end
|
|
|
|
|
2024-10-03 01:29:13 +00:00
|
|
|
--[[ function on_pre_update()
|
2024-04-27 04:52:47 +00:00
|
|
|
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
|
2024-09-29 18:35:24 +00:00
|
|
|
local dt = world:resource(DeltaTime)
|
2024-04-27 04:52:47 +00:00
|
|
|
|
|
|
|
world:view(function (t)
|
|
|
|
t:translate(0, 0.15 * dt, 0)
|
|
|
|
return t
|
2024-09-29 18:35:24 +00:00
|
|
|
end, Transform)
|
2024-04-27 04:52:47 +00:00
|
|
|
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 ]]
|