-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d60996
commit e8b4a4a
Showing
41 changed files
with
487 additions
and
1 deletion.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
Content.Server/_Sunrise/FootPrints/Components/FootPrintsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Numerics; | ||
|
||
namespace Content.Server.FootPrints.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class FootPrintsComponent : Component | ||
{ | ||
[DataField] | ||
public string LeftBarePrint = "footprint-left-bare-human"; | ||
|
||
[DataField] | ||
public string RightBarePrint = "footprint-right-bare-human"; | ||
|
||
[DataField] | ||
public string ShoesPrint = "footprint-shoes"; | ||
|
||
[DataField] | ||
public string SuitPrint = "footprint-suit"; | ||
|
||
[DataField] | ||
public string[] DraggingPrint = | ||
{ | ||
"dragging-1", | ||
"dragging-2", | ||
"dragging-3", | ||
"dragging-4", | ||
"dragging-5" | ||
}; | ||
|
||
[DataField] | ||
public Vector2 OffsetCenter = new(-0.5f, -1f); | ||
|
||
[DataField] | ||
public Vector2 OffsetPrint = new(0.1f, 0f); | ||
|
||
[DataField] | ||
public Color PrintsColor = Color.FromHex("#00000000"); | ||
|
||
[DataField] | ||
public float StepSize = 0.7f; | ||
|
||
[DataField] | ||
public float DragSize = 0.5f; | ||
|
||
[DataField] | ||
public float ColorQuantity; | ||
|
||
public Vector2 StepPos = Vector2.Zero; | ||
|
||
public bool RightStep = true; | ||
} |
8 changes: 8 additions & 0 deletions
8
Content.Server/_Sunrise/FootPrints/Components/PuddleFootPrintsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Content.Server.FootPrints.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class PuddleFootPrintsComponent : Component | ||
{ | ||
public float SizeRatio = 0.3f; | ||
public float OffPercent = 80f; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using System.Linq; | ||
using Content.Server.Atmos.Components; | ||
using Content.Server.Decals; | ||
using Content.Server.FootPrints.Components; | ||
using Content.Shared.Inventory; | ||
using Content.Shared.Standing; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server.FootPrints; | ||
|
||
public sealed class FootPrintsSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly DecalSystem _decals = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly InventorySystem _inventorySystem = default!; | ||
[Dependency] private readonly StandingStateSystem _standing = default!; | ||
|
||
private const float AlphaReduce = 0.15f; | ||
|
||
private List<KeyValuePair<EntityUid, uint>> _storedDecals = new(); | ||
private const int MaxStoredDecals = 750; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<FootPrintsComponent, MoveEvent>(OnMove); | ||
} | ||
|
||
private void OnMove(EntityUid uid, FootPrintsComponent component, ref MoveEvent args) | ||
{ | ||
if (component.PrintsColor.A <= 0f) | ||
return; | ||
|
||
if (!TryComp<TransformComponent>(uid, out var transform)) | ||
return; | ||
|
||
var dragging = _standing.IsDown(uid); | ||
var distance = (transform.LocalPosition - component.StepPos).Length(); | ||
var stepSize = dragging ? component.DragSize : component.StepSize; | ||
|
||
if (!(distance > stepSize)) | ||
return; | ||
|
||
|
||
if (!PrintDecal((uid, component, transform), dragging)) | ||
return; | ||
|
||
var newAlpha = Math.Max(component.PrintsColor.A - AlphaReduce, 0f); | ||
|
||
component.PrintsColor = component.PrintsColor.WithAlpha(newAlpha); | ||
component.StepPos = transform.LocalPosition; | ||
component.RightStep = !component.RightStep; | ||
} | ||
|
||
private bool PrintDecal(Entity<FootPrintsComponent, TransformComponent> prints, bool dragging) | ||
{ | ||
if (prints.Comp2.GridUid is not { } gridUid) | ||
return false; | ||
|
||
if (_storedDecals.Count > MaxStoredDecals) | ||
{ | ||
var excessDecals = _storedDecals.Count - MaxStoredDecals; | ||
RemoveExcessDecals(excessDecals); | ||
} | ||
|
||
var print = PickPrint(prints, dragging); | ||
var coords = CalculateEntityCoordinates(prints, dragging); | ||
var colors = prints.Comp1.PrintsColor; | ||
var rotation = dragging | ||
? (prints.Comp2.LocalPosition - prints.Comp1.StepPos).ToAngle() + Angle.FromDegrees(-90f) | ||
: prints.Comp2.LocalRotation + Angle.FromDegrees(180f); | ||
|
||
|
||
if (!_decals.TryAddDecal(print, coords, out var decalId, colors, rotation, 0, true)) | ||
return false; | ||
|
||
_storedDecals.Add(new KeyValuePair<EntityUid, uint>(gridUid, decalId)); | ||
return true; | ||
} | ||
|
||
private EntityCoordinates CalculateEntityCoordinates(Entity<FootPrintsComponent, TransformComponent> entity, | ||
bool isDragging) | ||
{ | ||
var printComp = entity.Comp1; | ||
var transform = entity.Comp2; | ||
|
||
if (isDragging) | ||
return new EntityCoordinates(entity, transform.LocalPosition + printComp.OffsetCenter); | ||
|
||
var offset = printComp.OffsetCenter + (printComp.RightStep | ||
? new Angle(Angle.FromDegrees(180f) + transform.LocalRotation).RotateVec(printComp.OffsetPrint) | ||
: new Angle(transform.LocalRotation).RotateVec(printComp.OffsetPrint)); | ||
|
||
return new EntityCoordinates(entity, transform.LocalPosition + offset); | ||
} | ||
|
||
|
||
private string PickPrint(Entity<FootPrintsComponent> prints, bool dragging) | ||
{ | ||
if (dragging) | ||
return _random.Pick(prints.Comp.DraggingPrint); | ||
|
||
if (_inventorySystem.TryGetSlotEntity(prints, "shoes", out _)) | ||
return prints.Comp.ShoesPrint; | ||
|
||
if (_inventorySystem.TryGetSlotEntity(prints, "outerClothing", out var suit) && | ||
TryComp<PressureProtectionComponent>(suit, out _)) | ||
return prints.Comp.SuitPrint; | ||
|
||
return prints.Comp.RightStep ? prints.Comp.RightBarePrint : prints.Comp.LeftBarePrint; | ||
} | ||
|
||
private void RemoveExcessDecals(int excessDecals) | ||
{ | ||
for (var i = 0; i < excessDecals; i++) | ||
{ | ||
var decalToRemove = _storedDecals[i]; | ||
_decals.RemoveDecal(decalToRemove.Key, decalToRemove.Value); | ||
} | ||
|
||
_storedDecals = _storedDecals.Skip(excessDecals).ToList(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Content.Server/_Sunrise/FootPrints/PuddleFootPrintsSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Content.Server.FootPrints.Components; | ||
using Content.Shared.Fluids.Components; | ||
using Robust.Shared.Physics.Events; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.FootPrints; | ||
|
||
public sealed class PuddleFootPrintsSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IPrototypeManager _prototype = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<PuddleFootPrintsComponent, EndCollideEvent>(OnStepTrigger); | ||
} | ||
|
||
private void OnStepTrigger(EntityUid uid, PuddleFootPrintsComponent comp, ref EndCollideEvent args) | ||
{ | ||
if (!TryComp<FootPrintsComponent>(args.OtherEntity, out var footPrints)) | ||
return; | ||
|
||
if (!TryComp<PuddleComponent>(uid, out var puddle) || puddle.Solution is not { } entSolution) | ||
return; | ||
|
||
|
||
var solution = entSolution.Comp.Solution; | ||
var quantity = solution.Volume; | ||
var color = solution.GetColor(_prototype); | ||
|
||
footPrints.PrintsColor = footPrints.ColorQuantity == 0f | ||
? color | ||
: Color.InterpolateBetween(footPrints.PrintsColor, color, 0.3f); | ||
footPrints.ColorQuantity += quantity.Float() * 1.2f; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,3 +163,4 @@ | |
solution: puddle | ||
- type: BadDrink | ||
- type: IgnoresFingerprints | ||
- type: PuddleFootPrints # Sunrise-edit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.