diff options
author | 2019-05-21 15:44:44 -0700 | |
---|---|---|
committer | 2019-05-21 18:44:44 -0400 | |
commit | 27f66693c5d1263453d625a2d4a17f99b6766443 (patch) | |
tree | 9061c48967f7221a009fa44a0886a42b1851c251 /plugins/autofire/init.lua | |
parent | 20d691db79fd57ac78d15876f7450ae4cdd4ef89 (diff) |
Autofire plugin: Save/load fixes (#5093)
* Fixed bugs related to reloading roms
Soft resets would reload autofire settings without saving them first, causing the settings to be lost. This commit adds a check to only reload from the settings file if loading a different rom than before.
Hard resets would leave bad references lying around, causing MAME to crash under certain circumstances (i.e. resetting while in the edit menu and entering the menu again). This commit makes sure to properly clean up and reinitialize menu and button states when resetting.
* Used set_folder to avoid hardcoding plugin name in settings path
* Bumped autofire plugin version
Diffstat (limited to 'plugins/autofire/init.lua')
-rw-r--r-- | plugins/autofire/init.lua | 33 |
1 files changed, 29 insertions, 4 deletions
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 |