From 91d26eeb653aea3a61e6ab519d638a770106bc5a Mon Sep 17 00:00:00 2001 From: Ilya Bodo Date: Mon, 17 Jul 2023 00:28:16 -0400 Subject: [PATCH] Add mod to rebind right mouse button --- README.md | 6 +++ assets/data/lang/sc/gui.en_US.json.patch | 6 +++ assets/data/lang/sc/gui.ru_RU.json.patch | 6 +++ src/_prestart.js | 2 + src/right-mouse-rebind.js | 56 ++++++++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 src/right-mouse-rebind.js diff --git a/README.md b/README.md index e427b1d..389a903 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,12 @@ _Always enabled_ Allows binding the 4th and 5th mouse buttons (sometimes called "side buttons") to any action in the Controls settings. **Be aware that those buttons don't have an icon for now!** +### Right mouse rebind [QoL] + +[_Previous location_](https://github.com/ilyabodo/crosscode-tweak-pack) + +Allows the right mouse button functionality to be changed. Currently the right mouse button can be set to: melee, dash only, or guard only. + ### Render hitboxes [debug] [_Previous location_](https://github.com/dmitmel/crosscode-render-hitboxes) diff --git a/assets/data/lang/sc/gui.en_US.json.patch b/assets/data/lang/sc/gui.en_US.json.patch index 92a8d74..9dfa14e 100644 --- a/assets/data/lang/sc/gui.en_US.json.patch +++ b/assets/data/lang/sc/gui.en_US.json.patch @@ -46,6 +46,12 @@ "name": "Skip title screen intro", "description": "Skip the intro sequence with logos which plays before the title screen. \\c[2][debug]" } + }, + "right-mouse-rebind": { + "right-mouse": { + "name": "Right mouse button rebind", + "description": "Rebind right mouse button. 1: Default/normal, 2: Melee, 3: Dash only, 4: Guard only. \\c[2][QoL]" + } } }, "controls": { diff --git a/assets/data/lang/sc/gui.ru_RU.json.patch b/assets/data/lang/sc/gui.ru_RU.json.patch index 76da349..b8e5c69 100644 --- a/assets/data/lang/sc/gui.ru_RU.json.patch +++ b/assets/data/lang/sc/gui.ru_RU.json.patch @@ -46,6 +46,12 @@ "name": "Пропускать интро перед экраном старта", "description": "Пропускает интро с логотипами, которое показывается перед главным экраном игры. \\c[2][debug]" } + }, + "right-mouse-rebind": { + "right-mouse": { + "name": "Переназначение правой кнопки мыши", + "description": "1: Стандартный/нормальный, 2: Ближний бой, 3: Только рывок, 4: Только защита. \\c[2][QoL]" + } } }, "controls": { diff --git a/src/_prestart.js b/src/_prestart.js index d1c7420..84f98ac 100644 --- a/src/_prestart.js +++ b/src/_prestart.js @@ -9,3 +9,5 @@ import './chest-radar.js'; import './open-map-menu-shortcut.js'; import './autoaim.js'; import './skip-title-screen-intro.js'; +import './right-mouse-rebind.js'; + diff --git a/src/right-mouse-rebind.js b/src/right-mouse-rebind.js new file mode 100644 index 0000000..0a43ec7 --- /dev/null +++ b/src/right-mouse-rebind.js @@ -0,0 +1,56 @@ +import * as core from './_core.js'; + +let module = new core.Module('right-mouse-rebind'); + +sc.RIGHT_MOUSE_REBIND = { + NORMAL: 0, // Default game behavior + MELEE: 1, // Replace dash/guard with melee + DASH: 2, // Dash only on right mouse button + GUARD: 3 // Guard only on right mouse button +}; + +let myOptionKey = module.getRawOptionName('right-mouse'); +let myOptionDef = { + type: 'OBJECT_SLIDER', + data: sc.RIGHT_MOUSE_REBIND, + init: sc.RIGHT_MOUSE_REBIND.NORMAL, + cat: sc.OPTION_CATEGORY.GENERAL, + fill: true +}; + +sc.OPTIONS_DEFINITION[myOptionKey] = myOptionDef; + +// Rebind mouse2 (left mouse button) +sc.CrossCode.inject({ + update() { + this.parent() + var opt = sc.options.get(myOptionKey); + + if (opt == sc.RIGHT_MOUSE_REBIND.MELEE){ + ig.input.bind(ig.KEY.MOUSE2,"melee"); + } + else if (opt == sc.RIGHT_MOUSE_REBIND.GUARD){ + ig.input.bind(ig.KEY.MOUSE2,"guard"); + } + else{ // Covers if NORMAL or DASH is selected + ig.input.bind(ig.KEY.MOUSE2,"dash"); // This is what the game defaults to + } + + } +}); + +// If right mouse button is set to dashing only, remove the ability to guard using dash buttons +// By default, performing a dash will also guard if standing still +sc.Control.inject({ + guarding() { + var opt = sc.options.get(myOptionKey); + if (opt == sc.RIGHT_MOUSE_REBIND.DASH){ // ig.input.state("dash") has been removed from default logic + return this.autoControl ? this.autoControl.get("guarding") : + (ig.input.state("guard") || ig.gamepad.isButtonDown(ig.BUTTONS.FACE1) || ig.gamepad.isButtonDown(this._getDashButton())) && !ig.interact.isBlocked() + } + else { // This logic is the default game logic + return this.autoControl ? this.autoControl.get("guarding") : + (ig.input.state("dash") || ig.input.state("guard") || ig.gamepad.isButtonDown(ig.BUTTONS.FACE1) || ig.gamepad.isButtonDown(this._getDashButton())) && !ig.interact.isBlocked() + } + } +});