v2 - Use BuildOperation instead of global keybinding with ray casting

d4vid 3 months ago
parent fab436938a
commit 77d46f137e

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

@ -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.
"""

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

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

@ -0,0 +1,37 @@
using DLatchPoke.Client.Keybindings;
using DLatchPoke.Shared.Packets.C2S;
using FancyInput;
using LogicAPI.Data;
using LogicAPI.Services;
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 {
public enum DLatchPokeContext {
None,
None = 0,
DLatchPoke,
}
}

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

@ -1,15 +1,19 @@
using DLatchPoke.Shared.Packets.C2S;
using LogicAPI.Data;
using LogicWorld.SharedCode.Networking;
namespace DLatchPoke.Server.Network {
public class DLatchPokeRequestHandler : PacketHandler<DLatchPokeRequest> {
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);
}
}
}
}

@ -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<ComponentAddress> ComponentAddresses;
}
}
Loading…
Cancel
Save