Skip to content

Commit

Permalink
print
Browse files Browse the repository at this point in the history
  • Loading branch information
babaevlsdd committed Jun 26, 2024
1 parent 7d60996 commit e8b4a4a
Show file tree
Hide file tree
Showing 41 changed files with 487 additions and 1 deletion.
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;
}
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;
}
124 changes: 124 additions & 0 deletions Content.Server/_Sunrise/FootPrints/FootPrintsSystem.cs
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 Content.Server/_Sunrise/FootPrints/PuddleFootPrintsSystem.cs
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;
}

}
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Effects/puddle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@
solution: puddle
- type: BadDrink
- type: IgnoresFingerprints
- type: PuddleFootPrints # Sunrise-edit
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/arachnid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
state: "creampie_arachnid"
visible: false
# Sunrise-start
- type: FootPrints
leftBarePrint: "footprint-left-bare-spider"
rightBarePrint: "footprint-right-bare-spider"
- type: FootstepModifier
footstepSoundCollection:
collection: FootstepSpiderLegs
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Species/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
components:
- type: Carriable # Sunrise-edit
- type: CanEscapeInventory # Sunrise-edit
- type: FootPrints # Sunrise-edit
- type: Barotrauma
damage:
types:
Expand Down
5 changes: 5 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/diona.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
actionPrototype: DionaGibAction
allowedStates:
- Dead
# Sunrise-start
- type: FootPrints
leftBarePrint: "footprint-left-bare-diona"
rightBarePrint: "footprint-right-bare-diona"
# Sunrise-end

- type: entity
parent: BaseSpeciesDummy
Expand Down
5 changes: 5 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/dwarf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
hideLayersOnEquip:
- Hair
- Snout
# Sunrise-start
- type: FootPrints
leftBarePrint: "footprint-left-bare-dwarf"
rightBarePrint: "footprint-right-bare-dwarf"
# Sunrise-end

- type: entity
parent: BaseSpeciesDummy
Expand Down
5 changes: 5 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/reptilian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
types:
Heat : 1.5 #per second, scales with temperature & other constants
- type: Wagging
# Sunrise-start
- type: FootPrints
leftBarePrint: "footprint-left-bare-lizard"
rightBarePrint: "footprint-right-bare-lizard"
# Sunrise-end

- type: entity
parent: BaseSpeciesDummy
Expand Down
5 changes: 5 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/slime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
types:
Asphyxiation: -1.0
maxSaturation: 15
# Sunrise-start
- type: FootPrints
leftBarePrint: "footprint-left-bare-slime"
rightBarePrint: "footprint-right-bare-slime"
# Sunrise-end

- type: entity
parent: MobHumanDummy
Expand Down
Loading

0 comments on commit e8b4a4a

Please sign in to comment.