diff --git a/DLatchPoke/DLatchPoke.csproj b/DLatchPoke/DLatchPoke.csproj index db0c6f7..9045cf4 100644 --- a/DLatchPoke/DLatchPoke.csproj +++ b/DLatchPoke/DLatchPoke.csproj @@ -35,18 +35,15 @@ $(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.BuildingManagement.dll - - $(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Players.dll - - - $(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Physics.dll - $(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Interfaces.dll $(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Modding.dll + + $(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.GameStates.dll + $(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.SharedCode.dll diff --git a/DLatchPoke/DLatchPoke/languages/English/English_input.jecs b/DLatchPoke/DLatchPoke/languages/English/English_input.jecs index a93d29d..ae55e22 100644 --- a/DLatchPoke/DLatchPoke/languages/English/English_input.jecs +++ b/DLatchPoke/DLatchPoke/languages/English/English_input.jecs @@ -1,6 +1,6 @@ MHG.SettingsMenu.Pages.Controls.Headings.DLatchPoke: "Mod: DLatch Poke" -FancyInput.Trigger.DLatchPoke.Poke: "Poke a DLatch" +FancyInput.Trigger.DLatchPoke.Poke: "Toggle DLatch State" FancyInput.Trigger.DLatchPoke.Poke.Description: """ - Toggles the internal state of the DLatch the player is looking at. + Toggles the internal state of the DLatch (or multiple) the player is looking at or has selected. """ diff --git a/DLatchPoke/DLatchPoke/manifest.jecs b/DLatchPoke/DLatchPoke/manifest.jecs index 2da36f9..92dae5f 100644 --- a/DLatchPoke/DLatchPoke/manifest.jecs +++ b/DLatchPoke/DLatchPoke/manifest.jecs @@ -1,7 +1,7 @@ ID: D4VID_DLatchPoke Name: DLatch Poke Author: D4VID -Version: 1.0.1 +Version: 2.0.0 Priority: 0 Dependencies: - EccsLogicWorldAPI diff --git a/DLatchPoke/DLatchPoke/src/client/DLatchPokeClient.cs b/DLatchPoke/DLatchPoke/src/client/DLatchPokeClient.cs index 272dac8..965656d 100644 --- a/DLatchPoke/DLatchPoke/src/client/DLatchPokeClient.cs +++ b/DLatchPoke/DLatchPoke/src/client/DLatchPokeClient.cs @@ -1,15 +1,9 @@ using DLatchPoke.Client.Keybindings; using DLatchPoke.Client.Network; -using DLatchPoke.Shared.Packets.C2S; using EccsLogicWorldAPI.Client.Injectors; using FancyInput; using LogicAPI.Client; -using LogicAPI.Data; using LogicLog; -using LogicWorld; -using LogicWorld.Interfaces; -using LogicWorld.Physics; -using LogicWorld.Players; namespace DLatchPoke.Client { public class DLatchPokeClient : ClientMod { @@ -23,42 +17,10 @@ namespace DLatchPoke.Client { // Register keybindings in the settings menu CustomInput.Register("DLatchPoke"); - // Register the keybinding to enter the path analyzer game state - FirstPersonInteraction.RegisterBuildingKeybinding(DLatchPokeTrigger.Poke, () => { - if (!ServerSupportsMod) { - Logger.Error("Server does not support this mod"); - return false; - } - - return PokeDLatch(); - } - ); - // Inject packet handlers RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version)); Logger.Info("DLatchPoke mod loaded"); } - - private bool PokeDLatch() { - HitInfo hitInfo = PlayerCaster.CameraCast(Masks.Environment | Masks.Structure | Masks.Peg); - if (!hitInfo.HitSomething) { - return false; - } - - ComponentAddress componentAddress; - if (hitInfo.HitComponent) { - componentAddress = hitInfo.cAddress; - } else if (hitInfo.HitPeg) { - componentAddress = hitInfo.pAddress.ComponentAddress; - } else { - return false; - } - - Instances.SendData.Send(new DLatchPokeRequest() { - ComponentAddress = componentAddress, - }); - return true; - } } } \ No newline at end of file diff --git a/DLatchPoke/DLatchPoke/src/client/DLatchPokeOperation.cs b/DLatchPoke/DLatchPoke/src/client/DLatchPokeOperation.cs new file mode 100644 index 0000000..8db7112 --- /dev/null +++ b/DLatchPoke/DLatchPoke/src/client/DLatchPokeOperation.cs @@ -0,0 +1,36 @@ +using DLatchPoke.Client.Keybindings; +using DLatchPoke.Shared.Packets.C2S; +using FancyInput; +using LogicAPI.Data; +using LogicWorld.Building.Overhaul; +using LogicWorld.GameStates; +using LogicWorld.Interfaces; + +namespace DLatchPoke.Client { + public class DLatchPokeOperation : BuildingOperation { + public override string IconHexCode => "f363"; + + public override bool CanOperateOn(ComponentSelection selection) { + if (!DLatchPokeClient.ServerSupportsMod) { + DLatchPokeClient.Logger.Error("Server does not support this mod"); + return false; + } + ComponentType dLatchType = Instances.MainWorld.ComponentTypes.GetComponentType("MHG.DLatch"); + foreach (ComponentAddress componentAddress in selection) { + if (Instances.MainWorld.Data.Lookup(componentAddress).Data.Type != dLatchType) { + return false; + } + } + return true; + } + + public override void BeginOperationOn(ComponentSelection selection) { + Instances.SendData.Send(new DLatchPokeRequest() { + ComponentAddresses = selection.ComponentsInSelection, + }); + GameStateManager.TransitionBackToBuildingState(); + } + + public override InputTrigger OperationStarter => DLatchPokeTrigger.Poke; + } +} \ No newline at end of file diff --git a/DLatchPoke/DLatchPoke/src/client/keybindings/DLatchPokeContext.cs b/DLatchPoke/DLatchPoke/src/client/keybindings/DLatchPokeContext.cs index 51bcedd..be8c8e7 100644 --- a/DLatchPoke/DLatchPoke/src/client/keybindings/DLatchPokeContext.cs +++ b/DLatchPoke/DLatchPoke/src/client/keybindings/DLatchPokeContext.cs @@ -1,6 +1,6 @@ namespace DLatchPoke.Client.Keybindings { public enum DLatchPokeContext { - None, + None = 0, DLatchPoke, } } \ No newline at end of file diff --git a/DLatchPoke/DLatchPoke/src/client/keybindings/DLatchPokeTrigger.cs b/DLatchPoke/DLatchPoke/src/client/keybindings/DLatchPokeTrigger.cs index 2f202ff..105fd65 100644 --- a/DLatchPoke/DLatchPoke/src/client/keybindings/DLatchPokeTrigger.cs +++ b/DLatchPoke/DLatchPoke/src/client/keybindings/DLatchPokeTrigger.cs @@ -1,7 +1,7 @@ namespace DLatchPoke.Client.Keybindings { // Define all available keybindings of the mod public enum DLatchPokeTrigger { - None, + None = 0, Poke, } } \ No newline at end of file diff --git a/DLatchPoke/DLatchPoke/src/server/network/DLatchPokeRequestHandler.cs b/DLatchPoke/DLatchPoke/src/server/network/DLatchPokeRequestHandler.cs index d8f9241..3c4d4b7 100644 --- a/DLatchPoke/DLatchPoke/src/server/network/DLatchPokeRequestHandler.cs +++ b/DLatchPoke/DLatchPoke/src/server/network/DLatchPokeRequestHandler.cs @@ -1,15 +1,19 @@ using DLatchPoke.Shared.Packets.C2S; +using LogicAPI.Data; using LogicWorld.SharedCode.Networking; namespace DLatchPoke.Server.Network { public class DLatchPokeRequestHandler : PacketHandler { private readonly DLatchPokeServer _dLatchPokeServer; + public DLatchPokeRequestHandler(DLatchPokeServer dLatchPokeServer) { _dLatchPokeServer = dLatchPokeServer; } public override void Handle(DLatchPokeRequest packet, HandlerContext context) { - _dLatchPokeServer.PokeDLatch(packet.ComponentAddress); + foreach (ComponentAddress componentAddress in packet.ComponentAddresses) { + _dLatchPokeServer.PokeDLatch(componentAddress); + } } } } \ No newline at end of file diff --git a/DLatchPoke/DLatchPoke/src/shared/packets/c2s/DLatchPokeRequest.cs b/DLatchPoke/DLatchPoke/src/shared/packets/c2s/DLatchPokeRequest.cs index adb6199..6032055 100644 --- a/DLatchPoke/DLatchPoke/src/shared/packets/c2s/DLatchPokeRequest.cs +++ b/DLatchPoke/DLatchPoke/src/shared/packets/c2s/DLatchPokeRequest.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using LogicAPI.Data; using LogicAPI.Networking.Packets; using MessagePack; @@ -5,6 +6,6 @@ using MessagePack; namespace DLatchPoke.Shared.Packets.C2S { [MessagePackObject] public class DLatchPokeRequest : Packet { - [Key(0)] public ComponentAddress ComponentAddress; + [Key(0)] public IEnumerable ComponentAddresses; } } \ No newline at end of file