Fix power sensor looking at wrong electrical network (#40934)
* Fix power sensor looking at wrong electrical network if it happened to be connected * Remove unnecessary loop in power sensor logic
This commit is contained in:
@@ -98,28 +98,19 @@ public sealed class PowerSensorSystem : EntitySystem
|
|||||||
var nodeContainer = Comp<NodeContainerComponent>(uid);
|
var nodeContainer = Comp<NodeContainerComponent>(uid);
|
||||||
var deviceNode = (CableDeviceNode) nodeContainer.Nodes[cable.Node];
|
var deviceNode = (CableDeviceNode) nodeContainer.Nodes[cable.Node];
|
||||||
|
|
||||||
var charge = 0f;
|
|
||||||
var chargingState = false;
|
|
||||||
var dischargingState = false;
|
|
||||||
|
|
||||||
// update state based on the power stats retrieved from the selected power network
|
// update state based on the power stats retrieved from the selected power network
|
||||||
var xform = _xformQuery.GetComponent(uid);
|
var xform = _xformQuery.GetComponent(uid);
|
||||||
if (!TryComp(xform.GridUid, out MapGridComponent? grid))
|
if (!TryComp(xform.GridUid, out MapGridComponent? grid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var cables = deviceNode.GetReachableNodes(xform, _nodeQuery, _xformQuery, grid, EntityManager);
|
if (deviceNode.NodeGroup == null)
|
||||||
foreach (var node in cables)
|
return;
|
||||||
{
|
|
||||||
if (node.NodeGroup == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var group = (IBasePowerNet) node.NodeGroup;
|
var group = (IBasePowerNet) deviceNode.NodeGroup;
|
||||||
var stats = _powerNet.GetNetworkStatistics(group.NetworkNode);
|
var stats = _powerNet.GetNetworkStatistics(group.NetworkNode);
|
||||||
charge = comp.Output ? stats.OutStorageCurrent : stats.InStorageCurrent;
|
var charge = comp.Output ? stats.OutStorageCurrent : stats.InStorageCurrent;
|
||||||
chargingState = charge > comp.LastCharge;
|
var chargingState = charge > comp.LastCharge;
|
||||||
dischargingState = charge < comp.LastCharge;
|
var dischargingState = charge < comp.LastCharge;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
comp.LastCharge = charge;
|
comp.LastCharge = charge;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user