From 300206e308c2c5f9ad8898fb62f1873be682df5a Mon Sep 17 00:00:00 2001 From: feos Date: Sun, 27 Feb 2022 18:12:25 +0300 Subject: Lua engine: Make setting analog I/O port field values user-friendly. (#9322) Exposed minimum/maximum values for analog fields. together with defvalue, they can be used to check range of values and neutral position. Previously you had to send a normalised value between -65535 and 65535 which would be scaled depending on machine specifics. You could read the scaled value from the port, but you couldn't send scaled values in. This allows scripts to set scaled values as seen by the machine. --- src/frontend/mame/luaengine_input.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/frontend/mame/luaengine_input.cpp') diff --git a/src/frontend/mame/luaengine_input.cpp b/src/frontend/mame/luaengine_input.cpp index 1812bdc17b3..4f13b7e2484 100644 --- a/src/frontend/mame/luaengine_input.cpp +++ b/src/frontend/mame/luaengine_input.cpp @@ -257,6 +257,7 @@ void lua_engine::initialize_input(sol::table &emu) auto ioport_field_type = sol().registry().new_usertype("ioport_field", sol::no_constructor); ioport_field_type["set_value"] = &ioport_field::set_value; + ioport_field_type["clear_value"] = &ioport_field::clear_value; ioport_field_type["set_input_seq"] = [] (ioport_field &f, std::string const &seq_type_string, const input_seq &seq) { @@ -312,6 +313,16 @@ void lua_engine::initialize_input(sol::table &emu) ioport_field_type["player"] = sol::property(&ioport_field::player, &ioport_field::set_player); ioport_field_type["mask"] = sol::property(&ioport_field::mask); ioport_field_type["defvalue"] = sol::property(&ioport_field::defvalue); + ioport_field_type["minvalue"] = sol::property( + [] (ioport_field &f) + { + return f.is_analog() ? std::make_optional(f.minval()) : std::nullopt; + }); + ioport_field_type["maxvalue"] = sol::property( + [] (ioport_field &f) + { + return f.is_analog() ? std::make_optional(f.maxval()) : std::nullopt; + }); ioport_field_type["sensitivity"] = sol::property(&ioport_field::sensitivity); ioport_field_type["way"] = sol::property(&ioport_field::way); ioport_field_type["type_class"] = sol::property( -- cgit v1.2.3-70-g09d2