Move UnpoweredFlashlight to shared (#27449)
This commit is contained in:
@@ -1,113 +0,0 @@
|
|||||||
using Content.Server.Light.Events;
|
|
||||||
using Content.Shared.Actions;
|
|
||||||
using Content.Shared.Decals;
|
|
||||||
using Content.Shared.Emag.Systems;
|
|
||||||
using Content.Shared.Light;
|
|
||||||
using Content.Shared.Light.Components;
|
|
||||||
using Content.Shared.Mind.Components;
|
|
||||||
using Content.Shared.Toggleable;
|
|
||||||
using Content.Shared.Verbs;
|
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.Audio.Systems;
|
|
||||||
using Robust.Shared.Prototypes;
|
|
||||||
using Robust.Shared.Random;
|
|
||||||
using Robust.Shared.Utility;
|
|
||||||
|
|
||||||
namespace Content.Server.Light.EntitySystems
|
|
||||||
{
|
|
||||||
public sealed class UnpoweredFlashlightSystem : EntitySystem
|
|
||||||
{
|
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
|
||||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
|
||||||
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
||||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
|
||||||
[Dependency] private readonly SharedPointLightSystem _light = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
|
|
||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerbs);
|
|
||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetItemActionsEvent>(OnGetActions);
|
|
||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, ToggleActionEvent>(OnToggleAction);
|
|
||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, MindAddedMessage>(OnMindAdded);
|
|
||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, GotEmaggedEvent>(OnGotEmagged);
|
|
||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, MapInitEvent>(OnMapInit);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnMapInit(EntityUid uid, UnpoweredFlashlightComponent component, MapInitEvent args)
|
|
||||||
{
|
|
||||||
_actionContainer.EnsureAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
|
||||||
Dirty(uid, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnToggleAction(EntityUid uid, UnpoweredFlashlightComponent component, ToggleActionEvent args)
|
|
||||||
{
|
|
||||||
if (args.Handled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ToggleLight(uid, component);
|
|
||||||
|
|
||||||
args.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnGetActions(EntityUid uid, UnpoweredFlashlightComponent component, GetItemActionsEvent args)
|
|
||||||
{
|
|
||||||
args.AddAction(ref component.ToggleActionEntity, component.ToggleAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddToggleLightVerbs(EntityUid uid, UnpoweredFlashlightComponent component, GetVerbsEvent<ActivationVerb> args)
|
|
||||||
{
|
|
||||||
if (!args.CanAccess || !args.CanInteract)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ActivationVerb verb = new()
|
|
||||||
{
|
|
||||||
Text = Loc.GetString("toggle-flashlight-verb-get-data-text"),
|
|
||||||
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png")),
|
|
||||||
Act = () => ToggleLight(uid, component),
|
|
||||||
Priority = -1 // For things like PDA's, Open-UI and other verbs that should be higher priority.
|
|
||||||
};
|
|
||||||
|
|
||||||
args.Verbs.Add(verb);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnMindAdded(EntityUid uid, UnpoweredFlashlightComponent component, MindAddedMessage args)
|
|
||||||
{
|
|
||||||
_actionsSystem.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnGotEmagged(EntityUid uid, UnpoweredFlashlightComponent component, ref GotEmaggedEvent args)
|
|
||||||
{
|
|
||||||
if (!_light.TryGetLight(uid, out var light))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_prototypeManager.TryIndex<ColorPalettePrototype>(component.EmaggedColorsPrototype, out var possibleColors))
|
|
||||||
{
|
|
||||||
var pick = _random.Pick(possibleColors.Colors.Values);
|
|
||||||
_light.SetColor(uid, pick, light);
|
|
||||||
}
|
|
||||||
|
|
||||||
args.Repeatable = true;
|
|
||||||
args.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ToggleLight(EntityUid uid, UnpoweredFlashlightComponent flashlight)
|
|
||||||
{
|
|
||||||
if (!_light.TryGetLight(uid, out var light))
|
|
||||||
return;
|
|
||||||
|
|
||||||
flashlight.LightOn = !flashlight.LightOn;
|
|
||||||
_light.SetEnabled(uid, flashlight.LightOn, light);
|
|
||||||
|
|
||||||
_appearance.SetData(uid, UnpoweredFlashlightVisuals.LightOn, flashlight.LightOn);
|
|
||||||
|
|
||||||
_audioSystem.PlayPvs(flashlight.ToggleSound, uid);
|
|
||||||
|
|
||||||
RaiseLocalEvent(uid, new LightToggleEvent(flashlight.LightOn), true);
|
|
||||||
_actionsSystem.SetToggled(flashlight.ToggleActionEntity, flashlight.LightOn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
namespace Content.Server.Light.Events
|
|
||||||
{
|
|
||||||
public sealed class LightToggleEvent : EntityEventArgs
|
|
||||||
{
|
|
||||||
public bool IsOn;
|
|
||||||
|
|
||||||
public LightToggleEvent(bool isOn)
|
|
||||||
{
|
|
||||||
IsOn = isOn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ using Content.Server.Chat.Managers;
|
|||||||
using Content.Server.DeviceNetwork.Components;
|
using Content.Server.DeviceNetwork.Components;
|
||||||
using Content.Server.Instruments;
|
using Content.Server.Instruments;
|
||||||
using Content.Server.Light.EntitySystems;
|
using Content.Server.Light.EntitySystems;
|
||||||
using Content.Server.Light.Events;
|
|
||||||
using Content.Server.PDA.Ringer;
|
using Content.Server.PDA.Ringer;
|
||||||
using Content.Server.Station.Systems;
|
using Content.Server.Station.Systems;
|
||||||
using Content.Server.Store.Components;
|
using Content.Server.Store.Components;
|
||||||
@@ -12,7 +11,9 @@ using Content.Server.Store.Systems;
|
|||||||
using Content.Shared.Access.Components;
|
using Content.Shared.Access.Components;
|
||||||
using Content.Shared.CartridgeLoader;
|
using Content.Shared.CartridgeLoader;
|
||||||
using Content.Shared.Chat;
|
using Content.Shared.Chat;
|
||||||
|
using Content.Shared.Light;
|
||||||
using Content.Shared.Light.Components;
|
using Content.Shared.Light.Components;
|
||||||
|
using Content.Shared.Light.EntitySystems;
|
||||||
using Content.Shared.PDA;
|
using Content.Shared.PDA;
|
||||||
using Robust.Server.Containers;
|
using Robust.Server.Containers;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
@@ -207,8 +208,9 @@ namespace Content.Server.PDA
|
|||||||
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (TryComp<UnpoweredFlashlightComponent>(uid, out var flashlight))
|
// TODO PREDICTION
|
||||||
_unpoweredFlashlight.ToggleLight(uid, flashlight);
|
// When moving this to shared, fill in the user field
|
||||||
|
_unpoweredFlashlight.TryToggleLight(uid, user: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaShowRingtoneMessage msg)
|
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaShowRingtoneMessage msg)
|
||||||
|
|||||||
@@ -68,9 +68,10 @@ public sealed class GetItemActionsEvent : EntityEventArgs
|
|||||||
AddAction(ref actionId, prototypeId, Provider);
|
AddAction(ref actionId, prototypeId, Provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddAction(EntityUid actionId)
|
public void AddAction(EntityUid? actionId)
|
||||||
{
|
{
|
||||||
Actions.Add(actionId);
|
if (actionId != null)
|
||||||
|
Actions.Add(actionId.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ using Content.Shared.Decals;
|
|||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
|
||||||
|
|
||||||
namespace Content.Shared.Light.Components;
|
namespace Content.Shared.Light.Components;
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ public sealed partial class UnpoweredFlashlightComponent : Component
|
|||||||
public SoundSpecifier ToggleSound = new SoundPathSpecifier("/Audio/Items/flashlight_pda.ogg");
|
public SoundSpecifier ToggleSound = new SoundPathSpecifier("/Audio/Items/flashlight_pda.ogg");
|
||||||
|
|
||||||
[DataField, AutoNetworkedField]
|
[DataField, AutoNetworkedField]
|
||||||
public bool LightOn = false;
|
public bool LightOn;
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
public EntProtoId ToggleAction = "ActionToggleLight";
|
public EntProtoId ToggleAction = "ActionToggleLight";
|
||||||
|
|||||||
122
Content.Shared/Light/EntitySystems/UnpoweredFlashlightSystem.cs
Normal file
122
Content.Shared/Light/EntitySystems/UnpoweredFlashlightSystem.cs
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
using Content.Shared.Actions;
|
||||||
|
using Content.Shared.Emag.Systems;
|
||||||
|
using Content.Shared.Light.Components;
|
||||||
|
using Content.Shared.Mind.Components;
|
||||||
|
using Content.Shared.Toggleable;
|
||||||
|
using Content.Shared.Verbs;
|
||||||
|
using Robust.Shared.Audio.Systems;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
|
namespace Content.Shared.Light.EntitySystems;
|
||||||
|
|
||||||
|
public sealed class UnpoweredFlashlightSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||||
|
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
||||||
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||||
|
[Dependency] private readonly SharedPointLightSystem _light = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerbs);
|
||||||
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetItemActionsEvent>(OnGetActions);
|
||||||
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, ToggleActionEvent>(OnToggleAction);
|
||||||
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, MindAddedMessage>(OnMindAdded);
|
||||||
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, GotEmaggedEvent>(OnGotEmagged);
|
||||||
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, MapInitEvent>(OnMapInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMapInit(EntityUid uid, UnpoweredFlashlightComponent component, MapInitEvent args)
|
||||||
|
{
|
||||||
|
_actionContainer.EnsureAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
||||||
|
Dirty(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnToggleAction(EntityUid uid, UnpoweredFlashlightComponent component, ToggleActionEvent args)
|
||||||
|
{
|
||||||
|
if (args.Handled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
TryToggleLight((uid, component), args.Performer);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGetActions(EntityUid uid, UnpoweredFlashlightComponent component, GetItemActionsEvent args)
|
||||||
|
{
|
||||||
|
args.AddAction(component.ToggleActionEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddToggleLightVerbs(EntityUid uid, UnpoweredFlashlightComponent component, GetVerbsEvent<ActivationVerb> args)
|
||||||
|
{
|
||||||
|
if (!args.CanAccess || !args.CanInteract)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ActivationVerb verb = new()
|
||||||
|
{
|
||||||
|
Text = Loc.GetString("toggle-flashlight-verb-get-data-text"),
|
||||||
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png")),
|
||||||
|
Act = () => TryToggleLight((uid, component), args.User),
|
||||||
|
Priority = -1 // For things like PDA's, Open-UI and other verbs that should be higher priority.
|
||||||
|
};
|
||||||
|
|
||||||
|
args.Verbs.Add(verb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMindAdded(EntityUid uid, UnpoweredFlashlightComponent component, MindAddedMessage args)
|
||||||
|
{
|
||||||
|
_actionsSystem.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGotEmagged(EntityUid uid, UnpoweredFlashlightComponent component, ref GotEmaggedEvent args)
|
||||||
|
{
|
||||||
|
if (!_light.TryGetLight(uid, out var light))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_prototypeManager.TryIndex(component.EmaggedColorsPrototype, out var possibleColors))
|
||||||
|
{
|
||||||
|
var pick = _random.Pick(possibleColors.Colors.Values);
|
||||||
|
_light.SetColor(uid, pick, light);
|
||||||
|
}
|
||||||
|
|
||||||
|
args.Repeatable = true;
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TryToggleLight(Entity<UnpoweredFlashlightComponent?> ent, EntityUid? user = null, bool quiet = false)
|
||||||
|
{
|
||||||
|
if (!Resolve(ent, ref ent.Comp, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetLight(ent, !ent.Comp.LightOn, user, quiet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetLight(Entity<UnpoweredFlashlightComponent?> ent, bool value, EntityUid? user = null, bool quiet = false)
|
||||||
|
{
|
||||||
|
if (!Resolve(ent, ref ent.Comp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ent.Comp.LightOn == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_light.TryGetLight(ent, out var light))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Dirty(ent);
|
||||||
|
ent.Comp.LightOn = value;
|
||||||
|
_light.SetEnabled(ent, value, light);
|
||||||
|
_appearance.SetData(ent, UnpoweredFlashlightVisuals.LightOn, value);
|
||||||
|
|
||||||
|
if (!quiet)
|
||||||
|
_audioSystem.PlayPredicted(ent.Comp.ToggleSound, ent, user);
|
||||||
|
|
||||||
|
_actionsSystem.SetToggled(ent.Comp.ToggleActionEntity, value);
|
||||||
|
RaiseLocalEvent(ent, new LightToggleEvent(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
6
Content.Shared/Light/LightToggleEvent.cs
Normal file
6
Content.Shared/Light/LightToggleEvent.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Content.Shared.Light;
|
||||||
|
|
||||||
|
public sealed class LightToggleEvent(bool isOn) : EntityEventArgs
|
||||||
|
{
|
||||||
|
public bool IsOn = isOn;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user