mirror of
https://github.com/holub/mame
synced 2025-06-11 07:14:07 +03:00
plugins/portname: new wip plugin for loading translations or alt names for input port fields [Carl]
This commit is contained in:
parent
c3c8df4cce
commit
d3e7be82a8
108
plugins/portname/init.lua
Normal file
108
plugins/portname/init.lua
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
-- license:BSD-3-Clause
|
||||||
|
-- copyright-holders:Carl
|
||||||
|
-- use plugin options to save the input port list to a gettext formatted file
|
||||||
|
-- the file is saved in the ctrlrpath dir
|
||||||
|
local exports = {}
|
||||||
|
exports.name = "portname"
|
||||||
|
exports.version = "0.0.1"
|
||||||
|
exports.description = "IOPort name/translation plugin"
|
||||||
|
exports.license = "The BSD 3-Clause License"
|
||||||
|
exports.author = { name = "Carl" }
|
||||||
|
|
||||||
|
local portname = exports
|
||||||
|
|
||||||
|
function portname.startplugin()
|
||||||
|
local ctrlrpath = lfs.env_replace(manager:options().entries.ctrlrpath:value():match("([^;]+)"))
|
||||||
|
local function get_filename(nosoft)
|
||||||
|
local filename
|
||||||
|
if emu.softname() ~= "" and not nosoft then
|
||||||
|
filename = emu.romname() .. "_" .. emu.softname() .. ".po"
|
||||||
|
else
|
||||||
|
filename = emu.romname() .. ".po"
|
||||||
|
end
|
||||||
|
return filename
|
||||||
|
end
|
||||||
|
|
||||||
|
emu.register_start(function()
|
||||||
|
local file = io.open(ctrlrpath .. "/" .. get_filename(), "r")
|
||||||
|
if not file then
|
||||||
|
file = io.open(ctrlrpath .. "/" .. get_filename(true), "r")
|
||||||
|
if not file then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local orig, rep
|
||||||
|
for line in file:lines() do
|
||||||
|
if line:find("^msgid") then
|
||||||
|
orig = line:match("^msgid \"(.+)\"")
|
||||||
|
elseif line:find("^msgstr") then
|
||||||
|
rep = line:match("^msgstr \"(.+)\"")
|
||||||
|
if rep and rep ~= "" then
|
||||||
|
rep = rep:gsub("\\(.)", "%1")
|
||||||
|
orig = orig:gsub("\\(.)", "%1")
|
||||||
|
for pname, port in pairs(manager:machine():ioport().ports) do
|
||||||
|
if port.fields[orig] then
|
||||||
|
port.fields[orig].live.name = rep
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
file:close()
|
||||||
|
end)
|
||||||
|
|
||||||
|
local function menu_populate()
|
||||||
|
return {{ _("Save input names to file"), "", 0 }}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function menu_callback(index, event)
|
||||||
|
if event == "select" then
|
||||||
|
local fields = {}
|
||||||
|
for pname, port in pairs(manager:machine():ioport().ports) do
|
||||||
|
for fname, field in pairs(port.fields) do
|
||||||
|
local dname = field.default_name
|
||||||
|
if not fields[dname] then
|
||||||
|
fields[dname] = ""
|
||||||
|
end
|
||||||
|
if fname ~= dname then
|
||||||
|
fields[dname] = fname
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local attr = lfs.attributes(ctrlrpath)
|
||||||
|
if not attr then
|
||||||
|
lfs.mkdir(ctrlrpath)
|
||||||
|
if not lfs.attributes(ctrlrpath) then
|
||||||
|
manager:machine():popmessage(_("Failed to save input name file"))
|
||||||
|
emu.print_verbose("portname: unable to create ctrlrpath " .. ctrlrpath .. "\n")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
elseif attr.mode ~= "directory" then
|
||||||
|
manager:machine():popmessage(_("Failed to save input name file"))
|
||||||
|
emu.print_verbose("portname: ctrlrpath exists but isn't directory " .. ctrlrpath .. "\n")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local filename = get_filename()
|
||||||
|
local file = io.open(ctrlrpath .. "/" .. filename, "r")
|
||||||
|
if file then
|
||||||
|
emu.print_verbose("portname: input name file exists " .. filename .. "\n")
|
||||||
|
manager:machine():popmessage(_("Failed to save input name file"))
|
||||||
|
file:close()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
file = io.open(ctrlrpath .. "/" .. filename, "w")
|
||||||
|
for def, custom in pairs(fields) do
|
||||||
|
def = def:gsub("[\\\"]", function (s) return "\\" .. s end)
|
||||||
|
custom = custom:gsub("[\\\"]", function (s) return "\\" .. s end)
|
||||||
|
file:write("msgid \"" .. def .."\"\nmsgstr \"" .. custom .. "\"\n\n")
|
||||||
|
end
|
||||||
|
file:close()
|
||||||
|
manager:machine():popmessage(_("Input port name file saved to ") .. ctrlrpath .. "/" .. filename)
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
emu.register_menu(menu_callback, menu_populate, _("Input ports"))
|
||||||
|
end
|
||||||
|
|
||||||
|
return exports
|
10
plugins/portname/plugin.json
Normal file
10
plugins/portname/plugin.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"plugin": {
|
||||||
|
"name": "portname",
|
||||||
|
"description": "IOPort name/translation plugin",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"author": "Carl",
|
||||||
|
"type": "plugin",
|
||||||
|
"start": "false"
|
||||||
|
}
|
||||||
|
}
|
@ -1496,11 +1496,22 @@ void lua_engine::initialize()
|
|||||||
"field", &ioport_port::field,
|
"field", &ioport_port::field,
|
||||||
"fields", sol::property([this](ioport_port &p){
|
"fields", sol::property([this](ioport_port &p){
|
||||||
sol::table f_table = sol().create_table();
|
sol::table f_table = sol().create_table();
|
||||||
|
// parse twice for custom and default names, default has priority
|
||||||
for(ioport_field &field : p.fields())
|
for(ioport_field &field : p.fields())
|
||||||
{
|
{
|
||||||
if (field.type_class() != INPUT_CLASS_INTERNAL)
|
if (field.type_class() != INPUT_CLASS_INTERNAL)
|
||||||
f_table[field.name()] = &field;
|
f_table[field.name()] = &field;
|
||||||
}
|
}
|
||||||
|
for(ioport_field &field : p.fields())
|
||||||
|
{
|
||||||
|
if (field.type_class() != INPUT_CLASS_INTERNAL)
|
||||||
|
{
|
||||||
|
if(field.specific_name())
|
||||||
|
f_table[field.specific_name()] = &field;
|
||||||
|
else
|
||||||
|
f_table[field.manager().type_name(field.type(), field.player())] = &field;
|
||||||
|
}
|
||||||
|
}
|
||||||
return f_table;
|
return f_table;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -1511,6 +1522,9 @@ void lua_engine::initialize()
|
|||||||
"set_value", &ioport_field::set_value,
|
"set_value", &ioport_field::set_value,
|
||||||
"device", sol::property(&ioport_field::device),
|
"device", sol::property(&ioport_field::device),
|
||||||
"name", sol::property(&ioport_field::name),
|
"name", sol::property(&ioport_field::name),
|
||||||
|
"default_name", sol::property([](ioport_field &f) {
|
||||||
|
return f.specific_name() ? f.specific_name() : f.manager().type_name(f.type(), f.player());
|
||||||
|
}),
|
||||||
"player", sol::property(&ioport_field::player, &ioport_field::set_player),
|
"player", sol::property(&ioport_field::player, &ioport_field::set_player),
|
||||||
"mask", sol::property(&ioport_field::mask),
|
"mask", sol::property(&ioport_field::mask),
|
||||||
"defvalue", sol::property(&ioport_field::defvalue),
|
"defvalue", sol::property(&ioport_field::defvalue),
|
||||||
@ -1529,9 +1543,16 @@ void lua_engine::initialize()
|
|||||||
"analog_invert", sol::property(&ioport_field::analog_invert),
|
"analog_invert", sol::property(&ioport_field::analog_invert),
|
||||||
"impulse", sol::property(&ioport_field::impulse),
|
"impulse", sol::property(&ioport_field::impulse),
|
||||||
"type", sol::property(&ioport_field::type),
|
"type", sol::property(&ioport_field::type),
|
||||||
|
"live", sol::property(&ioport_field::live),
|
||||||
"crosshair_scale", sol::property(&ioport_field::crosshair_scale, &ioport_field::set_crosshair_scale),
|
"crosshair_scale", sol::property(&ioport_field::crosshair_scale, &ioport_field::set_crosshair_scale),
|
||||||
"crosshair_offset", sol::property(&ioport_field::crosshair_offset, &ioport_field::set_crosshair_offset));
|
"crosshair_offset", sol::property(&ioport_field::crosshair_offset, &ioport_field::set_crosshair_offset));
|
||||||
|
|
||||||
|
/* field.live
|
||||||
|
*/
|
||||||
|
|
||||||
|
sol().registry().new_usertype<ioport_field_live>("ioport_field_live", "new", sol::no_constructor,
|
||||||
|
"name", &ioport_field_live::name);
|
||||||
|
|
||||||
/* machine:parameters()
|
/* machine:parameters()
|
||||||
* parameter:add(tag, val) - add tag = val parameter
|
* parameter:add(tag, val) - add tag = val parameter
|
||||||
* parameter:lookup(tag) - get val for tag
|
* parameter:lookup(tag) - get val for tag
|
||||||
|
Loading…
Reference in New Issue
Block a user