public void RemoveAlert(ServerAlertsComponent status)
        {
            var grid = status.Owner.Transform.GridID;

            if (!_alerts.TryGetValue(grid, out var statuses))
            {
                return;
            }

            statuses.Remove(status);
        }
Esempio n. 2
0
        public void ShowAlerts()
        {
            // this is kind of unnecessary because there's integration test coverage of Alert components
            // but wanted to keep it anyway to see what's possible w.r.t. testing components
            // in a unit test

            var prototypeManager = IoCManager.Resolve <IPrototypeManager>();

            prototypeManager.RegisterType(typeof(AlertPrototype));
            var factory = IoCManager.Resolve <IComponentFactory>();

            factory.Register <ServerAlertsComponent>();
            prototypeManager.LoadFromStream(new StringReader(PROTOTYPES));
            prototypeManager.Resync();
            var alertManager = IoCManager.Resolve <AlertManager>();

            alertManager.Initialize();


            var alertsComponent = new ServerAlertsComponent();

            alertsComponent = IoCManager.InjectDependencies(alertsComponent);

            Assert.That(alertManager.TryGetWithEncoded(AlertType.LowPressure, out var lowpressure, out var lpencoded));
            Assert.That(alertManager.TryGetWithEncoded(AlertType.HighPressure, out var highpressure, out var hpencoded));

            alertsComponent.ShowAlert(AlertType.LowPressure);
            var alertState = alertsComponent.GetComponentState() as AlertsComponentState;

            Assert.NotNull(alertState);
            Assert.That(alertState.Alerts.Length, Is.EqualTo(1));
            Assert.That(alertState.Alerts[0], Is.EqualTo(new AlertState {
                AlertEncoded = lpencoded
            }));

            alertsComponent.ShowAlert(AlertType.HighPressure);
            alertState = alertsComponent.GetComponentState() as AlertsComponentState;
            Assert.That(alertState.Alerts.Length, Is.EqualTo(1));
            Assert.That(alertState.Alerts[0], Is.EqualTo(new AlertState {
                AlertEncoded = hpencoded
            }));

            alertsComponent.ClearAlertCategory(AlertCategory.Pressure);
            alertState = alertsComponent.GetComponentState() as AlertsComponentState;
            Assert.That(alertState.Alerts.Length, Is.EqualTo(0));
        }
        public void AddAlert(ServerAlertsComponent status)
        {
            var gridId = status.Owner.Transform.GridID;
            var alerts = _alerts.GetOrNew(gridId);

            alerts.Add(status);

            if (_mapManager.TryGetGrid(status.Owner.Transform.GridID, out var grid))
            {
                if (grid.HasGravity)
                {
                    RemoveWeightless(status);
                }
                else
                {
                    AddWeightless(status);
                }
            }
        }
 private void RemoveWeightless(ServerAlertsComponent status)
 {
     status.ClearAlert(AlertType.Weightless);
 }
 private void AddWeightless(ServerAlertsComponent status)
 {
     status.ShowAlert(AlertType.Weightless);
 }