Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PORT] RPD #715

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 63 additions & 7 deletions Content.Client/RCD/RCDConstructionGhostSystem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Content.Shared.Hands.Components;
using Content.Shared.Input;
using Content.Shared.Interaction;
using Content.Shared.RCD;
using Content.Shared.RCD.Components;
using Content.Shared.RCD.Systems;
using Robust.Client.Placement;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;

namespace Content.Client.RCD;

Expand All @@ -14,9 +17,54 @@ public sealed class RCDConstructionGhostSystem : EntitySystem
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly RCDSystem _rcdSystem = default!;
[Dependency] private readonly IPlacementManager _placementManager = default!;

private string _placementMode = typeof(AlignRCDConstruction).Name;
private Direction _placementDirection = default;
private bool _useMirrorPrototype = false;
public event EventHandler? FlipConstructionPrototype;

public override void Initialize()
{
base.Initialize();

// bind key
CommandBinds.Builder
.Bind(ContentKeyFunctions.EditorFlipObject,
new PointerInputCmdHandler(HandleFlip, outsidePrediction: true))
.Register<RCDConstructionGhostSystem>();
}

public override void Shutdown()
{
CommandBinds.Unregister<RCDConstructionGhostSystem>();
base.Shutdown();
}

private bool HandleFlip(in PointerInputCmdHandler.PointerInputCmdArgs args)
{
if (args.State == BoundKeyState.Down)
{
if (!_placementManager.IsActive || _placementManager.Eraser)
return false;

var placerEntity = _placementManager.CurrentPermission?.MobUid;

if(!TryComp<RCDComponent>(placerEntity, out var rcd) ||
string.IsNullOrEmpty(rcd.CachedPrototype.MirrorPrototype))
return false;

_useMirrorPrototype = !rcd.UseMirrorPrototype;

var useProto = _useMirrorPrototype ? rcd.CachedPrototype.MirrorPrototype : rcd.CachedPrototype.Prototype;
CreatePlacer(placerEntity.Value, rcd, useProto);

// tell the server

RaiseNetworkEvent(new RCDConstructionGhostFlipEvent(GetNetEntity(placerEntity.Value), _useMirrorPrototype));
}

return true;
}

public override void Update(float frameTime)
{
Expand Down Expand Up @@ -55,20 +103,28 @@ public override void Update(float frameTime)
RaiseNetworkEvent(new RCDConstructionGhostRotationEvent(GetNetEntity(heldEntity.Value), _placementDirection));
}

// If the placer has not changed, exit
// If the placer has not changed build it.
_rcdSystem.UpdateCachedPrototype(heldEntity.Value, rcd);
var useProto = (_useMirrorPrototype && !string.IsNullOrEmpty(rcd.CachedPrototype.MirrorPrototype)) ? rcd.CachedPrototype.MirrorPrototype : rcd.CachedPrototype.Prototype;

if (heldEntity == placerEntity && rcd.CachedPrototype.Prototype == placerProto)
return;
if (heldEntity != placerEntity || useProto != placerProto)
{
CreatePlacer(heldEntity.Value, rcd, useProto);
}

}

private void CreatePlacer(EntityUid uid, RCDComponent component, string? prototype)
{

// Create a new placer
var newObjInfo = new PlacementInformation
{
MobUid = heldEntity.Value,
MobUid = uid,
PlacementOption = _placementMode,
EntityType = rcd.CachedPrototype.Prototype,
EntityType = prototype,
Range = (int) Math.Ceiling(SharedInteractionSystem.InteractionRange),
IsTile = (rcd.CachedPrototype.Mode == RcdMode.ConstructTile),
IsTile = (component.CachedPrototype.Mode == RcdMode.ConstructTile),
UseEditorContext = false,
};

Expand Down
24 changes: 24 additions & 0 deletions Content.Client/RCD/RCDMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
<ui:RadialMenuTextureButton StyleClasses="RadialMenuButton" SetSize="64 64" ToolTip="{Loc 'rcd-component-lighting'}" TargetLayer="Lighting" Visible="False">
<TextureRect VerticalAlignment="Center" HorizontalAlignment="Center" TextureScale="2 2" TexturePath="/Textures/Interface/Radial/RCD/lighting.png"/>
</ui:RadialMenuTextureButton>
<ui:RadialMenuTextureButton StyleClasses="RadialMenuButton" SetSize="64 64" ToolTip="{Loc 'rcd-component-piping'}" TargetLayer="Piping" Visible="False">
<TextureRect VerticalAlignment="Center" HorizontalAlignment="Center" TextureScale="2 2" TexturePath="/Textures/Interface/Radial/RPD/fourway.png"/>
</ui:RadialMenuTextureButton>
<ui:RadialMenuTextureButton StyleClasses="RadialMenuButton" SetSize="64 64" ToolTip="{Loc 'rcd-component-atmosphericutility'}" TargetLayer="AtmosphericUtility" Visible="False">
<TextureRect VerticalAlignment="Center" HorizontalAlignment="Center" TextureScale="2 2" TexturePath="/Textures/Interface/Radial/RPD/port.png"/>
</ui:RadialMenuTextureButton>
<ui:RadialMenuTextureButton StyleClasses="RadialMenuButton" SetSize="64 64" ToolTip="{Loc 'rcd-component-pumpsvalves'}" TargetLayer="PumpsValves" Visible="False">
<TextureRect VerticalAlignment="Center" HorizontalAlignment="Center" TextureScale="2 2" TexturePath="/Textures/Interface/Radial/RPD/pump_volume.png"/>
</ui:RadialMenuTextureButton>
<ui:RadialMenuTextureButton StyleClasses="RadialMenuButton" SetSize="64 64" ToolTip="{Loc 'rcd-component-vents'}" TargetLayer="Vents" Visible="False">
<TextureRect VerticalAlignment="Center" HorizontalAlignment="Center" TextureScale="2 2" TexturePath="/Textures/Interface/Radial/RPD/vent_passive.png"/>
</ui:RadialMenuTextureButton>
</ui:RadialContainer>

<!-- Walls and flooring -->
Expand All @@ -44,4 +56,16 @@
<!-- Lighting -->
<ui:RadialContainer Name="Lighting" VerticalExpand="True" HorizontalExpand="True" Radius="64"/>

<!-- Piping -->
<ui:RadialContainer Name="Piping" VerticalExpand="True" HorizontalExpand="True" Radius="64"/>

<!-- Pumps & Valves -->
<ui:RadialContainer Name="PumpsValves" VerticalExpand="True" HorizontalExpand="True" Radius="64"/>

<!-- Atmospheric Utility -->
<ui:RadialContainer Name="AtmosphericUtility" VerticalExpand="True" HorizontalExpand="True" Radius="64"/>

<!-- Vents -->
<ui:RadialContainer Name="Vents" VerticalExpand="True" HorizontalExpand="True" Radius="64"/>

</ui:RadialMenu>
3 changes: 2 additions & 1 deletion Content.Server/Charges/Systems/ChargesSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Shared.Charges.Components;
using Content.Shared.Charges.Systems;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Robust.Shared.Timing;

namespace Content.Server.Charges.Systems;
Expand Down Expand Up @@ -37,7 +38,7 @@ protected override void OnExamine(EntityUid uid, LimitedChargesComponent comp, E
args.PushMarkup(Loc.GetString("limited-charges-recharging", ("seconds", timeRemaining)));
}

public override void AddCharges(EntityUid uid, int change, LimitedChargesComponent? comp = null)
public override void AddCharges(EntityUid uid, FixedPoint2 change, LimitedChargesComponent? comp = null)
{
if (!Query.Resolve(uid, ref comp, false))
return;
Expand Down
5 changes: 3 additions & 2 deletions Content.Shared/Charges/Components/LimitedChargesComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Charges.Systems;
using Content.Shared.FixedPoint;
using Robust.Shared.GameStates;

namespace Content.Shared.Charges.Components;
Expand All @@ -13,12 +14,12 @@ public sealed partial class LimitedChargesComponent : Component
/// </summary>
[DataField("maxCharges"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public int MaxCharges = 3;
public FixedPoint2 MaxCharges = 3;

/// <summary>
/// The current number of charges
/// </summary>
[DataField("charges"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public int Charges = 3;
public FixedPoint2 Charges = 3;
}
9 changes: 5 additions & 4 deletions Content.Shared/Charges/Systems/SharedChargesSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.Charges.Components;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;

namespace Content.Shared.Charges.Systems;

Expand Down Expand Up @@ -34,13 +35,13 @@ protected virtual void OnExamine(EntityUid uid, LimitedChargesComponent comp, Ex
/// <summary>
/// Tries to add a number of charges. If it over or underflows it will be clamped, wasting the extra charges.
/// </summary>
public virtual void AddCharges(EntityUid uid, int change, LimitedChargesComponent? comp = null)
public virtual void AddCharges(EntityUid uid, FixedPoint2 change, LimitedChargesComponent? comp = null)
{
if (!Query.Resolve(uid, ref comp, false))
return;

var old = comp.Charges;
comp.Charges = Math.Clamp(comp.Charges + change, 0, comp.MaxCharges);
comp.Charges = FixedPoint2.Clamp(comp.Charges + change, 0, comp.MaxCharges);
if (comp.Charges != old)
Dirty(uid, comp);
}
Expand Down Expand Up @@ -84,7 +85,7 @@ public bool TryUseCharge(Entity<LimitedChargesComponent?> ent)
/// Gets the limited charges component and returns true if the number of charges remaining is less than the specified value.
/// Will return false if there is no limited charges component.
/// </summary>
public bool HasInsufficientCharges(EntityUid uid, int requiredCharges, LimitedChargesComponent? comp = null)
public bool HasInsufficientCharges(EntityUid uid, FixedPoint2 requiredCharges, LimitedChargesComponent? comp = null)
{
// can't be empty if there are no limited charges
if (!Resolve(uid, ref comp, false))
Expand All @@ -96,7 +97,7 @@ public bool HasInsufficientCharges(EntityUid uid, int requiredCharges, LimitedCh
/// <summary>
/// Uses up a specified number of charges. Must check HasInsufficentCharges beforehand to prevent using with insufficient remaining charges.
/// </summary>
public virtual void UseCharges(EntityUid uid, int chargesUsed, LimitedChargesComponent? comp = null)
public virtual void UseCharges(EntityUid uid, FixedPoint2 chargesUsed, LimitedChargesComponent? comp = null)
{
AddCharges(uid, -chargesUsed, comp);
}
Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/RCD/Components/RCDAmmoComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.FixedPoint;
using Content.Shared.RCD.Systems;
using Robust.Shared.GameStates;

Expand All @@ -12,5 +13,5 @@ public sealed partial class RCDAmmoComponent : Component
/// Can be partially transferred into an RCD, until it is empty then it gets deleted.
/// </summary>
[DataField("charges"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public int Charges = 30;
public FixedPoint2 Charges = 30;
}
12 changes: 12 additions & 0 deletions Content.Shared/RCD/Components/RCDComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ public sealed partial class RCDComponent : Component
[ViewVariables(VVAccess.ReadOnly)]
public RCDPrototype CachedPrototype { get; set; } = default!;

/// <summary>
/// Indicates if a mirrored version of the construction prototype should be used (if available)
/// </summary>
[AutoNetworkedField, ViewVariables(VVAccess.ReadOnly)]
public bool UseMirrorPrototype = false;

/// <summary>
/// Indicates whether this is an RCD or an RPD
/// </summary>
[DataField, AutoNetworkedField]
public bool IsRpd { get; set; } = false;

/// <summary>
/// The direction constructed entities will face upon spawning
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion Content.Shared/RCD/Components/RCDDeconstructibleComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.FixedPoint;
using Content.Shared.RCD.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
Expand All @@ -12,7 +13,7 @@ public sealed partial class RCDDeconstructableComponent : Component
/// Number of charges consumed when the deconstruction is completed
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int Cost = 1;
public FixedPoint2 Cost = 1;

/// <summary>
/// The length of the deconstruction
Expand All @@ -31,4 +32,10 @@ public sealed partial class RCDDeconstructableComponent : Component
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool Deconstructable = true;

/// <summary>
/// Toggles whether this entity is deconstructable by the RPD or not
/// </summary>
[DataField("rpd"), ViewVariables(VVAccess.ReadWrite)]
public bool RpdDeconstructable = false;
}
12 changes: 12 additions & 0 deletions Content.Shared/RCD/RCDEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public RCDConstructionGhostRotationEvent(NetEntity netEntity, Direction directio
}
}

[Serializable, NetSerializable]
public sealed class RCDConstructionGhostFlipEvent : EntityEventArgs
{
public readonly NetEntity NetEntity;
public readonly bool UseMirrorPrototype;
public RCDConstructionGhostFlipEvent(NetEntity netEntity, bool useMirrorPrototype)
{
NetEntity = netEntity;
UseMirrorPrototype = useMirrorPrototype;
}
}

[Serializable, NetSerializable]
public enum RcdUiKey : byte
{
Expand Down
9 changes: 8 additions & 1 deletion Content.Shared/RCD/RCDPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.FixedPoint;
using Content.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Prototypes;
Expand Down Expand Up @@ -44,11 +45,17 @@ public sealed partial class RCDPrototype : IPrototype
[DataField, ViewVariables(VVAccess.ReadOnly)]
public string? Prototype { get; private set; } = string.Empty;

/// <summary>
/// If the entity can be flipped, this prototype is available as an alternate (mode dependent)
/// </summary>
[DataField, ViewVariables(VVAccess.ReadOnly)]
public string? MirrorPrototype { get; private set; } = string.Empty;

/// <summary>
/// Number of charges consumed when the operation is completed
/// </summary>
[DataField, ViewVariables(VVAccess.ReadOnly)]
public int Cost { get; private set; } = 1;
public FixedPoint2 Cost { get; private set; } = 1;

/// <summary>
/// The length of the operation
Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/RCD/Systems/RCDAmmoSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Shared.Charges.Components;
using Content.Shared.Charges.Systems;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.RCD.Components;
Expand Down Expand Up @@ -43,7 +44,7 @@ private void OnAfterInteract(EntityUid uid, RCDAmmoComponent comp, AfterInteract

var user = args.User;
args.Handled = true;
var count = Math.Min(charges.MaxCharges - charges.Charges, comp.Charges);
var count = FixedPoint2.Min(charges.MaxCharges - charges.Charges,comp.Charges);
if (count <= 0)
{
_popup.PopupClient(Loc.GetString("rcd-ammo-component-after-interact-full"), target, user);
Expand Down
Loading
Loading