public void OnUpdate() { var newState = CalcChargeState(); if (newState != LastChargeState) { LastChargeState = newState; Appearance.SetData(ApcVisuals.ChargeState, newState); } var newCharge = Storage.Charge; if (newCharge != _lastCharge) { _lastCharge = newCharge; _uiDirty = true; } var extPowerState = CalcExtPowerState(); if (extPowerState != _lastExternalPowerState) { _lastExternalPowerState = extPowerState; _uiDirty = true; } if (_uiDirty) { _userInterface.SetState(new ApcBoundInterfaceState(_provider.MainBreaker, extPowerState, newCharge / Storage.Capacity)); _uiDirty = false; } }
public void Update() { var newState = CalcChargeState(); if (newState != _lastChargeState && _lastChargeStateChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) { _lastChargeState = newState; _lastChargeStateChange = _gameTiming.CurTime; _appearance.SetData(ApcVisuals.ChargeState, newState); } var newCharge = Battery.CurrentCharge; if (newCharge != _lastCharge && _lastChargeChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) { _lastCharge = newCharge; _lastChargeChange = _gameTiming.CurTime; _uiDirty = true; } var extPowerState = CalcExtPowerState(); if (extPowerState != _lastExternalPowerState && _lastExternalPowerStateChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) { _lastExternalPowerState = extPowerState; _lastExternalPowerStateChange = _gameTiming.CurTime; _uiDirty = true; } if (_uiDirty) { _userInterface.SetState(new ApcBoundInterfaceState(MainBreakerEnabled, extPowerState, newCharge / Battery.MaxCharge)); _uiDirty = false; } }
public override void Update(float frameTime) { var newState = CalcChargeState(); if (newState != LastChargeState) { LastChargeState = newState; Appearance.SetData(ApcVisuals.ChargeState, newState); } }
public void Update() { var newState = CalcChargeState(); if (newState != _lastChargeState && _lastChargeStateChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) { _lastChargeState = newState; _lastChargeStateChange = _gameTiming.CurTime; if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) { appearance.SetData(ApcVisuals.ChargeState, newState); } if (_entMan.TryGetComponent(Owner, out SharedPointLightComponent? light)) { light.Color = newState switch { ApcChargeState.Lack => LackColor, ApcChargeState.Charging => ChargingColor, ApcChargeState.Full => FullColor, _ => LackColor }; light.Dirty(); } } _entMan.TryGetComponent(Owner, out BatteryComponent? battery); var newCharge = battery?.CurrentCharge; if (newCharge != null && newCharge != _lastCharge && _lastChargeChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) { _lastCharge = newCharge.Value; _lastChargeChange = _gameTiming.CurTime; _uiDirty = true; } var extPowerState = CalcExtPowerState(); if (extPowerState != _lastExternalPowerState && _lastExternalPowerStateChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) { _lastExternalPowerState = extPowerState; _lastExternalPowerStateChange = _gameTiming.CurTime; _uiDirty = true; } if (_uiDirty && battery != null && newCharge != null) { UserInterface?.SetState(new ApcBoundInterfaceState(MainBreakerEnabled, extPowerState, newCharge.Value / battery.MaxCharge)); _uiDirty = false; } }