Fix AME node updating to fix exceptions.
And also make it run less poorly, I guess.
This commit is contained in:
@@ -27,7 +27,6 @@ namespace Content.Client.AME.UI
|
|||||||
_window.ToggleInjection.OnPressed += _ => ButtonPressed(UiButton.ToggleInjection);
|
_window.ToggleInjection.OnPressed += _ => ButtonPressed(UiButton.ToggleInjection);
|
||||||
_window.IncreaseFuelButton.OnPressed += _ => ButtonPressed(UiButton.IncreaseFuel);
|
_window.IncreaseFuelButton.OnPressed += _ => ButtonPressed(UiButton.IncreaseFuel);
|
||||||
_window.DecreaseFuelButton.OnPressed += _ => ButtonPressed(UiButton.DecreaseFuel);
|
_window.DecreaseFuelButton.OnPressed += _ => ButtonPressed(UiButton.DecreaseFuel);
|
||||||
_window.RefreshPartsButton.OnPressed += _ => ButtonPressed(UiButton.RefreshParts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ namespace Content.Client.AME.UI
|
|||||||
public Button ToggleInjection { get; set; }
|
public Button ToggleInjection { get; set; }
|
||||||
public Button IncreaseFuelButton { get; set; }
|
public Button IncreaseFuelButton { get; set; }
|
||||||
public Button DecreaseFuelButton { get; set; }
|
public Button DecreaseFuelButton { get; set; }
|
||||||
public Button RefreshPartsButton { get; set; }
|
|
||||||
public ProgressBar? FuelMeter { get; set; }
|
public ProgressBar? FuelMeter { get; set; }
|
||||||
public Label FuelAmount { get; set; }
|
public Label FuelAmount { get; set; }
|
||||||
public Label InjectionAmount { get; set; }
|
public Label InjectionAmount { get; set; }
|
||||||
@@ -85,7 +84,6 @@ namespace Content.Client.AME.UI
|
|||||||
{
|
{
|
||||||
Children =
|
Children =
|
||||||
{
|
{
|
||||||
(RefreshPartsButton = new Button {Text = Loc.GetString("ame-window-refresh-parts-button"), StyleClasses = {StyleBase.ButtonOpenBoth }, Disabled = true }),
|
|
||||||
new Label { Text = Loc.GetString("ame-window-core-count-label")},
|
new Label { Text = Loc.GetString("ame-window-core-count-label")},
|
||||||
(CoreCount = new Label { Text = "0"}),
|
(CoreCount = new Label { Text = "0"}),
|
||||||
}
|
}
|
||||||
@@ -159,8 +157,6 @@ namespace Content.Client.AME.UI
|
|||||||
InjectionStatus.Text = Loc.GetString("ame-window-engine-injection-status-injecting-label");
|
InjectionStatus.Text = Loc.GetString("ame-window-engine-injection-status-injecting-label");
|
||||||
}
|
}
|
||||||
|
|
||||||
RefreshPartsButton.Disabled = castState.Injecting;
|
|
||||||
|
|
||||||
CoreCount.Text = $"{castState.CoreCount}";
|
CoreCount.Text = $"{castState.CoreCount}";
|
||||||
InjectionAmount.Text = $"{castState.InjectionAmount}";
|
InjectionAmount.Text = $"{castState.InjectionAmount}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,64 +41,38 @@ namespace Content.Server.AME
|
|||||||
{
|
{
|
||||||
base.LoadNodes(groupNodes);
|
base.LoadNodes(groupNodes);
|
||||||
|
|
||||||
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||||
|
var grid = mapManager.GetGrid(GridId);
|
||||||
|
|
||||||
foreach (var node in groupNodes)
|
foreach (var node in groupNodes)
|
||||||
{
|
{
|
||||||
if (node.Owner.TryGetComponent(out AMEControllerComponent? controller))
|
var nodeOwner = node.Owner;
|
||||||
|
if (nodeOwner.TryGetComponent(out AMEControllerComponent? controller))
|
||||||
{
|
{
|
||||||
_masterController = controller;
|
_masterController = controller;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void RemoveNode(Node node)
|
if (nodeOwner.TryGetComponent(out AMEShieldComponent? shield))
|
||||||
{
|
|
||||||
base.RemoveNode(node);
|
|
||||||
|
|
||||||
RefreshAMENodes(_masterController);
|
|
||||||
if (_masterController != null && _masterController?.Owner == node.Owner) { _masterController = null; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RefreshAMENodes(AMEControllerComponent? controller)
|
|
||||||
{
|
|
||||||
if(_masterController == null && controller != null)
|
|
||||||
{
|
|
||||||
_masterController = controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (AMEShieldComponent core in _cores)
|
|
||||||
{
|
|
||||||
core.UnsetCore();
|
|
||||||
}
|
|
||||||
_cores.Clear();
|
|
||||||
|
|
||||||
//Check each shield node to see if it meets core criteria
|
|
||||||
foreach (Node node in Nodes)
|
|
||||||
{
|
|
||||||
var nodeOwner = node.Owner;
|
|
||||||
if (!nodeOwner.TryGetComponent<AMEShieldComponent>(out var shield)) { continue; }
|
|
||||||
|
|
||||||
var grid = IoCManager.Resolve<IMapManager>().GetGrid(nodeOwner.Transform.GridID);
|
|
||||||
var nodeNeighbors = grid.GetCellsInSquareArea(nodeOwner.Transform.Coordinates, 1)
|
|
||||||
.Select(sgc => nodeOwner.EntityManager.GetEntity(sgc))
|
|
||||||
.Where(entity => entity != nodeOwner)
|
|
||||||
.Select(entity => entity.TryGetComponent<AMEShieldComponent>(out var adjshield) ? adjshield : null)
|
|
||||||
.Where(adjshield => adjshield != null);
|
|
||||||
|
|
||||||
if (nodeNeighbors.Count() >= 8)
|
|
||||||
{
|
{
|
||||||
_cores.Add(shield);
|
var nodeNeighbors = grid.GetCellsInSquareArea(nodeOwner.Transform.Coordinates, 1)
|
||||||
}
|
.Select(sgc => nodeOwner.EntityManager.GetEntity(sgc))
|
||||||
}
|
.Where(entity => entity != nodeOwner && entity.HasComponent<AMEShieldComponent>());
|
||||||
|
|
||||||
foreach (AMEShieldComponent core in _cores)
|
if (nodeNeighbors.Count() >= 8)
|
||||||
{
|
{
|
||||||
core.SetCore();
|
_cores.Add(shield);
|
||||||
|
shield.SetCore();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shield.UnsetCore();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateCoreVisuals(int injectionAmount, bool injecting)
|
public void UpdateCoreVisuals(int injectionAmount, bool injecting)
|
||||||
{
|
{
|
||||||
|
|
||||||
var injectionStrength = CoreCount > 0 ? injectionAmount / CoreCount : 0;
|
var injectionStrength = CoreCount > 0 ? injectionAmount / CoreCount : 0;
|
||||||
|
|
||||||
foreach (AMEShieldComponent core in _cores)
|
foreach (AMEShieldComponent core in _cores)
|
||||||
|
|||||||
@@ -212,9 +212,6 @@ namespace Content.Server.AME.Components
|
|||||||
case UiButton.DecreaseFuel:
|
case UiButton.DecreaseFuel:
|
||||||
InjectionAmount = InjectionAmount > 0 ? InjectionAmount -= 2 : 0;
|
InjectionAmount = InjectionAmount > 0 ? InjectionAmount -= 2 : 0;
|
||||||
break;
|
break;
|
||||||
case UiButton.RefreshParts:
|
|
||||||
RefreshParts();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GetAMENodeGroup()?.UpdateCoreVisuals(InjectionAmount, _injecting);
|
GetAMENodeGroup()?.UpdateCoreVisuals(InjectionAmount, _injecting);
|
||||||
@@ -277,12 +274,6 @@ namespace Content.Server.AME.Components
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshParts()
|
|
||||||
{
|
|
||||||
GetAMENodeGroup()?.RefreshAMENodes(this);
|
|
||||||
UpdateUserInterface();
|
|
||||||
}
|
|
||||||
|
|
||||||
private AMENodeGroup? GetAMENodeGroup()
|
private AMENodeGroup? GetAMENodeGroup()
|
||||||
{
|
{
|
||||||
Owner.TryGetComponent(out NodeContainerComponent? nodeContainer);
|
Owner.TryGetComponent(out NodeContainerComponent? nodeContainer);
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ namespace Content.Shared.AME
|
|||||||
ToggleInjection,
|
ToggleInjection,
|
||||||
IncreaseFuel,
|
IncreaseFuel,
|
||||||
DecreaseFuel,
|
DecreaseFuel,
|
||||||
RefreshParts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
Reference in New Issue
Block a user