2016-04-27 16:36:04 +02:00
|
|
|
-- license:BSD-3-Clause
|
|
|
|
-- copyright-holders:Carl
|
2016-08-30 07:53:27 +02:00
|
|
|
-- Layout scripts should return a table and a string. The table can have two optional keys reset and frame
|
2016-04-27 16:36:04 +02:00
|
|
|
-- which have functions for values called on reset and frame draw respectively and the string is a unique name.
|
|
|
|
local exports = {}
|
|
|
|
exports.name = "layout"
|
|
|
|
exports.version = "0.0.1"
|
|
|
|
exports.description = "Layout helper plugin"
|
|
|
|
exports.license = "The BSD 3-Clause License"
|
|
|
|
exports.author = { name = "Carl" }
|
|
|
|
|
|
|
|
local layout = exports
|
|
|
|
|
|
|
|
function layout.startplugin()
|
|
|
|
local scripts = {}
|
2020-11-25 09:18:26 +01:00
|
|
|
local function prepare_layout(file, script)
|
|
|
|
local env = {
|
2020-12-26 15:32:37 +01:00
|
|
|
machine = manager.machine,
|
2020-12-05 11:04:22 +01:00
|
|
|
emu = {
|
|
|
|
render_bounds = emu.render_bounds,
|
|
|
|
render_color = emu.render_color,
|
|
|
|
print_verbose = emu.print_verbose,
|
|
|
|
print_error = emu.print_error,
|
|
|
|
print_info = emu.print_info,
|
|
|
|
print_debug = emu.print_debug },
|
2020-11-25 09:18:26 +01:00
|
|
|
file = file,
|
|
|
|
print = print,
|
|
|
|
pairs = pairs,
|
|
|
|
ipairs = ipairs,
|
|
|
|
string = { format = string.format },
|
|
|
|
table = { insert = table.insert, remove = table.remove } }
|
2016-04-27 16:36:04 +02:00
|
|
|
local script, err = load(script, script, "t", env)
|
|
|
|
if not script then
|
|
|
|
emu.print_verbose("error loading layout script " .. err)
|
|
|
|
return
|
|
|
|
end
|
2020-11-25 09:18:26 +01:00
|
|
|
local hooks = script()
|
|
|
|
if hooks ~= nil then
|
|
|
|
table.insert(scripts, hooks)
|
|
|
|
end
|
2016-04-27 16:36:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
emu.register_callback(prepare_layout, "layout")
|
|
|
|
emu.register_frame(function()
|
2020-12-26 15:32:37 +01:00
|
|
|
if manager.machine.paused then
|
2016-04-27 16:36:04 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
for num, scr in pairs(scripts) do
|
|
|
|
if scr.frame then
|
|
|
|
scr.frame()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
emu.register_start(function()
|
|
|
|
for num, scr in pairs(scripts) do
|
|
|
|
if scr.reset then
|
|
|
|
scr.reset()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
emu.register_stop(function() scripts = {} end)
|
|
|
|
end
|
|
|
|
|
|
|
|
return exports
|