-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
90 lines (69 loc) · 2.45 KB
/
Copy pathinit.lua
File metadata and controls
90 lines (69 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
local log = function(msg, ...)
minetest.log("action", "[ui] " .. msg:format(...))
end
modname = minetest.get_current_modname()
modpath = minetest.get_modpath(modname)
_G.ui = {} -- global, if you want
-- log
ui.log = log
-- Load utils first
ui.util = dofile(modpath .. "/util.lua")
-- Session
ui.session = ui.util.doModfile("session.lua")
-- Widgets
ui.widgets = ui.util.doModfile("widgets/init.lua")
-- Style
ui.get_style = ui.util.doModfile("style/get_style.lua")
ui.merge_theme = ui.util.doModfile("style/merge_theme.lua")
ui.stylegen = ui.util.doModfile("style/stylegen.lua")
ui.themes = ui.util.doModfile("style/themes.lua")
-- Engine
local Hooks = ui.util.doModfile("engine/hooks.lua")
local hooks = Hooks:new(function(user) render:renderRoot(user) end)
ui.hooks = hooks
local vnode = ui.util.doModfile("engine/vnode.lua")
local flatten = ui.util.doModfile("engine/flatten.lua")
local Events = ui.util.doModfile("engine/events.lua")
ui.events = Events:new()
-- Coordination layer
engine = {
flatten = function() return flatten end,
hooks = function() return hooks end,
widgets = ui.widgets,
}
local Render = ui.util.doModfile("engine/render.lua")
local render = Render:new(engine)
ui.render = render
-- NOW wire hooks to renderRoot
hooks.renderRoot = function(user) render:renderRoot(user) end
ui.createElement = vnode.createElement
ui.useState = function(...) return hooks:useState(...) end
ui.useEffect = function(...) return hooks:useEffect(...) end
ui.flatten = flatten
-- Register with in-game events
ui.util.doModfile("game_events.lua")
-- Elements
-- List all .lua files in /elements (except elements.lua)
local elements_path = modpath .. "/elements"
for _, file in ipairs(minetest.get_dir_list(elements_path, false)) do
if file:match("%.lua$") then
local name = file:sub(1, -5)
if ui[name] then
error("Element collision: ui." .. name .. " already exists")
end
local fn = dofile(elements_path .. "/" .. file)
if type(fn) ~= "function" then
error("Element file '" .. file .. "' did not return a function")
end
ui[name] = fn
ui.log("Loaded element: " .. name)
end
end
-- === Examples ===
local examples_path = modpath .. "/examples"
for _, fname in ipairs(minetest.get_dir_list(examples_path, false)) do
if fname:match("%.lua$") then
dofile(examples_path .. "/" .. fname)
minetest.log("action", "[ui.loader] Loaded example: " .. fname)
end
end