Skip to content

Commit

Permalink
Better map key handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreML committed Mar 15, 2023
1 parent 38ef366 commit 92c6aed
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion SingleplayerCoopEmotes/modinfo.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "sabreml.singleplayercoopemotes",
"name": "Singleplayer Co-op Emotes",
"version": "1.2.0",
"version": "1.2.1",
"target_game_version": "v1.9.06",
"authors": "SabreML",
"description": "Makes the Jolly Co-op emotes work in singleplayer!",
Expand Down
22 changes: 14 additions & 8 deletions src/SPCoopEmotesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,29 @@ public override void Initialize()
// If the player is using the default map key then a double tap is required to start pointing, so this changes to reflect that.
public override void Update()
{
string newText;
string newLabelText;

// Default keybind.
if (keyBinder.value == PointInput.defaultValue)
if (!System.Enum.TryParse(keyBinder.value, out KeyCode currentKeybind))
{
newText = "Double tap and hold the Point button with a movement input to start pointing in a direction.";
// This shouldn't ever happen since it can only store `KeyCode`s.
return;
}
// Custom keybind.

// Using the map button. (Default behaviour)
if (SingleplayerCoopEmotes.KeybindIsMapKey(currentKeybind))
{
newLabelText = "Double tap and hold the Point button with a movement input to start pointing in a direction.";
}
// Using a custom keybind.
else
{
newText = "Press and hold the Point button with a movement input to start pointing in a direction.";
newLabelText = "Press and hold the Point button with a movement input to start pointing in a direction.";
}

// Only go through the effort of updating it if the text has actually changed.
if (pointingLabel.text != newText)
if (pointingLabel.text != newLabelText)
{
pointingLabel.text = newText;
pointingLabel.text = newLabelText;
}
}

Expand Down
31 changes: 18 additions & 13 deletions src/SingleplayerCoopEmotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace SingleplayerCoopEmotes
{
[BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.2.0")]
[BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.2.1")]
public class SingleplayerCoopEmotes : BaseUnityPlugin
{
// The current mod version.
Expand Down Expand Up @@ -87,20 +87,13 @@ private void JollyUpdateHK(On.Player.orig_JollyUpdate orig, Player self, bool eu
// Updates `self.jollyButtonDown` based on the player's pointing keybind.
// If the player is using the default keybind (the map button), this copies the standard Jolly Co-op behaviour of a double-tap and hold.
// If not, then this just checks if the key is currently being held.
//
// (Taken mostly from the 'Jolly Rebind' mod.)
// (It's a lot simpler and easier to just copy some of the functionality over to this than to try and make them compatible.)
private void UpdateJollyButton(Player self)
{
Options.ControlSetup playerControls = RWCustom.Custom.rainWorld.options.controls[self.playerState.playerNumber];

// The map key.
KeyCode defaultKeybind = self.input[0].gamePad ? playerControls.GamePadMap : playerControls.KeyboardMap;
// The key which is set in the remix menu. (By default, the map key.)
KeyCode playerKeybind = SPCoopEmotesConfig.PointInput.Value;
// The key which is set in the remix menu.
KeyCode customKeybind = SPCoopEmotesConfig.PointInput.Value;

// If the player is using the default keybind, use the standard Jolly Co-op double-tap behaviour.
if (playerKeybind == defaultKeybind)
// If the player's keybind is the same as the map key, continue on to the standard double tap behaviour.
if (KeybindIsMapKey(customKeybind))
{
if (!self.input[0].mp) // If the button isn't being held down at all.
{
Expand All @@ -118,13 +111,25 @@ private void UpdateJollyButton(Player self)
}
}
}
// Otherwise check for their custom keybind.
else
{
self.jollyButtonDown = Input.GetKey(playerKeybind);
self.jollyButtonDown = Input.GetKey(customKeybind);
}
}


// Checks if `keybindToCheck` is the same as the player's map keybind.
public static bool KeybindIsMapKey(KeyCode keybindToCheck)
{
// The player's Rain World keybinds. (Always player 0 since it's a singleplayer mod)
Options.ControlSetup playerControls = RWCustom.Custom.rainWorld.options.controls[0];

// If the keybind is the same as the keyboard or controller map key.
return keybindToCheck == playerControls.KeyboardMap || keybindToCheck == playerControls.GamePadMap;
}


// Restores the (most likely unintentional) functionality from the 1.5 version of
// pointing with no movement input making your slugcat face towards the screen.
// (Technically, making them face towards the hand rendered behind their body.)
Expand Down

0 comments on commit 92c6aed

Please sign in to comment.