summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/inputmacro/inputmacro_persist.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/inputmacro/inputmacro_persist.lua')
-rw-r--r--plugins/inputmacro/inputmacro_persist.lua36
1 files changed, 21 insertions, 15 deletions
diff --git a/plugins/inputmacro/inputmacro_persist.lua b/plugins/inputmacro/inputmacro_persist.lua
index 9c9e9322eed..b8670800fa4 100644
--- a/plugins/inputmacro/inputmacro_persist.lua
+++ b/plugins/inputmacro/inputmacro_persist.lua
@@ -5,7 +5,7 @@
-- Helpers
local function settings_path()
- return emu.subst_env(manager.machine.options.entries.homepath:value():match('([^;]+)')) .. '/inputmacro/'
+ return manager.machine.options.entries.homepath:value():match('([^;]+)') .. '/inputmacro'
end
local function settings_filename()
@@ -20,6 +20,7 @@ local function make_macro(setting)
local result = {
name = setting.name,
binding = manager.machine.input:seq_from_tokens(setting.binding),
+ bindingcfg = setting.binding,
earlycancel = setting.earlycancel,
loop = setting.loop,
steps = { } }
@@ -33,13 +34,18 @@ local function make_macro(setting)
duration = step.duration }
for j, input in ipairs(step.inputs) do
if input.port and input.mask and input.type then
+ local ipt = {
+ port = input.port,
+ mask = input.mask,
+ type = ioport:token_to_input_type(input.type) }
local port = ioport.ports[input.port]
if port then
local field = port:field(input.mask)
- if field and (field.type == ioport:token_to_input_type(input.type)) then
- table.insert(s.inputs, { port = port, field = field })
+ if field and (field.type == ipt.type) then
+ ipt.field = field
end
end
+ table.insert(s.inputs, ipt)
end
end
if #s.inputs > 0 then
@@ -66,7 +72,7 @@ local function make_settings(macros)
for i, macro in ipairs(macros) do
local m = {
name = macro.name,
- binding = input:seq_to_tokens(macro.binding),
+ binding = macro.bindingcfg,
earlycancel = macro.earlycancel,
loop = macro.loop,
steps = { } }
@@ -79,9 +85,9 @@ local function make_settings(macros)
table.insert(m.steps, s)
for k, input in ipairs(step.inputs) do
local b = {
- port = input.port.tag,
- mask = input.field.mask,
- type = ioport:input_type_to_token(input.field.type) }
+ port = input.port,
+ mask = input.mask,
+ type = ioport:input_type_to_token(input.type) }
table.insert(s.inputs, b)
end
end
@@ -95,7 +101,7 @@ end
local lib = { }
function lib:load_settings()
- filename = settings_path() .. settings_filename()
+ local filename = settings_path() .. '/' .. settings_filename()
local file = io.open(filename, 'r')
if not file then
return { }
@@ -104,7 +110,7 @@ function lib:load_settings()
local settings = json.parse(file:read('a'))
file:close()
if not settings then
- emu.print_error(string.format('Error loading input macros: error parsing file "%s" as JSON\n', filename))
+ emu.print_error(string.format('Error loading input macros: error parsing file "%s" as JSON', filename))
return { }
end
@@ -121,17 +127,17 @@ end
function lib:save_settings(macros)
local path = settings_path()
local stat = lfs.attributes(path)
- if not stat then
- lfs.mkdir(path)
- elseif stat.mode ~= 'directory' then
- emu.print_error(string.format('Error saving input macros: "%s" is not a directory\n', path))
+ if stat and (stat.mode ~= 'directory') then
+ emu.print_error(string.format('Error saving input macros: "%s" is not a directory', path))
return
end
- filename = path .. settings_filename()
+ local filename = path .. '/' .. settings_filename()
if #macros == 0 then
os.remove(filename)
return
+ elseif not stat then
+ lfs.mkdir(path)
end
local json = require('json')
@@ -139,7 +145,7 @@ function lib:save_settings(macros)
local text = json.stringify(settings, { indent = true })
local file = io.open(filename, 'w')
if not file then
- emu.print_error(string.format('Error saving input macros: error opening file "%s" for writing\n', filename))
+ emu.print_error(string.format('Error saving input macros: error opening file "%s" for writing', filename))
return
end
file:write(text)