From 7f0b2ca798a0dd62c047ce1a039e6b68e85f2382 Mon Sep 17 00:00:00 2001 From: Denis Pakhorukov Date: Tue, 26 Sep 2023 18:03:05 +0300 Subject: [PATCH] #235 Fix chore cancellation from the user menu --- .../Commands/Screens/UserMenu/ClickUserMenuButton.cs | 2 +- .../Multiplayer/Objects/GameObjectExtensions.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/MultiplayerMod/Multiplayer/Commands/Screens/UserMenu/ClickUserMenuButton.cs b/src/MultiplayerMod/Multiplayer/Commands/Screens/UserMenu/ClickUserMenuButton.cs index 069f91a5..aaaef3a5 100644 --- a/src/MultiplayerMod/Multiplayer/Commands/Screens/UserMenu/ClickUserMenuButton.cs +++ b/src/MultiplayerMod/Multiplayer/Commands/Screens/UserMenu/ClickUserMenuButton.cs @@ -17,7 +17,7 @@ public class ClickUserMenuButton : MultiplayerCommand { private string actionName; public ClickUserMenuButton(GameObject gameObject, System.Action action) { - reference = gameObject.GetMultiplayerReference(); + reference = gameObject.GetReference(); actionDeclaringType = action.Method.DeclaringType!; actionName = action.Method.Name; } diff --git a/src/MultiplayerMod/Multiplayer/Objects/GameObjectExtensions.cs b/src/MultiplayerMod/Multiplayer/Objects/GameObjectExtensions.cs index 19a73ed7..5a03a2b3 100644 --- a/src/MultiplayerMod/Multiplayer/Objects/GameObjectExtensions.cs +++ b/src/MultiplayerMod/Multiplayer/Objects/GameObjectExtensions.cs @@ -14,4 +14,13 @@ public static GameObjectReference GetMultiplayerReference(this GameObject gameOb public static GameObjectReference GetGridReference(this GameObject gameObject) => new GridReference(gameObject); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObjectReference GetReference(this GameObject gameObject) { + var multiplayerId = gameObject.GetComponent().Id; + if (multiplayerId != null) + return new MultiplayerIdReference(multiplayerId); + + return new GridReference(gameObject); + } + }