Merge remote-tracking branch 'upstream/master' into 20-10-30-admins
This commit is contained in:
@@ -7,12 +7,14 @@ using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -41,6 +43,11 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
[ViewVariables(VVAccess.ReadWrite)] public string? TurnOnFailSound;
|
||||
[ViewVariables(VVAccess.ReadWrite)] public string? TurnOffSound;
|
||||
|
||||
/// <summary>
|
||||
/// Client-side ItemStatus level
|
||||
/// </summary>
|
||||
private byte? _lastLevel;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -190,24 +197,34 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
}
|
||||
|
||||
if (Activated && !Cell.TryUseCharge(Wattage * frameTime)) TurnOff(false);
|
||||
Dirty();
|
||||
|
||||
var level = GetLevel();
|
||||
|
||||
if (level != _lastLevel)
|
||||
{
|
||||
_lastLevel = level;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
// Curently every single flashlight has the same number of levels for status and that's all it uses the charge for
|
||||
// Thus we'll just check if the level changes.
|
||||
private byte? GetLevel()
|
||||
{
|
||||
if (Cell == null)
|
||||
return null;
|
||||
|
||||
var currentCharge = Cell.CurrentCharge;
|
||||
|
||||
if (MathHelper.CloseTo(currentCharge, 0) || Wattage > currentCharge)
|
||||
return 0;
|
||||
|
||||
return (byte?) ContentHelpers.RoundToNearestLevels(currentCharge / Cell.MaxCharge * 255, 255, StatusLevels);
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
if (Cell == null)
|
||||
{
|
||||
return new HandheldLightComponentState(null, false);
|
||||
}
|
||||
|
||||
if (Wattage > Cell.CurrentCharge)
|
||||
{
|
||||
// Practically zero.
|
||||
// This is so the item status works correctly.
|
||||
return new HandheldLightComponentState(0, HasCell);
|
||||
}
|
||||
|
||||
return new HandheldLightComponentState(Cell.CurrentCharge / Cell.MaxCharge, HasCell);
|
||||
return new HandheldLightComponentState(GetLevel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
{
|
||||
public interface ISignalReceiver
|
||||
{
|
||||
void TriggerSignal(SignalState state);
|
||||
}
|
||||
using System;
|
||||
|
||||
public enum SignalState
|
||||
namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
{
|
||||
public interface ISignalReceiver<in T>
|
||||
{
|
||||
On,
|
||||
Off,
|
||||
Toggle
|
||||
void TriggerSignal(T signal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Server.GameObjects.Components.MachineLinking.Signals;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -29,7 +30,7 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
return;
|
||||
}
|
||||
|
||||
if (transmitter.TransmitSignal(user, SignalState.Toggle))
|
||||
if (transmitter.TransmitSignal(user, new ToggleSignal()))
|
||||
{
|
||||
// Since the button doesn't have an animation, I'm going to use a popup message
|
||||
Owner.PopupMessage(user, Loc.GetString("Click."));
|
||||
|
||||
@@ -26,9 +26,9 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
_transmitters = new List<SignalTransmitterComponent>();
|
||||
}
|
||||
|
||||
public void DistributeSignal(SignalState state)
|
||||
public void DistributeSignal<T>(T state)
|
||||
{
|
||||
foreach (var comp in Owner.GetAllComponents<ISignalReceiver>())
|
||||
foreach (var comp in Owner.GetAllComponents<ISignalReceiver<T>>())
|
||||
{
|
||||
comp.TriggerSignal(state);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
return;
|
||||
}
|
||||
|
||||
transmitter.TransmitSignal(user, _on ? SignalState.On : SignalState.Off);
|
||||
transmitter.TransmitSignal(user, _on);
|
||||
}
|
||||
|
||||
private void UpdateSprite()
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
}
|
||||
}
|
||||
|
||||
public bool TransmitSignal(IEntity user, SignalState state)
|
||||
public bool TransmitSignal<T>(IEntity user, T signal)
|
||||
{
|
||||
if (_receivers.Count == 0)
|
||||
{
|
||||
@@ -102,7 +102,7 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
continue;
|
||||
}
|
||||
|
||||
receiver.DistributeSignal(state);
|
||||
receiver.DistributeSignal(signal);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace Content.Server.GameObjects.Components.MachineLinking.Signals
|
||||
{
|
||||
public struct ToggleSignal {}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.Components.MachineLinking;
|
||||
using Content.Server.GameObjects.Components.MachineLinking.Signals;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
@@ -28,7 +29,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
/// Component that represents a wall light. It has a light bulb that can be replaced when broken.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class PoweredLightComponent : Component, IInteractHand, IInteractUsing, IMapInit, ISignalReceiver
|
||||
public class PoweredLightComponent : Component, IInteractHand, IInteractUsing, IMapInit, ISignalReceiver<bool>, ISignalReceiver<ToggleSignal>
|
||||
{
|
||||
[Dependency] private IGameTiming _gameTiming = default!;
|
||||
|
||||
@@ -62,23 +63,6 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
return InsertBulb(eventArgs.Using);
|
||||
}
|
||||
|
||||
public void TriggerSignal(SignalState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case SignalState.On:
|
||||
_on = true;
|
||||
break;
|
||||
case SignalState.Off:
|
||||
_on = false;
|
||||
break;
|
||||
case SignalState.Toggle:
|
||||
_on = !_on;
|
||||
break;
|
||||
}
|
||||
UpdateLight();
|
||||
}
|
||||
|
||||
public bool InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out IDamageableComponent damageableComponent))
|
||||
@@ -252,5 +236,17 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
var entity = Owner.EntityManager.SpawnEntity(prototype, Owner.Transform.Coordinates);
|
||||
_lightBulbContainer.Insert(entity);
|
||||
}
|
||||
|
||||
public void TriggerSignal(bool signal)
|
||||
{
|
||||
_on = signal;
|
||||
UpdateLight();
|
||||
}
|
||||
|
||||
public void TriggerSignal(ToggleSignal signal)
|
||||
{
|
||||
_on = !_on;
|
||||
UpdateLight();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -45,10 +46,15 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
appearance.SetData(PowerCellVisuals.ChargeLevel, CurrentCharge / MaxCharge);
|
||||
appearance.SetData(PowerCellVisuals.ChargeLevel, GetLevel(CurrentCharge / MaxCharge));
|
||||
}
|
||||
}
|
||||
|
||||
private byte GetLevel(float fraction)
|
||||
{
|
||||
return (byte) ContentHelpers.RoundToNearestLevels(fraction, 1, SharedPowerCell.PowerCellVisualsLevels);
|
||||
}
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if(inDetailsRange)
|
||||
|
||||
Reference in New Issue
Block a user