diff options
| -rw-r--r-- | docs/source/luascript/ref-input.rst | 45 | ||||
| -rw-r--r-- | src/frontend/mame/luaengine_input.cpp | 244 |
2 files changed, 240 insertions, 49 deletions
diff --git a/docs/source/luascript/ref-input.rst b/docs/source/luascript/ref-input.rst index 840e0a3ff5f..96d31fca6c1 100644 --- a/docs/source/luascript/ref-input.rst +++ b/docs/source/luascript/ref-input.rst @@ -269,6 +269,20 @@ field:set_value(value) field:clear_value() Clear programmatically overridden value and restore the field’s regular behaviour. +field:set_sensitivity(sensitivity) + Set the sensitivity or gain for analog fields. Raises an error for digital + fields. +field:set_keydelta(sensitivity) + Set the sensitivity to corresponding digital increment/decrement inputs for + analog fields. Raises an error for digital fields. +field:set_centerdelta(sensitivity) + Set the speed at which non-wrapping analog fields return to their default + values after associated digital increment/decrement inputs are released. + Raises an error for digital fields and wrapping analog fields. +field:set_analog_reverse(reverse) + Set whether an analog field’s value increases in the opposite direction to + the convention (e.g. larger values when a pedal is released or a joystick is + moved to the left). Raises an error for digital fields. field:set_input_seq(seqtype, seq) Set the :ref:`input sequence <luascript-ref-inputseq>` for the specified sequence type. This is used to configure per-machine input settings. The @@ -319,6 +333,33 @@ field.maxvalue (read-only) The maximum allowed value for analog fields, or ``nil`` for digital fields. field.sensitivity (read-only) The sensitivity or gain for analog fields, or ``nil`` for digital fields. +field.default_sensitivity (read-only) + The default sensitivity or gain for analog fields, or ``nil`` for digital + fields. +field.keydelta (read-only) + The sensitivity to corresponding digital increment/decrement inputs for + analog fields, or ``nil`` for digital fields. +field.default_keydelta (read-only) + The default sensitivity to corresponding digital increment/decrement inputs + for analog fields, or ``nil`` for digital fields. +field.centerdelta (read-only) + The speed at which non-wrapping analog fields return to their default values + after associated digital increment/decrement inputs are released, or ``nil`` + for digital fields and wrapping analog fields. +field.default_centerdelta (read-only) + The default speed at which non-wrapping analog fields return to their + default values after associated digital increment/decrement inputs are + released, or ``nil`` for digital fields and wrapping analog fields. +field.analog_reverse (read-only) + A Boolean indicating whether the field corresponds to an analog control that + increases in the opposite direction to the convention (e.g. larger values + when a pedal is released or a joystick is moved to the left), or ``nil`` for + digital fields. +field.default_analog_reverse (read-only) + A Boolean indicating whether the field corresponds to an analog control that + increases in the opposite direction to the convention by default (e.g. + larger values when a pedal is released or a joystick is moved to the left), + or ``nil`` for digital fields. field.way (read-only) The number of directions allowed by the restrictor plate/gate for a digital joystick, or zero (0) for other inputs. @@ -339,10 +380,6 @@ field.cocktail (read-only) field.toggle (read-only) A Boolean indicating whether the field corresponds to a hardware toggle switch or push-on, push-off button. -field.analog_reverse (read-only) - A Boolean indicating whether the field corresponds to an analog control that - increases in the opposite direction to the convention (e.g. larger values - when a pedal is released or a joystick is moved to the left). field.analog_reset (read-only) A Boolean indicating whether the field corresponds to an incremental position input (e.g. a dial or trackball axis) that should be reset to zero diff --git a/src/frontend/mame/luaengine_input.cpp b/src/frontend/mame/luaengine_input.cpp index fb5003f7c99..ca594b6f979 100644 --- a/src/frontend/mame/luaengine_input.cpp +++ b/src/frontend/mame/luaengine_input.cpp @@ -265,50 +265,120 @@ void lua_engine::initialize_input(sol::table &emu) auto ioport_field_type = sol().registry().new_usertype<ioport_field>("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) - { - input_seq_type seq_type = s_seq_type_parser(seq_type_string); - ioport_field::user_settings settings; - f.get_user_settings(settings); - settings.seq[seq_type] = seq; - if (seq.is_default()) - settings.cfg[seq_type].clear(); - else if (!seq.length()) - settings.cfg[seq_type] = "NONE"; - else - settings.cfg[seq_type] = f.port().device().machine().input().seq_to_tokens(seq); - f.set_user_settings(settings); - }; - ioport_field_type["input_seq"] = - [] (ioport_field &f, std::string const &seq_type_string) - { - input_seq_type seq_type = s_seq_type_parser(seq_type_string); - return f.seq(seq_type); - }; - ioport_field_type["set_default_input_seq"] = - [] (ioport_field &f, std::string const &seq_type_string, input_seq const &seq) - { - input_seq_type seq_type = s_seq_type_parser(seq_type_string); - f.set_defseq(seq_type, seq); - }; - ioport_field_type["default_input_seq"] = - [] (ioport_field &f, const std::string &seq_type_string) - { - input_seq_type seq_type = s_seq_type_parser(seq_type_string); - return f.defseq(seq_type); - }; - ioport_field_type["keyboard_codes"] = - [this] (ioport_field &f, int which) - { - sol::table result = sol().create_table(); - int index = 1; - for (char32_t code : f.keyboard_codes(which)) - result[index++] = code; - return result; - }; + ioport_field_type.set_function("set_value", &ioport_field::set_value); + ioport_field_type.set_function("clear_value", &ioport_field::clear_value); + ioport_field_type.set_function( + "set_sensitivity", + [] (sol::this_state s, ioport_field &f, s32 val) + { + if (!f.is_analog()) + luaL_error(s, "set_sensitivity is only applicable to analog fields"); + ioport_field::user_settings settings; + f.get_user_settings(settings); + settings.sensitivity = val; + f.set_user_settings(settings); + }); + ioport_field_type.set_function( + "set_keydelta", + [] (sol::this_state s, ioport_field &f, s32 val) + { + if (!f.is_analog()) + luaL_error(s, "set_keydelta is only applicable to analog fields"); + ioport_field::user_settings settings; + f.get_user_settings(settings); + settings.delta = val; + f.set_user_settings(settings); + }); + ioport_field_type.set_function( + "set_centerdelta", + [] (sol::this_state s, ioport_field &f, s32 val) + { + if (!f.is_analog()) + luaL_error(s, "set_centerdelta is only applicable to analog fields"); + switch (f.type()) + { + case IPT_POSITIONAL: + case IPT_POSITIONAL_V: + if (f.analog_wraps()) + luaL_error(s, "set_centerdelta is not applicable to wrapping fields"); + break; + + case IPT_AD_STICK_X: + case IPT_AD_STICK_Y: + case IPT_AD_STICK_Z: + case IPT_PADDLE: + case IPT_PADDLE_V: + case IPT_PEDAL: + case IPT_PEDAL2: + case IPT_PEDAL3: + break; + + default: + luaL_error(s, "set_centerdelta is not applicable to this field type"); + } + ioport_field::user_settings settings; + f.get_user_settings(settings); + settings.centerdelta = val; + f.set_user_settings(settings); + }); + ioport_field_type.set_function( + "set_analog_reverse", + [] (sol::this_state s, ioport_field &f, bool val) + { + if (!f.is_analog()) + luaL_error(s, "set_analog_reverse is only applicable to analog fields"); + ioport_field::user_settings settings; + f.get_user_settings(settings); + settings.reverse = val; + f.set_user_settings(settings); + }); + ioport_field_type.set_function( + "set_input_seq", + [] (ioport_field &f, std::string const &seq_type_string, const input_seq &seq) + { + input_seq_type seq_type = s_seq_type_parser(seq_type_string); + ioport_field::user_settings settings; + f.get_user_settings(settings); + settings.seq[seq_type] = seq; + if (seq.is_default()) + settings.cfg[seq_type].clear(); + else if (!seq.length()) + settings.cfg[seq_type] = "NONE"; + else + settings.cfg[seq_type] = f.port().device().machine().input().seq_to_tokens(seq); + f.set_user_settings(settings); + }); + ioport_field_type.set_function( + "input_seq", + [] (ioport_field &f, std::string const &seq_type_string) + { + input_seq_type seq_type = s_seq_type_parser(seq_type_string); + return f.seq(seq_type); + }); + ioport_field_type.set_function( + "set_default_input_seq", + [] (ioport_field &f, std::string const &seq_type_string, input_seq const &seq) + { + input_seq_type seq_type = s_seq_type_parser(seq_type_string); + f.set_defseq(seq_type, seq); + }); + ioport_field_type.set_function( + "default_input_seq", + [] (ioport_field &f, const std::string &seq_type_string) + { + input_seq_type seq_type = s_seq_type_parser(seq_type_string); + return f.defseq(seq_type); + }); + ioport_field_type.set_function( + "keyboard_codes", + [this] (ioport_field &f, int which) + { + sol::table result = sol().create_table(); + int index = 1; + for (char32_t code : f.keyboard_codes(which)) + result[index++] = code; + return result; + }); ioport_field_type["device"] = sol::property(&ioport_field::device); ioport_field_type["port"] = sol::property(&ioport_field::port); ioport_field_type["live"] = sol::property(&ioport_field::live); @@ -335,8 +405,93 @@ void lua_engine::initialize_input(sol::table &emu) ioport_field_type["sensitivity"] = sol::property( [] (ioport_field const &f) { + analog_field const *const analog = f.live().analog; + return analog ? std::make_optional(analog->sensitivity()) : std::nullopt; + }); + ioport_field_type["default_sensitivity"] = sol::property( + [] (ioport_field const &f) + { return f.is_analog() ? std::make_optional(f.sensitivity()) : std::nullopt; }); + ioport_field_type["keydelta"] = sol::property( + [] (ioport_field const &f) + { + analog_field const *const analog = f.live().analog; + return analog ? std::make_optional(analog->delta()) : std::nullopt; + }); + ioport_field_type["default_keydelta"] = sol::property( + [] (ioport_field const &f) + { + return f.is_analog() ? std::make_optional(f.delta()) : std::nullopt; + }); + ioport_field_type["centerdelta"] = sol::property( + [] (ioport_field const &f) + { + // TODO: this code is duplicated with the UI + bool use_autocenter = false; + switch (f.type()) + { + case IPT_POSITIONAL: + case IPT_POSITIONAL_V: + use_autocenter = !f.analog_wraps(); + break; + + case IPT_AD_STICK_X: + case IPT_AD_STICK_Y: + case IPT_AD_STICK_Z: + case IPT_PADDLE: + case IPT_PADDLE_V: + case IPT_PEDAL: + case IPT_PEDAL2: + case IPT_PEDAL3: + use_autocenter = true; + break; + + default: + break; + } + analog_field const *const analog = f.live().analog; + return (analog && use_autocenter) ? std::make_optional(analog->centerdelta()) : std::nullopt; + }); + ioport_field_type["default_centerdelta"] = sol::property( + [] (ioport_field const &f) + { + // TODO: this code is duplicated with the UI + bool use_autocenter = false; + switch (f.type()) + { + case IPT_POSITIONAL: + case IPT_POSITIONAL_V: + use_autocenter = !f.analog_wraps(); + break; + + case IPT_AD_STICK_X: + case IPT_AD_STICK_Y: + case IPT_AD_STICK_Z: + case IPT_PADDLE: + case IPT_PADDLE_V: + case IPT_PEDAL: + case IPT_PEDAL2: + case IPT_PEDAL3: + use_autocenter = true; + break; + + default: + break; + } + return (f.is_analog() && use_autocenter) ? std::make_optional(f.centerdelta()) : std::nullopt; + }); + ioport_field_type["analog_reverse"] = sol::property( + [] (ioport_field const &f) + { + analog_field const *const analog = f.live().analog; + return analog ? std::make_optional(analog->reverse()) : std::nullopt; + }); + ioport_field_type["default_analog_reverse"] = sol::property( + [] (ioport_field const &f) + { + return f.is_analog() ? std::make_optional(f.analog_reverse()) : std::nullopt; + }); ioport_field_type["way"] = sol::property(&ioport_field::way); ioport_field_type["type_class"] = sol::property( [] (ioport_field const &f) @@ -357,7 +512,6 @@ void lua_engine::initialize_input(sol::table &emu) ioport_field_type["enabled"] = sol::property(&ioport_field::enabled); ioport_field_type["cocktail"] = sol::property(&ioport_field::cocktail); ioport_field_type["toggle"] = sol::property(&ioport_field::toggle); - ioport_field_type["analog_reverse"] = sol::property(&ioport_field::analog_reverse); ioport_field_type["analog_reset"] = sol::property(&ioport_field::analog_reset); ioport_field_type["analog_wraps"] = sol::property(&ioport_field::analog_wraps); ioport_field_type["analog_invert"] = sol::property(&ioport_field::analog_invert); |
