v2 - Use BuildOperation instead of global keybinding with ray casting

master
d4vid 3 months ago
parent fab436938a
commit 3c675daef6

@ -35,18 +35,15 @@
<Reference Include="LogicWorld.BuildingManagement"> <Reference Include="LogicWorld.BuildingManagement">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.BuildingManagement.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.BuildingManagement.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.Players">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Players.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.Physics">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Physics.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.Interfaces"> <Reference Include="LogicWorld.Interfaces">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Interfaces.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Interfaces.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.Modding"> <Reference Include="LogicWorld.Modding">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Modding.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Modding.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.GameStates">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.GameStates.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.SharedCode"> <Reference Include="LogicWorld.SharedCode">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.SharedCode.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.SharedCode.dll</HintPath>
</Reference> </Reference>

@ -1,6 +1,6 @@
MHG.SettingsMenu.Pages.Controls.Headings.DLatchPoke: "Mod: DLatch Poke" 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: """ 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.
""" """

@ -1,7 +1,7 @@
ID: D4VID_DLatchPoke ID: D4VID_DLatchPoke
Name: DLatch Poke Name: DLatch Poke
Author: D4VID Author: D4VID
Version: 1.0.1 Version: 2.0.0
Priority: 0 Priority: 0
Dependencies: Dependencies:
- EccsLogicWorldAPI - EccsLogicWorldAPI

@ -1,15 +1,9 @@
using DLatchPoke.Client.Keybindings; using DLatchPoke.Client.Keybindings;
using DLatchPoke.Client.Network; using DLatchPoke.Client.Network;
using DLatchPoke.Shared.Packets.C2S;
using EccsLogicWorldAPI.Client.Injectors; using EccsLogicWorldAPI.Client.Injectors;
using FancyInput; using FancyInput;
using LogicAPI.Client; using LogicAPI.Client;
using LogicAPI.Data;
using LogicLog; using LogicLog;
using LogicWorld;
using LogicWorld.Interfaces;
using LogicWorld.Physics;
using LogicWorld.Players;
namespace DLatchPoke.Client { namespace DLatchPoke.Client {
public class DLatchPokeClient : ClientMod { public class DLatchPokeClient : ClientMod {
@ -23,42 +17,10 @@ namespace DLatchPoke.Client {
// Register keybindings in the settings menu // Register keybindings in the settings menu
CustomInput.Register<DLatchPokeContext, DLatchPokeTrigger>("DLatchPoke"); CustomInput.Register<DLatchPokeContext, DLatchPokeTrigger>("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 // Inject packet handlers
RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version)); RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version));
Logger.Info("DLatchPoke mod loaded"); 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;
}
} }
} }

@ -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;
}
}

@ -1,6 +1,6 @@
namespace DLatchPoke.Client.Keybindings { namespace DLatchPoke.Client.Keybindings {
public enum DLatchPokeContext { public enum DLatchPokeContext {
None, None = 0,
DLatchPoke, DLatchPoke,
} }
} }

@ -1,7 +1,7 @@
namespace DLatchPoke.Client.Keybindings { namespace DLatchPoke.Client.Keybindings {
// Define all available keybindings of the mod // Define all available keybindings of the mod
public enum DLatchPokeTrigger { public enum DLatchPokeTrigger {
None, None = 0,
Poke, Poke,
} }
} }

@ -1,15 +1,19 @@
using DLatchPoke.Shared.Packets.C2S; using DLatchPoke.Shared.Packets.C2S;
using LogicAPI.Data;
using LogicWorld.SharedCode.Networking; using LogicWorld.SharedCode.Networking;
namespace DLatchPoke.Server.Network { namespace DLatchPoke.Server.Network {
public class DLatchPokeRequestHandler : PacketHandler<DLatchPokeRequest> { public class DLatchPokeRequestHandler : PacketHandler<DLatchPokeRequest> {
private readonly DLatchPokeServer _dLatchPokeServer; private readonly DLatchPokeServer _dLatchPokeServer;
public DLatchPokeRequestHandler(DLatchPokeServer dLatchPokeServer) { public DLatchPokeRequestHandler(DLatchPokeServer dLatchPokeServer) {
_dLatchPokeServer = dLatchPokeServer; _dLatchPokeServer = dLatchPokeServer;
} }
public override void Handle(DLatchPokeRequest packet, HandlerContext context) { public override void Handle(DLatchPokeRequest packet, HandlerContext context) {
_dLatchPokeServer.PokeDLatch(packet.ComponentAddress); foreach (ComponentAddress componentAddress in packet.ComponentAddresses) {
_dLatchPokeServer.PokeDLatch(componentAddress);
}
} }
} }
} }

@ -1,3 +1,4 @@
using System.Collections.Generic;
using LogicAPI.Data; using LogicAPI.Data;
using LogicAPI.Networking.Packets; using LogicAPI.Networking.Packets;
using MessagePack; using MessagePack;
@ -5,6 +6,6 @@ using MessagePack;
namespace DLatchPoke.Shared.Packets.C2S { namespace DLatchPoke.Shared.Packets.C2S {
[MessagePackObject] [MessagePackObject]
public class DLatchPokeRequest : Packet { public class DLatchPokeRequest : Packet {
[Key(0)] public ComponentAddress ComponentAddress; [Key(0)] public IEnumerable<ComponentAddress> ComponentAddresses;
} }
} }
Loading…
Cancel
Save