Files
tbd-station-14/Content.Server/GameObjects/Components/RadioComponent.cs
DrSmugleaf b9196d0a10 Add a test that puts all components on an entity and checks for no exceptions (#1815)
* Add test that puts all components on an entity and checks for no exceptions

Also fix all the exceptions that happened because of this

* Add comments to the test

* Fix nullable errors

* Fix more nullable errors

* More nullable error fixes

* Unignore basic actor component

* Fix more nullable errors

* NULLABLE ERROR

* Add string interpolation

* Merge if checks

* Remove redundant pragma warning disable 649

* Address reviews

* Remove null wrappers around TryGetComponent

* Merge conflict fixes

* APC battery component error fix

* Fix power test

* Fix atmos mapgrid usages
2020-08-22 22:29:20 +02:00

83 lines
2.2 KiB
C#

using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Content.Server.Interfaces.Chat;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components
{
[RegisterComponent]
class RadioComponent : Component, IUse, IListen
{
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
public override string Name => "Radio";
private bool _radioOn;
private int _listenRange = 7;
private RadioSystem _radioSystem = default!;
[ViewVariables]
public bool RadioOn
{
get => _radioOn;
private set
{
_radioOn = value;
Dirty();
}
}
public override void Initialize()
{
base.Initialize();
_radioSystem = _entitySystemManager.GetEntitySystem<RadioSystem>();
RadioOn = false;
}
public void PassOnMessage(string message)
{
if(RadioOn)
{
_radioSystem.SpreadMessage(Owner, message);
}
}
public void Speaker(string message)
{
var chat = IoCManager.Resolve<IChatManager>();
chat.EntitySay(Owner, message);
}
public bool UseEntity(UseEntityEventArgs eventArgs)
{
RadioOn = !RadioOn;
if(RadioOn)
{
_notifyManager.PopupMessage(Owner, eventArgs.User, "The radio is now on.");
}
else
{
_notifyManager.PopupMessage(Owner, eventArgs.User, "The radio is now off.");
}
return true;
}
public void HeardSpeech(string speech, IEntity source)
{
PassOnMessage(speech);
}
public int GetListenRange()
{
return _listenRange;
}
}
}