From 196a09fefa60f3c5c9f8b0a7286cd3e9a25e3f6d Mon Sep 17 00:00:00 2001 From: danzel Date: Sun, 13 Aug 2017 18:03:56 +1200 Subject: [PATCH] When a script is configured, override the controls settings so it is used. This means you only need to set one thing in the config to use a script (script_name). --- src/scripted_input/scripted_buttons.cpp | 7 +++++++ src/scripted_input/scripted_buttons.h | 5 +++++ src/scripted_input/scripted_input.cpp | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/scripted_input/scripted_buttons.cpp b/src/scripted_input/scripted_buttons.cpp index 40c484bc2..dffedb396 100644 --- a/src/scripted_input/scripted_buttons.cpp +++ b/src/scripted_input/scripted_buttons.cpp @@ -4,6 +4,7 @@ #include #include +#include "core/settings.h" #include "scripted_input/scripted_buttons.h" const int button_count = 15; @@ -40,6 +41,12 @@ public: ScriptedButton* buttons[button_count]; }; +void ScriptedButtons::OverrideControlsSettings() { + for (int i = 0; i < button_count; i++) { + Settings::values.buttons[i] = "engine:scripted,button:" + button_name_to_index[i]; + } +} + ScriptedButtons::ScriptedButtons() : scripted_button_list{std::make_shared()} {} std::unique_ptr ScriptedButtons::Create(const Common::ParamPackage& params) { diff --git a/src/scripted_input/scripted_buttons.h b/src/scripted_input/scripted_buttons.h index dd5291860..cbf9e5768 100644 --- a/src/scripted_input/scripted_buttons.h +++ b/src/scripted_input/scripted_buttons.h @@ -18,6 +18,11 @@ class ScriptedButtonList; */ class ScriptedButtons final : public Input::Factory { public: + /** + * Overrides the Settings for buttons so they are controlled by us + */ + static void OverrideControlsSettings(); + ScriptedButtons(); /** diff --git a/src/scripted_input/scripted_input.cpp b/src/scripted_input/scripted_input.cpp index f0d9d416c..4a58f0aa6 100644 --- a/src/scripted_input/scripted_input.cpp +++ b/src/scripted_input/scripted_input.cpp @@ -22,6 +22,8 @@ void Init() { void LoadScript(std::string script_name) { if (script_name.length() > 0) { script_runner.LoadScript(script_name); + + ScriptedButtons::OverrideControlsSettings(); } }