H.O.N.K. mech (#14670)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-05-05 13:21:13 +00:00
committed by GitHub
parent 19b313b218
commit bc101e1fb5
49 changed files with 822 additions and 8 deletions

View File

@@ -0,0 +1,16 @@
using Content.Shared.Mech.Equipment.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
namespace Content.Shared.Mech.Equipment.Components;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(MechSoundboardSystem))]
public sealed partial class MechSoundboardComponent : Component
{
/// <summary>
/// List of sounds that can be played
/// </summary>
[DataField("sounds"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public List<SoundCollectionSpecifier> Sounds = new();
}

View File

@@ -0,0 +1,57 @@
using Content.Shared.Mech;
using Content.Shared.Mech.Equipment.Components;
using Content.Shared.Mech.Equipment.Systems;
using Content.Shared.Timing;
using Robust.Shared.Audio;
using System.Linq;
namespace Content.Shared.Mech.Equipment.Systems;
/// <summary>
/// Handles everything for mech soundboard.
/// </summary>
public sealed class MechSoundboardSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MechSoundboardComponent, MechEquipmentUiStateReadyEvent>(OnUiStateReady);
SubscribeLocalEvent<MechSoundboardComponent, MechEquipmentUiMessageRelayEvent>(OnSoundboardMessage);
}
private void OnUiStateReady(EntityUid uid, MechSoundboardComponent comp, MechEquipmentUiStateReadyEvent args)
{
// you have to specify a collection so it must exist probably
var sounds = comp.Sounds.Select(sound => sound.Collection!);
var state = new MechSoundboardUiState
{
Sounds = sounds.ToList()
};
args.States.Add(uid, state);
}
private void OnSoundboardMessage(EntityUid uid, MechSoundboardComponent comp, MechEquipmentUiMessageRelayEvent args)
{
if (args.Message is not MechSoundboardPlayMessage msg)
return;
if (!TryComp<MechEquipmentComponent>(uid, out var equipment) ||
equipment.EquipmentOwner == null)
return;
if (msg.Sound >= comp.Sounds.Count)
return;
if (_useDelay.ActiveDelay(uid))
return;
// honk!!!!!
var mech = equipment.EquipmentOwner.Value;
_useDelay.BeginDelay(uid);
_audio.PlayPvs(comp.Sounds[msg.Sound], uid);
}
}

View File

@@ -67,6 +67,21 @@ public sealed class MechGrabberEjectMessage : MechEquipmentUiMessage
}
}
/// <summary>
/// Event raised for the soundboard equipment to play a sound from its component
/// </summary>
[Serializable, NetSerializable]
public sealed class MechSoundboardPlayMessage : MechEquipmentUiMessage
{
public int Sound;
public MechSoundboardPlayMessage(EntityUid equipment, int sound)
{
Equipment = equipment;
Sound = sound;
}
}
/// <summary>
/// BUI state for mechs that also contains all equipment ui states.
/// </summary>
@@ -100,3 +115,12 @@ public sealed class MechGrabberUiState : BoundUserInterfaceState
public List<EntityUid> Contents = new();
public int MaxContents;
}
/// <summary>
/// List of sound collection ids to be localized and displayed.
/// </summary>
[Serializable, NetSerializable]
public sealed class MechSoundboardUiState : BoundUserInterfaceState
{
public List<string> Sounds = new();
}