Skip to content

Commit

Permalink
Pow3r: stage 1 (#4208)
Browse files Browse the repository at this point in the history
Co-authored-by: 20kdc <[email protected]>
  • Loading branch information
PJB3005 and 20kdc authored Jul 4, 2021
1 parent ea60a81 commit 103bc19
Show file tree
Hide file tree
Showing 212 changed files with 8,580 additions and 4,422 deletions.
2 changes: 2 additions & 0 deletions Content.Client/Content.Client.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=power_005Cvisualizers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
1 change: 1 addition & 0 deletions Content.Client/Doors/AirlockVisualizer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Content.Client.Wires;
using Content.Client.Wires.Visualizers;
using Content.Shared.Audio;
using Content.Shared.Doors;
using JetBrains.Annotations;
Expand Down
10 changes: 6 additions & 4 deletions Content.Client/Entry/IgnoredComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static class IgnoredComponents
"AccessReader",
"IdCardConsole",
"Airlock",
"WirePlacer",
"CablePlacer",
"Drink",
"Food",
"FoodContainer",
Expand All @@ -73,6 +73,7 @@ public static class IgnoredComponents
"StorageFill",
"Mop",
"Bucket",
"CableVis",
"Puddle",
"CanSpill",
"SpeedLoader",
Expand Down Expand Up @@ -105,12 +106,11 @@ public static class IgnoredComponents
"PowerSupplier",
"PowerConsumer",
"Battery",
"BatteryStorage",
"BatteryDischarger",
"Apc",
"PowerProvider",
"PowerReceiver",
"Wire",
"ApcPowerReceiver",
"Cable",
"StressTestMovement",
"Toys",
"SurgeryTool",
Expand Down Expand Up @@ -273,6 +273,8 @@ public static class IgnoredComponents
"ExplosionLaunched",
"BeingCloned",
"Advertise",
"PowerNetworkBattery",
"BatteryCharger",
};
}
}
23 changes: 23 additions & 0 deletions Content.Client/Light/Visualizers/EmergencyLightVisualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Content.Shared.Light.Component;
using Robust.Client.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Content.Client.Light.Visualizers
{
[DataDefinition]
public sealed class EmergencyLightVisualizer : AppearanceVisualizer
{
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);

if (!component.Owner.TryGetComponent(out SpriteComponent? sprite))
return;

if (!component.TryGetData(EmergencyLightVisuals.On, out bool on))
on = false;

sprite.LayerSetState(0, on ? "emergency_light_on" : "emergency_light_off");
}
}
}
99 changes: 99 additions & 0 deletions Content.Client/NodeContainer/NodeGroupSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Collections.Generic;
using System.Linq;
using Content.Shared.NodeContainer;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.ResourceManagement;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;

namespace Content.Client.NodeContainer
{
[UsedImplicitly]
public sealed class NodeGroupSystem : EntitySystem
{
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly IEntityLookup _entityLookup = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;

public bool VisEnabled { get; private set; }

public Dictionary<int, NodeVis.GroupData> Groups { get; } = new();
public HashSet<string> Filtered { get; } = new();

public Dictionary<EntityUid, (NodeVis.GroupData group, NodeVis.NodeDatum node)[]>
Entities { get; private set; } = new();

public Dictionary<(int group, int node), NodeVis.NodeDatum> NodeLookup { get; private set; } = new();

public override void Initialize()
{
base.Initialize();

SubscribeNetworkEvent<NodeVis.MsgData>(DataMsgHandler);
}

public override void Shutdown()
{
base.Shutdown();

_overlayManager.RemoveOverlay<NodeVisualizationOverlay>();
}

private void DataMsgHandler(NodeVis.MsgData ev)
{
if (!VisEnabled)
return;

foreach (var deletion in ev.GroupDeletions)
{
Groups.Remove(deletion);
}

foreach (var group in ev.Groups)
{
Groups.Add(group.NetId, group);
}

Entities = Groups.Values
.SelectMany(g => g.Nodes, (data, nodeData) => (data, nodeData))
.GroupBy(n => n.nodeData.Entity)
.ToDictionary(g => g.Key, g => g.ToArray());

NodeLookup = Groups.Values
.SelectMany(g => g.Nodes, (data, nodeData) => (data, nodeData))
.ToDictionary(n => (n.data.NetId, n.nodeData.NetId), n => n.nodeData);
}

public void SetVisEnabled(bool enabled)
{
VisEnabled = enabled;

RaiseNetworkEvent(new NodeVis.MsgEnable(enabled));

if (enabled)
{
var overlay = new NodeVisualizationOverlay(
this,
_entityLookup,
_mapManager,
_inputManager,
_eyeManager,
_resourceCache,
EntityManager);

_overlayManager.AddOverlay(overlay);
}
else
{
Groups.Clear();
Entities.Clear();
}
}
}
}
56 changes: 56 additions & 0 deletions Content.Client/NodeContainer/NodeVisCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Content.Client.Administration.Managers;
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;

namespace Content.Client.NodeContainer
{
public sealed class NodeVisCommand : IConsoleCommand
{
public string Command => "nodevis";
public string Description => "Toggles node group visualization";
public string Help => "";

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var adminMan = IoCManager.Resolve<IClientAdminManager>();
if (!adminMan.HasFlag(AdminFlags.Debug))
{
shell.WriteError("You need +DEBUG for this command");
return;
}

var sys = EntitySystem.Get<NodeGroupSystem>();
sys.SetVisEnabled(!sys.VisEnabled);
}
}

public sealed class NodeVisFilterCommand : IConsoleCommand
{
public string Command => "nodevisfilter";
public string Description => "Toggles showing a specific group on nodevis";
public string Help => "Usage: nodevis [filter]\nOmit filter to list currently masked-off";

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var sys = EntitySystem.Get<NodeGroupSystem>();

if (args.Length == 0)
{
foreach (var filtered in sys.Filtered)
{
shell.WriteLine(filtered);
}
}
else
{
var filter = args[0];
if (!sys.Filtered.Add(filter))
{
sys.Filtered.Remove(filter);
}
}
}
}
}
Loading

0 comments on commit 103bc19

Please sign in to comment.