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

Add another bell clothing item #762

Merged
merged 7 commits into from
Dec 26, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Complete refactor
Mnemotechnician committed Dec 25, 2023
commit e8615323369b9ea726836ecf64d4fa9648a787e5
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Map;

namespace Content.Shared._NF.Clothing.Components;

/// <summary>
/// Indicates that the clothing entity emits sound when it moves.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class EmitsSoundOnMoveComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField(required: true), AutoNetworkedField]
public SoundSpecifier SoundCollection = default!;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("requiresGravity"), AutoNetworkedField]
public bool RequiresGravity = true;

[ViewVariables(VVAccess.ReadOnly)]
public EntityCoordinates LastPosition = EntityCoordinates.Invalid;

/// <summary>
/// The distance moved since the played sound.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public float SoundDistance = 0f;
}

This file was deleted.

42 changes: 15 additions & 27 deletions Content.Shared/_NF/Clothing/Systems/SoundEmittingClothingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Numerics;
using Content.Shared._NF.Clothing.Components;
using Content.Shared.Clothing.Components;
using Content.Shared.Gravity;
using Content.Shared.Inventory.Events;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
@@ -18,62 +20,48 @@ public sealed class SoundEmittingClothingSystem : EntitySystem
private EntityQuery<InputMoverComponent> _moverQuery;
private EntityQuery<PhysicsComponent> _physicsQuery;
private EntityQuery<TransformComponent> _xformQuery;
private EntityQuery<ClothingComponent> _clothingQuery;

public override void Initialize()
{
_moverQuery = GetEntityQuery<InputMoverComponent>();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();

SubscribeLocalEvent<SoundEmittingClothingComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<SoundEmittingClothingComponent, GotUnequippedEvent>(OnUnequipped);
}

private void OnEquipped(EntityUid uid, SoundEmittingClothingComponent component, GotEquippedEvent args)
{
var comp = EnsureComp<SoundEmittingEntityComponent>(args.Equipee);
comp.SoundCollection = component.SoundCollection;
comp.RequiresGravity = component.RequiresGravity;
}

private void OnUnequipped(EntityUid uid, SoundEmittingClothingComponent component, GotUnequippedEvent args)
{
if (TryComp<SoundEmittingEntityComponent>(args.Equipee, out var comp) &&
comp.SoundCollection == component.SoundCollection)
{
RemComp<SoundEmittingEntityComponent>(args.Equipee);
}
_clothingQuery = GetEntityQuery<ClothingComponent>();
}

public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<SoundEmittingEntityComponent>();
var query = EntityQueryEnumerator<EmitsSoundOnMoveComponent>();
while (query.MoveNext(out var uid, out var comp))
{
UpdateSound(uid, comp);
}
query.Dispose();
}

private void UpdateSound(EntityUid uid, SoundEmittingEntityComponent component)
private void UpdateSound(EntityUid uid, EmitsSoundOnMoveComponent component)
{
if (!_xformQuery.TryGetComponent(uid, out var xform) ||
!_physicsQuery.TryGetComponent(uid, out var physics))
return;

if (!physics.Awake || physics.LinearVelocity.EqualsApprox(Vector2.Zero))
return;

// Space does not transmit sound
if (xform.GridUid == null)
return;

if (component.RequiresGravity && _gravity.IsWeightless(uid, physics, xform))
return;

// The below is shamelessly copied from SharedMoverController
var coordinates = xform.Coordinates;
var distanceNeeded = (_moverQuery.TryGetComponent(uid, out var mover) && mover.Sprinting) ? 2f : 1.5f;
a var parent = xform.ParentUid;
var isWorn = parent is { Valid: true } &&
_clothingQuery.TryGetComponent(uid, out var clothing)
&& clothing.InSlot != null;
// If this entity is worn by another entity, use that entity's coordinates
var coordinates = isWorn ? Transform(parent).Coordinates : xform.Coordinates;
var distanceNeeded = (isWorn && _moverQuery.TryGetComponent(parent, out var mover) && mover.Sprinting)
? 2f // The parent is a mob that is currently sprinting
: 1.5f; // The parent is not a mob or is not sprinting

if (!coordinates.TryDistance(EntityManager, component.LastPosition, out var distance) || distance > distanceNeeded)
component.SoundDistance = distanceNeeded;
4 changes: 2 additions & 2 deletions Resources/Prototypes/_NF/Entities/Clothing/Neck/misc.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
- type: entity
parent: ClothingNeckBase
id: ClothingNeckBellCollar
name: Bell Collar
name: bell collar
description: A way to inform others about your presence, or just to annoy everyone around you!
components:
- type: Sprite
sprite: _NF/Clothing/Neck/bellcollar.rsi
- type: Clothing
sprite: _NF/Clothing/Neck/bellcollar.rsi
- type: SoundEmittingClothing
- type: EmitsSoundOnMove
soundCollection:
collection: FootstepJester
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Resources/Textures/_NF/Clothing/Neck/bellcollar.rsi/inhand-left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.