Skip to content

Commit

Permalink
Lots of using hardcoded values less, switched collision to a whitelist.
Browse files Browse the repository at this point in the history
Should Holograms collide with windows?
  • Loading branch information
Pspritechologist committed Feb 8, 2024
1 parent 22d3845 commit 311227d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void OnEntInserted(EntityUid uid, HologramServerComponent component, Ent
/// </summary>
private void OnEntRemoved(EntityUid uid, HologramServerComponent component, EntRemovedFromContainerMessage args)
{
if (args.Container.ID != component.DiskSlot || !_tags.HasTag(args.Entity, "HoloDisk"))
if (args.Container.ID != component.DiskSlot || !_tags.HasTag(args.Entity, TagHoloDisk))
return;

if (Exists(component.LinkedHologram))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ public sealed class HologramSystem : SharedHologramSystem
/// </remarks>
public override void DoKillHologram(EntityUid hologram, HologramComponent? holoComp = null) // TODOPark: HOLO Move this to Shared once Upstream merge.
{
if (!Resolve(hologram, ref holoComp))
return;

var meta = MetaData(hologram);
var holoPos = Transform(hologram).Coordinates;

if (TryComp<MindContainerComponent>(hologram, out var mindComp) && mindComp.Mind != null)
_gameTicker.OnGhostAttempt(mindComp.Mind, false);

_audio.Play(filename: "/Audio/SimpleStation14/Effects/Hologram/holo_off.ogg", playerFilter: Filter.Pvs(hologram), coordinates: holoPos, false);
_popup.PopupCoordinates(Loc.GetString(PopupDisappearOther, ("name", meta.EntityName)), holoPos, Filter.PvsExcept(hologram), false, PopupType.MediumCaution);
_popup.PopupCoordinates(Loc.GetString(PopupDeathSelf), holoPos, hologram, PopupType.LargeCaution);
_audio.Play(holoComp.OffSound, playerFilter: Filter.Pvs(hologram), coordinates: holoPos, false);
_popup.PopupCoordinates(Loc.GetString(holoComp.PopupDisappearOther, ("name", meta.EntityName)), holoPos, Filter.PvsExcept(hologram), false, PopupType.MediumCaution);
_popup.PopupCoordinates(Loc.GetString(holoComp.PopupDeathSelf), holoPos, hologram, PopupType.LargeCaution);

_entityManager.QueueDeleteEntity(hologram);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Content.Shared.Tag;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;

namespace Content.Shared.SimpleStation14.Holograms;

Expand All @@ -18,20 +16,65 @@ public sealed class HologramComponent : Component
/// The sound to play when the Hologram is turned on.
/// </summary>
[DataField("onSound"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public SoundSpecifier OnSound = new SoundPathSpecifier("/Audio/SimpleStation14/Effects/Hologram/holo_on.ogg");

/// <summary>
/// The sound to play when the Hologram is turned off.
/// </summary>
[DataField("offSound"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public SoundSpecifier OffSound = new SoundPathSpecifier("/Audio/SimpleStation14/Effects/Hologram/holo_off.ogg");

/// <summary>
/// The string to use for the popup when the Hologram appears, shown to others.
/// </summary>
[DataField("popupAppearOther"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public string PopupAppearOther = "system-hologram-phasing-appear-others";

/// <summary>
/// The string to use for the popup when the Hologram appears, shown to themselves.
/// </summary>
[DataField("popupAppearSelf"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public string PopupAppearSelf = "system-hologram-phasing-appear-self";

/// <summary>
/// The string to use for the popup when the Hologram disappears, shown to others.
/// </summary>
[DataField("popupDisappearOther"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public string PopupDisappearOther = "system-hologram-phasing-disappear-others";

/// <summary>
/// The string to use for the popup when the Hologram is killed, shown to themselves.
/// </summary>
[DataField("popupDeathSelf"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public string PopupDeathSelf = "system-hologram-phasing-death-self";

/// <summary>
/// The string to use for the popup when the Hologram fails to interact with something, due to their non-solid nature.
/// </summary>
[DataField("popupHoloInteractionFail"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public string PopupHoloInteractionFail = "system-hologram-interaction-with-others-fail";

/// <summary>
/// The string to use for the popup when the someone fails to interact with the Hologram, due to their non-holographic nature.
/// </summary>
[DataField("popupInteractionWithHoloFail"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public string PopupInteractionWithHoloFail = "system-hologram-interaction-with-holo-fail";

/// <summary>
/// A list of tags for the Hologram to collide with, assuming they're not hardlight.
/// </summary>
/// <remarks>
/// This should generally include the 'Wall' tag.
/// </remarks>
[DataField("collideTags", customTypeSerializer: typeof(PrototypeIdListSerializer<TagPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public List<string> CollideTags = new() { "Wall", "Airlock" };
[DataField("collideWhitelist"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public EntityWhitelist CollideWhitelist = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public sealed partial class HologramServerLinkedComponent : Component
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("gridBound"), AutoNetworkedField]
[AutoNetworkedField]
public bool GridBound = true;

/// <summary>
Expand All @@ -28,6 +27,5 @@ public sealed partial class HologramServerLinkedComponent : Component
/// </remarks>
[ViewVariables(VVAccess.ReadOnly)]
[AutoNetworkedField]
[AutoNetworkedField]
public EntityUid? LinkedServer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public virtual void DoReturnHologram(EntityUid hologram, HologramProjectedCompon

// If their last visited Projector is invalid ignoring occlusion and none is found
if (!IsHoloProjectorValid(hologram, holoProjectedComp.CurProjector, 0, false) &&
!TryGetHoloProjector(hologram, holoProjectedComp.ProjectorRange, out holoProjectedComp.CurProjector, holoProjectedComp, false))
!TryGetHoloProjector(hologram, holoProjectedComp.ProjectorRange, out holoProjectedComp.CurProjector, holoProjectedComp, false))
{
// Kill the hologram.
// Kill the hologram.
TryKillHologram(hologram);
return;
}
Expand Down Expand Up @@ -190,8 +190,11 @@ public bool IsHoloProjectorValid(MapCoordinates hologram, [NotNullWhen(true)] En
/// </remarks>
/// <param name="hologram">The hologram to move.</param>
/// <param name="projector">The projector to move it to, or the projector's position.</param>
public void MoveHologram(EntityUid hologram, EntityCoordinates projector)
public void MoveHologram(EntityUid hologram, EntityCoordinates projector, HologramComponent? holoComp = null)
{
if (!Resolve(hologram, ref holoComp))
return;

// Stops any pulling goin on.
if (TryComp<SharedPullableComponent>(hologram, out var pullable) && pullable.BeingPulled)
_pulling.TryStopPull(pullable);
Expand All @@ -206,8 +209,8 @@ public void MoveHologram(EntityUid hologram, EntityCoordinates projector)
if (!_timing.InPrediction) // TODOPark: HOLO Change this to run on the first prediction once it predicts reliably.
{
var holoPos = Transform(hologram).Coordinates;
_audio.Play(filename: "/Audio/SimpleStation14/Effects/Hologram/holo_off.ogg", playerFilter: Filter.Pvs(hologram), coordinates: holoPos, false);
_popup.PopupCoordinates(Loc.GetString(PopupDisappearOther, ("name", meta.EntityName)), holoPos, Filter.PvsExcept(hologram), false, PopupType.MediumCaution);
_audio.Play(holoComp.OffSound, playerFilter: Filter.Pvs(hologram), coordinates: holoPos, false);
_popup.PopupCoordinates(Loc.GetString(holoComp.PopupDisappearOther, ("name", meta.EntityName)), holoPos, Filter.PvsExcept(hologram), false, PopupType.MediumCaution);
}

// Does the do.
Expand All @@ -217,16 +220,16 @@ public void MoveHologram(EntityUid hologram, EntityCoordinates projector)
// Plays the appearing effects.
if (!_timing.InPrediction)
{
_audio.PlayPvs("/Audio/SimpleStation14/Effects/Hologram/holo_on.ogg", hologram);
_popup.PopupEntity(Loc.GetString(PopupAppearOther, ("name", meta.EntityName)), hologram, Filter.PvsExcept(hologram), false, PopupType.Medium);
_popup.PopupEntity(Loc.GetString(PopupAppearSelf, ("name", meta.EntityName)), hologram, hologram, PopupType.Large);
_audio.PlayPvs(holoComp.OnSound, hologram);
_popup.PopupEntity(Loc.GetString(holoComp.PopupAppearOther, ("name", meta.EntityName)), hologram, Filter.PvsExcept(hologram), false, PopupType.Medium);
_popup.PopupEntity(Loc.GetString(holoComp.PopupAppearSelf, ("name", meta.EntityName)), hologram, hologram, PopupType.Large);
}
}

/// <inheritdoc cref="MoveHologram"/>
public void MoveHologramToProjector(EntityUid hologram, EntityUid projector)
public void MoveHologramToProjector(EntityUid hologram, EntityUid projector, HologramComponent? holoComp = null)
{
MoveHologram(hologram, Transform(projector).Coordinates);
MoveHologram(hologram, Transform(projector).Coordinates, holoComp);
}

protected bool ProjectedUpdate(EntityUid hologram, HologramProjectedComponent hologramProjectedComp, float frameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ public abstract partial class SharedHologramSystem : EntitySystem
[Dependency] private readonly SharedPullingSystem _pulling = default!;
[Dependency] private readonly IGameTiming _timing = default!;

protected const string PopupAppearOther = "system-hologram-phasing-appear-others";
protected const string PopupAppearSelf = "system-hologram-phasing-appear-self";
protected const string PopupDisappearOther = "system-hologram-phasing-disappear-others";
protected const string PopupDeathSelf = "system-hologram-phasing-death-self";
protected const string PopupHoloInteractionFail = "system-hologram-interaction-with-others-fail";
protected const string PopupInteractionWithHoloFail = "system-hologram-interaction-with-holo-fail";

public const string TagHardLight = "Hardlight";
public const string TagHoloMapped = "HoloMapped"; // TODO: HOLO

Expand Down Expand Up @@ -73,7 +66,7 @@ private void OnInteractionWithHoloAttempt(EntityUid uid, HologramComponent compo

private void OnHoloCollide(EntityUid uid, HologramComponent component, ref PreventCollideEvent args)
{
if (Transform(args.OtherEntity).Anchored || HoloInteractionAllowed(args.OurEntity, args.OtherEntity, component))
if (HoloInteractionAllowed(args.OurEntity, args.OtherEntity, component))
return;

args.Cancelled = true;
Expand All @@ -89,7 +82,14 @@ public bool HoloInteractionAllowed(EntityUid hologram, EntityUid? potential, Hol
{
if (potential == null)
return true;
return _tags.HasTag(hologram, TagHardLight) || _tags.HasTag(potential.Value, TagHardLight) || Resolve(hologram, ref holoComp) == HasComp<HologramComponent>(potential);

if (!Resolve(hologram, ref holoComp))
return false;

return _tags.HasTag(hologram, TagHardLight) || // Is the hologram hardlight?
_tags.HasTag(potential.Value, TagHardLight) || // Is the collider hardlight?
HasComp<HologramComponent>(potential) || // Is the collider a hologram?
holoComp.CollideWhitelist.IsValid(potential.Value); // Is the collider whitelisted in the hologram's collision whitelist?
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@
components:
- type: Hologram
isHardLight: false
collideTags:
- Wall
collideWhitelist:
components:
- Airlock
tags:
- Wall
- type: HologramProjected
gracePeriod: 0.08
validProjectorWhitelist:
Expand Down

0 comments on commit 311227d

Please sign in to comment.