summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author Jack Li <jackrjli@berkeley.edu>2019-05-21 15:44:44 -0700
committer ajrhacker <ajrhacker@users.noreply.github.com>2019-05-21 18:44:44 -0400
commit27f66693c5d1263453d625a2d4a17f99b6766443 (patch)
tree9061c48967f7221a009fa44a0886a42b1851c251 /plugins
parent20d691db79fd57ac78d15876f7450ae4cdd4ef89 (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')
-rw-r--r--plugins/autofire/autofire_menu.lua8
-rw-r--r--plugins/autofire/autofire_save.lua8
-rw-r--r--plugins/autofire/init.lua33
-rw-r--r--plugins/autofire/plugin.json2
4 files changed, 45 insertions, 6 deletions
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"