diff --git a/plugins/autofire/autofire_menu.lua b/plugins/autofire/autofire_menu.lua index f5f46a96d1e..1533465105f 100644 --- a/plugins/autofire/autofire_menu.lua +++ b/plugins/autofire/autofire_menu.lua @@ -265,6 +265,14 @@ local function handle_button_menu(index, event) return false end +function lib:init_menu(buttons) + header_height = 0 + content_height = 0 + menu_stack = { MENU_TYPES.MAIN } + current_button = {} + inputs = {} +end + function lib:populate_menu(buttons) local current_menu = menu_stack[#menu_stack] if current_menu == MENU_TYPES.MAIN then diff --git a/plugins/autofire/autofire_save.lua b/plugins/autofire/autofire_save.lua index e7d28029cd5..b15947fc168 100644 --- a/plugins/autofire/autofire_save.lua +++ b/plugins/autofire/autofire_save.lua @@ -1,7 +1,9 @@ local lib = {} +local plugin_path = '' + local function get_settings_path() - return lfs.env_replace(manager:machine():options().entries.pluginspath:value():match('([^;]+)')) .. '/autofire/cfg/' + return plugin_path .. '/cfg/' end local function get_settings_filename() @@ -45,6 +47,10 @@ local function serialize_settings(button_list) return settings end +function lib:set_plugin_path(path) + plugin_path = path +end + function lib:load_settings() local buttons = {} local json = require('json') diff --git a/plugins/autofire/init.lua b/plugins/autofire/init.lua index fd268b65ca3..5b52e47d350 100644 --- a/plugins/autofire/init.lua +++ b/plugins/autofire/init.lua @@ -2,13 +2,20 @@ -- copyright-holders:Jack Li local exports = {} exports.name = 'autofire' -exports.version = '0.0.1' +exports.version = '0.0.2' exports.description = 'Autofire plugin' exports.license = 'The BSD 3-Clause License' exports.author = { name = 'Jack Li' } local autofire = exports +function autofire.set_folder(path) + local loader = require('autofire/autofire_save') + if loader then + loader:set_plugin_path(path) + end +end + function autofire.startplugin() -- List of autofire buttons, each being a table with keys: @@ -21,6 +28,8 @@ function autofire.startplugin() -- 'counter' - position in autofire cycle local buttons = {} + local current_rom = nil + local function process_button(button) local pressed = manager:machine():input():code_pressed(button.key) if pressed then @@ -54,10 +63,26 @@ function autofire.startplugin() end end + local function reinit_buttons() + for i, button in ipairs(buttons) do + button.counter = 0 + button.button = manager:machine():ioport().ports[button.port].fields[button.field] + end + end + local function load_settings() - local loader = require('autofire/autofire_save') - if loader then - buttons = loader:load_settings() + if current_rom == emu.romname() then + reinit_buttons() + else + local loader = require('autofire/autofire_save') + if loader then + buttons = loader:load_settings() + end + end + current_rom = emu.romname() + local menu_handler = require('autofire/autofire_menu') + if menu_handler then + menu_handler:init_menu(buttons) end end diff --git a/plugins/autofire/plugin.json b/plugins/autofire/plugin.json index ccff6111c51..89e1a334523 100644 --- a/plugins/autofire/plugin.json +++ b/plugins/autofire/plugin.json @@ -2,7 +2,7 @@ "plugin": { "name": "autofire", "description": "Autofire plugin", - "version": "0.0.1", + "version": "0.0.2", "author": "Jack Li", "type": "plugin", "start": "false"