Beispiel #1
0
            public void Update(double time)
            {
                double value = variable.AsDouble();

                if (double.IsNaN(value) || double.IsInfinity(value))
                {
                    return;
                }
                points.Add(new Vector2d(time, value));
                if (points.Count > maxPoints)
                {
                    points.RemoveRange(0, points.Count - maxPoints);
                }
            }
Beispiel #2
0
        public void Click()
        {
            bool switchEnabled = true;

            if (!forcedShutdown)
            {
                if (perPodMasterSwitchValid)
                {
                    switchEnabled = rpmComp.GetPersistentVariable(perPodMasterSwitchName, false, false);
                }
                if (masterVariable != null)
                {
                    switchEnabled = masterVariable.IsInRange();
                }
            }
            if (!switchEnabled)
            {
                // If the master switch is 'off' and we're not here because
                // of a forced shutdown, don't allow this switch to work.
                // early return
                return;
            }

            if (isCustomAction)
            {
                if (switchGroupIdentifier >= 0)
                {
                    if (!forcedShutdown && !customGroupState)
                    {
                        customGroupState = true;
                        if (persistentVarValid)
                        {
                            rpmComp.SetPersistentVariable(persistentVarName, switchGroupIdentifier, perPodPersistenceIsGlobal);
                        }
                    }
                    // else: can't turn off a radio group switch.
                }
                else if (customAction == CustomActions.Plugin && stateVariable != null)
                {
                    int ivalue = stateVariable.AsInt();
                    customGroupState = (ivalue < 1) && !forcedShutdown;
                }
                else
                {
                    customGroupState = !customGroupState;
                    if (persistentVarValid)
                    {
                        rpmComp.SetPersistentVariable(persistentVarName, customGroupState, perPodPersistenceIsGlobal);
                    }
                }
            }
            else
            {
                vessel.ActionGroups.ToggleGroup(kspAction);
            }

            // Now we do extra things that with regular actions can't happen.
            switch (customAction)
            {
            case CustomActions.IntLight:
                SetInternalLights(customGroupState);
                break;

            case CustomActions.Plugin:
                actionHandler(customGroupState);
                break;

            case CustomActions.Stage:
                if (InputLockManager.IsUnlocked(ControlTypes.STAGING))
                {
                    StageManager.ActivateNextStage();
                }
                break;

            case CustomActions.TransferToPersistent:
                if (stateVariable != null)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = stateVariable.AsInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                float getValue = transferGetter.AsFloat();
                rpmComp.SetPersistentVariable(transferPersistentName, getValue, false);
                break;

            case CustomActions.TransferFromPersistent:
                if (stateVariable != null)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = stateVariable.AsInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                if (rpmComp.HasPersistentVariable(transferPersistentName, false))
                {
                    transferSetter(rpmComp.GetPersistentVariable(transferPersistentName, 0.0, false).MassageToDouble());
                }
                break;

            case CustomActions.TransferFromVariable:
                if (stateVariable != null)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = stateVariable.AsInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                double xferValue = transferGetter.AsDouble();
                transferSetter(xferValue);
                break;
            }
        }