diff options
| author | 2021-11-05 02:46:04 +1100 | |
|---|---|---|
| committer | 2021-11-05 02:46:04 +1100 | |
| commit | de9ed121867b8665060fb91fc1dbee0dfa3ca6fa (patch) | |
| tree | 790bf80e2da36d3c9cc0542514a96aae2fe7b467 /plugins/inputmacro | |
| parent | f196989f8bbd8163b58aaf20f64904eafbfea52f (diff) | |
plugins: Reduced amnesia for autofire and inputmacro plugins.
Made autofire and inputmacro plugins capable of remembering settings if
the host input device for the binding is missing or if an input for a
slot device that isn't present is referenced.
Diffstat (limited to 'plugins/inputmacro')
| -rw-r--r-- | plugins/inputmacro/init.lua | 11 | ||||
| -rw-r--r-- | plugins/inputmacro/inputmacro_menu.lua | 105 | ||||
| -rw-r--r-- | plugins/inputmacro/inputmacro_persist.lua | 18 |
3 files changed, 80 insertions, 54 deletions
diff --git a/plugins/inputmacro/init.lua b/plugins/inputmacro/init.lua index fc2ed2481f0..36d7aeeca2e 100644 --- a/plugins/inputmacro/init.lua +++ b/plugins/inputmacro/init.lua @@ -15,11 +15,14 @@ function inputmacro.startplugin() Configuration data: * name: display name (string) * binding: activation sequence (input sequence) + * bindingcfg: activation sequence configuration (string) * earlycancel: cancel or complete on release (Boolean) - * loop: -1 = release, 0 = prolong, >0 = loop to step on hold (int) + * loop: -1 = release, 0 = prolong, >0 = loop to step on hold (integer) * steps: * inputs: - * port: port (I/O port) + * port: port tag (string) + * mask: port field mask (integer) + * type: port field type (integer) * field: field (I/O port field) * delay: delay before activating inputs in frames (integer) * duration: duration to activate inputs for (integer) @@ -35,7 +38,9 @@ function inputmacro.startplugin() local function activate_inputs(inputs) for index, input in ipairs(inputs) do - active_inputs[string.format('%s.%d.%d', input.port.tag, input.field.mask, input.field.type)] = input.field + if input.field then + active_inputs[string.format('%s.%d.%d', input.port, input.mask, input.type)] = input.field + end end end diff --git a/plugins/inputmacro/inputmacro_menu.lua b/plugins/inputmacro/inputmacro_menu.lua index 944361c88fe..92c18706509 100644 --- a/plugins/inputmacro/inputmacro_menu.lua +++ b/plugins/inputmacro/inputmacro_menu.lua @@ -37,6 +37,7 @@ local function new_macro() return { name = name, binding = nil, + bindingcfg = '', earlycancel = true, loop = -1, steps = { @@ -44,6 +45,8 @@ local function new_macro() inputs = { { port = nil, + mask = nil, + type = nil, field = nil } }, delay = 0, duration = 1 } } } @@ -83,11 +86,11 @@ function start_input_menu(handler, start_field) table.insert(menu_stack, MENU_TYPES.INPUT) end -function handle_input(index, action) +local function handle_input(index, action) return input_menu:handle(index, action) end -function populate_input() +local function populate_input() return input_menu:populate(input_start_field) end @@ -120,6 +123,7 @@ local function handle_edit_items(index, event) if edit_switch_poller:poll() then if edit_switch_poller.sequence then edit_current_macro.binding = edit_switch_poller.sequence + edit_current_macro.bindingcfg = manager.machine.input:seq_to_tokens(edit_switch_poller.sequence) end edit_switch_poller = nil return true @@ -233,11 +237,12 @@ local function handle_edit_items(index, event) elseif command.action == 'input' then local inputs = edit_current_macro.steps[command.step].inputs if event == 'select' then - local hanlder = - function(field) - inputs[command.input].port = field.port - inputs[command.input].field = field - end + local function hanlder(field) + inputs[command.input].port = field.port.tag + inputs[command.input].mask = field.mask + inputs[command.input].type = field.type + inputs[command.input].field = field + end start_input_menu(hanlder, inputs[command.input].field) edit_start_selection = index return true @@ -250,12 +255,14 @@ local function handle_edit_items(index, event) elseif command.action == 'addinput' then if event == 'select' then local inputs = edit_current_macro.steps[command.step].inputs - local handler = - function(field) - inputs[#inputs + 1] = { - port = field.port, - field = field } - end + local function handler(field) + local newinput = { + port = field.port.tag, + mask = field.mask, + type = field.type, + field = field } + table.insert(inputs, newinput) + end start_input_menu(handler) edit_start_selection = index return true @@ -280,22 +287,23 @@ local function handle_edit_items(index, event) elseif command.action == 'addstep' then if event == 'select' then local steps = edit_current_macro.steps - local handler = - function(field) - local newstep = { - inputs = { - { - port = field.port, - field = field } }, - delay = 0, - duration = 1 } - table.insert(steps, edit_insert_position, newstep) - if edit_current_macro.loop >= edit_insert_position then - edit_current_macro.loop = edit_current_macro.loop + 1 - end - edit_start_step = edit_insert_position - edit_insert_position = edit_insert_position + 1 + local function handler(field) + local newstep = { + inputs = { + { + port = field.port.tag, + mask = field.mask, + type = field.type, + field = field } }, + delay = 0, + duration = 1 } + table.insert(steps, edit_insert_position, newstep) + if edit_current_macro.loop >= edit_insert_position then + edit_current_macro.loop = edit_current_macro.loop + 1 end + edit_start_step = edit_insert_position + edit_insert_position = edit_insert_position + 1 + end start_input_menu(handler) edit_start_selection = index return true @@ -383,7 +391,14 @@ local function add_edit_items(items) edit_items[#items] = { action = 'duration', step = i } for j, input in ipairs(step.inputs) do - local inputname = input.field and _p('input-name', input.field.name) or _p('plugin-inputmacro', '[not set]') + local inputname + if input.field then + inputname = _p('input-name', input.field.name) + elseif input.port then + inputname = _p('plugin-inputmacro', 'n/a') + else + inputname = _p('plugin-inputmacro', '[not set]') + end items[#items + 1] = { string.format(_p('plugin-inputmacro', 'Input %d'), j), inputname, '' } edit_items[#items] = { action = 'input', step = i, input = j } end @@ -456,16 +471,16 @@ end local function populate_add() local items = { } - items[#items + 1] = { _p('plugin-inputmacro', 'Add Input Macro'), '', 'off' } - items[#items + 1] = { '---', '', '' } + table.insert(items, { _p('plugin-inputmacro', 'Add Input Macro'), '', 'off' }) + table.insert(items, { '---', '', '' }) add_edit_items(items) - items[#items + 1] = { '---', '', '' } + table.insert(items, { '---', '', '' }) if current_macro_complete() then - items[#items + 1] = { _p('plugin-inputmacro', 'Create'), '', '' } + table.insert(items, { _p('plugin-inputmacro', 'Create'), '', '' }) else - items[#items + 1] = { _p('plugin-inputmacro', 'Cancel'), '', '' } + table.insert(items, { _p('plugin-inputmacro', 'Cancel'), '', '' }) end edit_item_exit = #items @@ -481,13 +496,13 @@ end local function populate_edit() local items = { } - items[#items + 1] = { _p('plugin-inputmacro', 'Edit Input Macro'), '', 'off' } - items[#items + 1] = { '---', '', '' } + table.insert(items, { _p('plugin-inputmacro', 'Edit Input Macro'), '', 'off' }) + table.insert(items, { '---', '', '' }) add_edit_items(items) - items[#items + 1] = { '---', '', '' } - items[#items + 1] = { _p('plugin-inputmacro', 'Done'), '', '' } + table.insert(items, { '---', '', '' }) + table.insert(items, { _p('plugin-inputmacro', 'Done'), '', '' }) edit_item_exit = #items local selection = edit_start_selection @@ -542,25 +557,25 @@ function populate_macros() local ioport = manager.machine.ioport local items = { } - items[#items + 1] = { _p('plugin-inputmacro', 'Input Macros'), '', 'off' } - items[#items + 1] = { string.format(_p('plugin-inputmacro', 'Press %s to delete'), manager.ui:get_general_input_setting(ioport:token_to_input_type('UI_CLEAR'))), '', 'off' } - items[#items + 1] = { '---', '', '' } + table.insert(items, { _p('plugin-inputmacro', 'Input Macros'), '', 'off' }) + table.insert(items, { string.format(_p('plugin-inputmacro', 'Press %s to delete'), manager.ui:get_general_input_setting(ioport:token_to_input_type('UI_CLEAR'))), '', 'off' }) + table.insert(items, { '---', '', '' }) macros_item_first_macro = #items + 1 if #macros > 0 then for index, macro in ipairs(macros) do - items[#items + 1] = { macro.name, input:seq_name(macro.binding), '' } + table.insert(items, { macro.name, input:seq_name(macro.binding), '' }) if macros_start_macro == index then macros_selection_save = #items end end else - items[#items + 1] = { _p('plugin-inputmacro', '[no macros]'), '', 'off' } + table.insert(items, { _p('plugin-inputmacro', '[no macros]'), '', 'off' }) end macros_start_macro = nil - items[#items + 1] = { '---', '', '' } - items[#items + 1] = { _p('plugin-inputmacro', 'Add macro'), '', '' } + table.insert(items, { '---', '', '' }) + table.insert(items, { _p('plugin-inputmacro', 'Add macro'), '', '' }) macros_item_add = #items local selection = macros_selection_save diff --git a/plugins/inputmacro/inputmacro_persist.lua b/plugins/inputmacro/inputmacro_persist.lua index b66d3c85c5c..4e043852c51 100644 --- a/plugins/inputmacro/inputmacro_persist.lua +++ b/plugins/inputmacro/inputmacro_persist.lua @@ -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 |
