Skip to content

Commit

Permalink
Merge pull request #280 from formlessnameless/dev
Browse files Browse the repository at this point in the history
Upstream merge
  • Loading branch information
formlessnameless authored Sep 18, 2024
2 parents a94be89 + 3df9c46 commit b1e93d6
Show file tree
Hide file tree
Showing 104 changed files with 2,444 additions and 288 deletions.
12 changes: 11 additions & 1 deletion Content.Client/Anomaly/AnomalySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public override void Initialize()
SubscribeLocalEvent<AnomalyComponent, AppearanceChangeEvent>(OnAppearanceChanged);
SubscribeLocalEvent<AnomalyComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<AnomalyComponent, AnimationCompletedEvent>(OnAnimationComplete);
}

SubscribeLocalEvent<AnomalySupercriticalComponent, ComponentShutdown>(OnShutdown);
}
private void OnStartup(EntityUid uid, AnomalyComponent component, ComponentStartup args)
{
_floating.FloatAnimation(uid, component.FloatingOffset, component.AnimationKey, component.AnimationTime);
Expand Down Expand Up @@ -75,4 +76,13 @@ public override void Update(float frameTime)
}
}
}

private void OnShutdown(Entity<AnomalySupercriticalComponent> ent, ref ComponentShutdown args)
{
if (!TryComp<SpriteComponent>(ent, out var sprite))
return;

sprite.Scale = Vector2.One;
sprite.Color = sprite.Color.WithAlpha(1f);
}
}
50 changes: 50 additions & 0 deletions Content.Client/Anomaly/Effects/ClientInnerBodySystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Content.Shared.Anomaly.Components;
using Content.Shared.Anomaly.Effects;
using Content.Shared.Body.Components;
using Robust.Client.GameObjects;

namespace Content.Client.Anomaly.Effects;

public sealed class ClientInnerBodyAnomalySystem : SharedInnerBodyAnomalySystem
{
public override void Initialize()
{
SubscribeLocalEvent<InnerBodyAnomalyComponent, AfterAutoHandleStateEvent>(OnAfterHandleState);
SubscribeLocalEvent<InnerBodyAnomalyComponent, ComponentShutdown>(OnCompShutdown);
}

private void OnAfterHandleState(Entity<InnerBodyAnomalyComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (!TryComp<SpriteComponent>(ent, out var sprite))
return;

if (ent.Comp.FallbackSprite is null)
return;

if (!sprite.LayerMapTryGet(ent.Comp.LayerMap, out var index))
index = sprite.LayerMapReserveBlank(ent.Comp.LayerMap);

if (TryComp<BodyComponent>(ent, out var body) &&
body.Prototype is not null &&
ent.Comp.SpeciesSprites.TryGetValue(body.Prototype.Value, out var speciesSprite))
{
sprite.LayerSetSprite(index, speciesSprite);
}
else
{
sprite.LayerSetSprite(index, ent.Comp.FallbackSprite);
}

sprite.LayerSetVisible(index, true);
sprite.LayerSetShader(index, "unshaded");
}

private void OnCompShutdown(Entity<InnerBodyAnomalyComponent> ent, ref ComponentShutdown args)
{
if (!TryComp<SpriteComponent>(ent, out var sprite))
return;

var index = sprite.LayerMapGet(ent.Comp.LayerMap);
sprite.LayerSetVisible(index, false);
}
}
3 changes: 3 additions & 0 deletions Content.Client/Audio/AmbientSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ private void ProcessNearbyAmbience(TransformComponent playerXform)
.WithMaxDistance(comp.Range);

var stream = _audio.PlayEntity(comp.Sound, Filter.Local(), uid, false, audioParams);
if (stream == null)
continue;

_playingSounds[sourceEntity] = (stream.Value.Entity, comp.Sound, key);
playingCount++;

Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Audio/ClientGlobalSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void PlayAdminSound(AdminSoundEvent soundEvent)
if(!_adminAudioEnabled) return;

var stream = _audio.PlayGlobal(soundEvent.Filename, Filter.Local(), false, soundEvent.AudioParams);
_adminAudio.Add(stream.Value.Entity);
_adminAudio.Add(stream?.Entity);
}

private void PlayStationEventMusic(StationEventMusicEvent soundEvent)
Expand All @@ -76,7 +76,7 @@ private void PlayStationEventMusic(StationEventMusicEvent soundEvent)
if(!_eventAudioEnabled || _eventAudio.ContainsKey(soundEvent.Type)) return;

var stream = _audio.PlayGlobal(soundEvent.Filename, Filter.Local(), false, soundEvent.AudioParams);
_eventAudio.Add(soundEvent.Type, stream.Value.Entity);
_eventAudio.Add(soundEvent.Type, stream?.Entity);
}

private void PlayGameSound(GameGlobalSoundEvent soundEvent)
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Audio/ContentAudioSystem.AmbientMusic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ private void UpdateAmbientMusic()
false,
AudioParams.Default.WithVolume(_musicProto.Sound.Params.Volume + _volumeSlider));

_ambientMusicStream = strim.Value.Entity;
_ambientMusicStream = strim?.Entity;

if (_musicProto.FadeIn)
if (_musicProto.FadeIn && strim != null)
{
FadeIn(_ambientMusicStream, strim.Value.Component, AmbientMusicFadeTime);
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Audio/ContentAudioSystem.LobbyMusic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void PlaySoundtrack(string soundtrackFilename)
false,
_lobbySoundtrackParams.WithVolume(_lobbySoundtrackParams.Volume + SharedAudioSystem.GainToVolume(_configManager.GetCVar(CCVars.LobbyMusicVolume)))
);
if (playResult.Value.Entity == default)
if (playResult == null)
{
_sawmill.Warning(
$"Tried to play lobby soundtrack '{{Filename}}' using {nameof(SharedAudioSystem)}.{nameof(SharedAudioSystem.PlayGlobal)} but it returned default value of EntityUid!",
Expand Down
20 changes: 9 additions & 11 deletions Content.Client/Examine/ExamineSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System.Linq;
using System.Numerics;
using System.Threading;
using Content.Client.Verbs;
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Input;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
Expand All @@ -12,13 +17,8 @@
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Utility;
using System.Linq;
using System.Numerics;
using System.Threading;
using static Content.Shared.Interaction.SharedInteractionSystem;
using static Robust.Client.UserInterface.Controls.BoxContainer;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Direction = Robust.Shared.Maths.Direction;

namespace Content.Client.Examine
Expand All @@ -35,7 +35,6 @@ public sealed class ExamineSystem : ExamineSystemShared

private EntityUid _examinedEntity;
private EntityUid _lastExaminedEntity;
private EntityUid _playerEntity;
private Popup? _examineTooltipOpen;
private ScreenCoordinates _popupPos;
private CancellationTokenSource? _requestCancelTokenSource;
Expand Down Expand Up @@ -74,9 +73,9 @@ private void OnExaminedItemDropped(EntityUid item, ItemComponent comp, DroppedEv
public override void Update(float frameTime)
{
if (_examineTooltipOpen is not {Visible: true}) return;
if (!_examinedEntity.Valid || !_playerEntity.Valid) return;
if (!_examinedEntity.Valid || _playerManager.LocalEntity is not { } player) return;

if (!CanExamine(_playerEntity, _examinedEntity))
if (!CanExamine(player, _examinedEntity))
CloseTooltip();
}

Expand Down Expand Up @@ -114,9 +113,8 @@ private bool HandleExamine(in PointerInputCmdHandler.PointerInputCmdArgs args)
return false;
}

_playerEntity = _playerManager.LocalEntity ?? default;

if (_playerEntity == default || !CanExamine(_playerEntity, entity))
if (_playerManager.LocalEntity is not { } player ||
!CanExamine(player, entity))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Traits/ParacusiaSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void PlayParacusiaSounds(EntityUid uid)
var newCoords = Transform(uid).Coordinates.Offset(randomOffset);

// Play the sound
paracusia.Stream = _audio.PlayStatic(paracusia.Sounds, uid, newCoords).Value.Entity;
paracusia.Stream = _audio.PlayStatic(paracusia.Sounds, uid, newCoords)?.Entity;
}

}
9 changes: 5 additions & 4 deletions Content.Client/Weather/WeatherSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ protected override void Run(EntityUid uid, WeatherData weather, WeatherPrototype
if (!Timing.IsFirstTimePredicted || weatherProto.Sound == null)
return;

weather.Stream ??= _audio.PlayGlobal(weatherProto.Sound, Filter.Local(), true).Value.Entity;
weather.Stream ??= _audio.PlayGlobal(weatherProto.Sound, Filter.Local(), true)?.Entity;

if (!TryComp(weather.Stream, out AudioComponent? comp))
return;

var stream = weather.Stream.Value;
var comp = Comp<AudioComponent>(stream);
var occlusion = 0f;

// Work out tiles nearby to determine volume.
Expand Down Expand Up @@ -115,7 +116,7 @@ protected override void Run(EntityUid uid, WeatherData weather, WeatherPrototype

var alpha = GetPercent(weather, uid);
alpha *= SharedAudioSystem.VolumeToGain(weatherProto.Sound.Params.Volume);
_audio.SetGain(stream, alpha, comp);
_audio.SetGain(weather.Stream, alpha, comp);
comp.Occlusion = occlusion;
}

Expand Down
44 changes: 39 additions & 5 deletions Content.Server/Anomaly/AnomalySynchronizerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Numerics;
using Content.Server.Anomaly.Components;
using Content.Server.DeviceLinking.Systems;
using Content.Server.Power.Components;
Expand All @@ -10,6 +11,7 @@
using Content.Shared.Power;
using Robust.Shared.Audio.Systems;
using Content.Shared.Verbs;
using Robust.Shared.Timing;

namespace Content.Server.Anomaly;

Expand All @@ -25,6 +27,7 @@ public sealed partial class AnomalySynchronizerSystem : EntitySystem
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly PowerReceiverSystem _power = default!;
[Dependency] private readonly IGameTiming _timing = default!;

public override void Initialize()
{
Expand All @@ -40,6 +43,34 @@ public override void Initialize()
SubscribeLocalEvent<AnomalyStabilityChangedEvent>(OnAnomalyStabilityChanged);
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<AnomalySynchronizerComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var sync, out var xform))
{
if (sync.ConnectedAnomaly is null)
continue;

if (_timing.CurTime < sync.NextCheckTime)
continue;
sync.NextCheckTime += sync.CheckFrequency;

if (Transform(sync.ConnectedAnomaly.Value).MapUid != Transform(uid).MapUid)
{
DisconnectFromAnomaly((uid, sync), sync.ConnectedAnomaly.Value);
continue;
}

if (!xform.Coordinates.TryDistance(EntityManager, Transform(sync.ConnectedAnomaly.Value).Coordinates, out var distance))
continue;

if (distance > sync.AttachRange)
DisconnectFromAnomaly((uid, sync), sync.ConnectedAnomaly.Value);
}
}

/// <summary>
/// If powered, try to attach a nearby anomaly.
/// </summary>
Expand Down Expand Up @@ -73,10 +104,10 @@ private void OnPowerChanged(Entity<AnomalySynchronizerComponent> ent, ref PowerC
if (args.Powered)
return;

if (!TryComp<AnomalyComponent>(ent.Comp.ConnectedAnomaly, out var anomaly))
if (ent.Comp.ConnectedAnomaly is null)
return;

DisconnectFromAnomaly(ent, anomaly);
DisconnectFromAnomaly(ent, ent.Comp.ConnectedAnomaly.Value);
}

private void OnExamined(Entity<AnomalySynchronizerComponent> ent, ref ExaminedEvent args)
Expand Down Expand Up @@ -125,13 +156,16 @@ private void ConnectToAnomaly(Entity<AnomalySynchronizerComponent> ent, Entity<A

//TODO: disconnection from the anomaly should also be triggered if the anomaly is far away from the synchronizer.
//Currently only bluespace anomaly can do this, but for some reason it is the only one that cannot be connected to the synchronizer.
private void DisconnectFromAnomaly(Entity<AnomalySynchronizerComponent> ent, AnomalyComponent anomaly)
private void DisconnectFromAnomaly(Entity<AnomalySynchronizerComponent> ent, EntityUid other)
{
if (ent.Comp.ConnectedAnomaly == null)
return;

if (ent.Comp.PulseOnDisconnect)
_anomaly.DoAnomalyPulse(ent.Comp.ConnectedAnomaly.Value, anomaly);
if (TryComp<AnomalyComponent>(other, out var anomaly))
{
if (ent.Comp.PulseOnDisconnect)
_anomaly.DoAnomalyPulse(ent.Comp.ConnectedAnomaly.Value, anomaly);
}

_popup.PopupEntity(Loc.GetString("anomaly-sync-disconnected"), ent, PopupType.Large);
_audio.PlayPvs(ent.Comp.ConnectedSound, ent);
Expand Down
6 changes: 5 additions & 1 deletion Content.Server/Anomaly/AnomalySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public override void Initialize()
SubscribeLocalEvent<AnomalyComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<AnomalyComponent, StartCollideEvent>(OnStartCollide);


InitializeGenerator();
InitializeScanner();
InitializeVessel();
Expand Down Expand Up @@ -86,7 +87,10 @@ public void ShuffleParticlesEffect(Entity<AnomalyComponent> anomaly)

private void OnShutdown(Entity<AnomalyComponent> anomaly, ref ComponentShutdown args)
{
EndAnomaly(anomaly);
if (anomaly.Comp.CurrentBehavior is not null)
RemoveBehavior(anomaly, anomaly.Comp.CurrentBehavior.Value);

EndAnomaly(anomaly, spawnCore: false);
}

private void OnStartCollide(Entity<AnomalyComponent> anomaly, ref StartCollideEvent args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Content.Server.Anomaly.Components;
/// <summary>
/// a device that allows you to translate anomaly activity into multitool signals.
/// </summary>
[RegisterComponent, Access(typeof(AnomalySynchronizerSystem))]
[RegisterComponent, AutoGenerateComponentPause, Access(typeof(AnomalySynchronizerSystem))]
public sealed partial class AnomalySynchronizerComponent : Component
{
/// <summary>
Expand All @@ -34,6 +34,15 @@ public sealed partial class AnomalySynchronizerComponent : Component
[DataField]
public float AttachRange = 0.4f;

/// <summary>
/// Periodicheski checks to see if the anomaly has moved to disconnect it.
/// </summary>
[DataField]
public TimeSpan CheckFrequency = TimeSpan.FromSeconds(1f);

[DataField, AutoPausedField]
public TimeSpan NextCheckTime = TimeSpan.Zero;

[DataField]
public ProtoId<SourcePortPrototype> DecayingPort = "Decaying";

Expand Down
Loading

0 comments on commit b1e93d6

Please sign in to comment.