2016-09-06 04:43:17 +02:00
|
|
|
-- license:BSD-3-Clause
|
|
|
|
-- copyright-holders:Carl
|
|
|
|
-- A data script should contain two functions check which takes a set name and returns the data
|
|
|
|
-- heading if it supports the set otherwise nil and get which returns the data
|
|
|
|
-- the script should be named data_<name>.lua
|
|
|
|
-- this is set default on in the plugin.json
|
|
|
|
local exports = {}
|
|
|
|
exports.name = "data"
|
|
|
|
exports.version = "0.0.1"
|
|
|
|
exports.description = "Data plugin"
|
|
|
|
exports.license = "The BSD 3-Clause License"
|
|
|
|
exports.author = { name = "Carl" }
|
|
|
|
|
|
|
|
local data = exports
|
|
|
|
|
|
|
|
function data.set_folder(path)
|
|
|
|
data.path = path
|
|
|
|
end
|
|
|
|
|
|
|
|
function data.startplugin()
|
|
|
|
local data_scr = {}
|
|
|
|
local valid_lst = {}
|
2016-09-07 05:11:01 +02:00
|
|
|
local cur_set
|
|
|
|
local cur_list
|
2016-09-06 04:43:17 +02:00
|
|
|
emu.register_start(function()
|
2016-09-07 05:11:01 +02:00
|
|
|
data_scr = {}
|
2016-09-06 04:43:17 +02:00
|
|
|
for file in lfs.dir(data.path) do
|
|
|
|
local name = string.match(file, "^(data_.*).lua$")
|
|
|
|
if name then
|
|
|
|
local script = require("data/" .. name)
|
|
|
|
if script then
|
|
|
|
data_scr[#data_scr + 1] = script
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
emu.register_callback(function(set)
|
2016-11-01 21:27:21 +01:00
|
|
|
local ret = {}
|
2016-09-07 16:00:08 +02:00
|
|
|
if set == "" then
|
|
|
|
set = emu.romname()
|
|
|
|
end
|
2016-09-07 05:11:01 +02:00
|
|
|
if set == cur_set then
|
|
|
|
return cur_list
|
|
|
|
end
|
2016-09-07 16:00:08 +02:00
|
|
|
cur_set = set
|
2016-09-07 05:11:01 +02:00
|
|
|
if not set then
|
|
|
|
return nil
|
|
|
|
end
|
2016-09-06 04:43:17 +02:00
|
|
|
valid_lst = {}
|
|
|
|
for num, scr in ipairs(data_scr) do
|
|
|
|
local setname, softname = set:match("^([^,]+),?(.*)$")
|
|
|
|
if softname == "" then
|
|
|
|
softname = nil
|
|
|
|
end
|
|
|
|
local name = scr.check(setname, softname)
|
|
|
|
if name then
|
2016-11-01 21:27:21 +01:00
|
|
|
ret[#ret + 1] = name
|
2016-09-06 04:43:17 +02:00
|
|
|
valid_lst[#valid_lst + 1] = scr
|
|
|
|
end
|
|
|
|
end
|
2016-09-07 05:11:01 +02:00
|
|
|
cur_list = ret
|
2016-09-06 04:43:17 +02:00
|
|
|
return ret
|
|
|
|
end, "data_list")
|
|
|
|
|
|
|
|
emu.register_callback(function(num)
|
|
|
|
return valid_lst[num + 1].get()
|
|
|
|
end, "data")
|
2016-09-07 05:11:01 +02:00
|
|
|
|
|
|
|
emu.register_callback(function(num)
|
|
|
|
local ver
|
|
|
|
if valid_lst[num + 1].ver then
|
|
|
|
ver = valid_lst[num + 1].ver()
|
|
|
|
end
|
|
|
|
if ver then
|
|
|
|
return ver
|
|
|
|
end
|
|
|
|
return ""
|
|
|
|
end, "data_version")
|
2016-09-06 04:43:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return exports
|