minetest-laptop/app_fw.lua

89 lines
1.9 KiB
Lua
Raw Normal View History

2017-11-23 17:17:59 +01:00
laptop.apps = {}
local app_class = {}
app_class.__index = app_class
2017-12-05 23:15:55 +01:00
laptop.class_lib.app = app_class
2017-11-23 17:17:59 +01:00
-- internally used: get current app formspec
2017-11-23 17:17:59 +01:00
function app_class:get_formspec()
local app_result
if self.formspec_func then
app_result = self.formspec_func(self, self.os)
2017-11-23 17:17:59 +01:00
else
app_result = ""
end
if self.fullscreen then
return app_result
end
if app_result == false then
return false
end
2017-12-06 20:15:57 +01:00
local launcher = self.os:get_app(self.os.hwdef.custom_launcher or "launcher")
2017-12-05 23:15:55 +01:00
local window_formspec = ""
if launcher.appwindow_formspec_func then
window_formspec = launcher.appwindow_formspec_func(launcher, self, self.os)
end
2017-12-05 23:15:55 +01:00
return window_formspec..app_result
2017-11-23 17:17:59 +01:00
end
-- internally used: process input
function app_class:receive_data(method, reshow, sender, ...)
local ret
if self[method] then
ret = self[method](self, self.os, sender, ...)
2017-11-23 17:17:59 +01:00
end
if method == "receive_fields_func" then
2017-12-11 20:04:55 +01:00
local fields = ...
if fields.os_back then
self:back_app()
elseif fields.os_exit then
self:exit_app()
end
end
return ret
2017-11-23 17:17:59 +01:00
end
2017-12-05 23:15:55 +01:00
-- Back to previous app in stack
function app_class:back_app(fields, sender)
self.os.sysram.current_app = self.os:appstack_pop()
if fields then
self.os:pass_to_app('receive_fields_func', true, sender, fields)
end
self.os:set_app(self.os.sysram.current_app)
end
2017-12-05 23:15:55 +01:00
-- Exit current app and back to launcher
function app_class:exit_app()
self.os:set_app() -- launcher
end
function app_class:get_timer()
self.os.timer = self.os.timer or minetest.get_node_timer(self.os.pos)
return self.os.timer
end
-- Register new app
2017-11-23 17:17:59 +01:00
function laptop.register_app(name, def)
laptop.apps[name] = def
end
-- Register new app
function laptop.register_view(name, def)
def.view = true
laptop.apps[name] = def
end
-- load all apps
local app_path = minetest.get_modpath('laptop')..'/apps/'
local app_list = minetest.get_dir_list(app_path, false)
2017-11-23 17:17:59 +01:00
for _, file in ipairs(app_list) do
if file:sub(-8) == '_app.lua' then
dofile(app_path..file)
2017-11-23 17:17:59 +01:00
end
end