-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Augment audio system with the ability to have captions
- Loading branch information
Showing
6 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Numerics; | ||
using Robust.Client.GameObjects; | ||
using Robust.Shared.ComponentTrees; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Maths; | ||
using Robust.Shared.Physics; | ||
using Robust.Shared.Audio.Components; | ||
using Robust.Shared.IoC; | ||
|
||
namespace Robust.Client.ComponentTrees; | ||
|
||
public sealed class CaptionTreeSystem : ComponentTreeSystem<CaptionTreeComponent, CaptionComponent> | ||
{ | ||
[Dependency] private readonly IEntityManager _entityManager = default!; | ||
|
||
#region Component Tree Overrides | ||
protected override bool DoFrameUpdate => false; | ||
protected override bool DoTickUpdate => true; | ||
protected override bool Recursive => true; | ||
protected override int InitialCapacity => 128; | ||
|
||
protected override Box2 ExtractAabb(in ComponentTreeEntry<CaptionComponent> entry, Vector2 pos, Angle rot) | ||
{ | ||
if (_entityManager.TryGetComponent(entry.Uid, out AudioComponent? audio)) | ||
{ | ||
var radius = audio.MaxDistance; | ||
var radiusVec = new Vector2(radius, radius); | ||
return new Box2(pos - radiusVec, pos + radiusVec); | ||
} | ||
return default; | ||
} | ||
|
||
protected override Box2 ExtractAabb(in ComponentTreeEntry<CaptionComponent> entry) | ||
{ | ||
if (entry.Component.TreeUid == null) | ||
return default; | ||
|
||
var pos = XformSystem.GetRelativePosition( | ||
entry.Transform, | ||
entry.Component.TreeUid.Value, | ||
GetEntityQuery<TransformComponent>()); | ||
|
||
return ExtractAabb(in entry, pos, default); | ||
} | ||
#endregion | ||
} |
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,30 @@ | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Localization; | ||
using Robust.Shared.ViewVariables; | ||
using Robust.Shared.Physics; | ||
using Robust.Shared.ComponentTrees; | ||
using Robust.Shared.Serialization.Manager.Attributes; | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Robust.Shared.Audio.Components; | ||
|
||
/// <summary> | ||
/// Stores the caption data for an audio entity. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] | ||
public sealed partial class CaptionComponent : Component, IComponentTreeEntry<CaptionComponent> | ||
{ | ||
[DataField, AutoNetworkedField] | ||
public LocId? Caption { get; set; } | ||
|
||
[ViewVariables(VVAccess.ReadOnly)] | ||
public string? LocalizedCaption => Caption != null ? Loc.GetString(Caption) : null; | ||
|
||
public EntityUid? TreeUid { get; set; } | ||
|
||
public DynamicTree<ComponentTreeEntry<CaptionComponent>>? Tree { get; set; } | ||
|
||
public bool AddToTree => true; | ||
|
||
public bool TreeUpdateQueued { get; set; } | ||
} |
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,14 @@ | ||
using Robust.Shared.Physics; | ||
using Robust.Shared.ComponentTrees; | ||
using Robust.Shared.GameObjects; | ||
|
||
namespace Robust.Shared.Audio.Components; | ||
|
||
/// <summary> | ||
/// Samples nearby <see cref="CaptionComponent"/>. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class CaptionTreeComponent : Component, IComponentTreeComponent<CaptionComponent> | ||
{ | ||
public DynamicTree<ComponentTreeEntry<CaptionComponent>> Tree { get; set; } = default!; | ||
} |
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