Refactor AdvertiseComponent to be ECS, improve performance. (#4676)

This commit is contained in:
Vera Aguilera Puerto
2021-09-23 18:02:22 +02:00
committed by GitHub
parent c4ec9a143d
commit 08184bc928
3 changed files with 156 additions and 130 deletions

View File

@@ -52,6 +52,8 @@ namespace Content.Server.VendingMachines
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(VendingMachineUiKey.Key);
public bool Broken => _broken;
void IActivate.Activate(ActivateEventArgs eventArgs)
{
if(!eventArgs.User.TryGetComponent(out ActorComponent? actor))
@@ -129,18 +131,6 @@ namespace Content.Server.VendingMachines
{
var state = args.Powered ? VendingMachineVisualState.Normal : VendingMachineVisualState.Off;
TrySetVisualState(state);
// Pause/resume advertising if advertising component exists and not broken
if (!Owner.TryGetComponent(out AdvertiseComponent? advertiseComponent) || _broken) return;
if (Powered)
{
advertiseComponent.Resume();
}
else
{
advertiseComponent.Pause();
}
}
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
@@ -250,11 +240,6 @@ namespace Content.Server.VendingMachines
{
_broken = true;
TrySetVisualState(VendingMachineVisualState.Broken);
if (Owner.TryGetComponent(out AdvertiseComponent? advertiseComponent))
{
advertiseComponent.Pause();
}
}
public enum Wires