コード例 #1
0
        public override void OnStart(PartModule.StartState state)
        {
            try {
                ParseSet(componentToggles, ActuatorType.PartComponent);
                ParseSet(groupToggles, ActuatorType.PartComponentGroup);
                ParseSet(moduleToggles, ActuatorType.PartModule);
                ParseSet(textureToggles, ActuatorType.TransformTexture);
                ParseSet(shaderToggles, ActuatorType.TransformShader);
                ParseSet(numericToggles, ActuatorType.StraightParameter);
                ParseSet(controlCrewCapacity, ActuatorType.CrewCapacity);
            } catch {
                JUtil.LogErrorMessage(this, "Please check your configuration.");
                Destroy(this);
            }
            foreach (string statestring in trueFlightStates.Split(new [] { ',', '|' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var situation = (Vessel.Situations)Enum.Parse(typeof(Vessel.Situations), statestring);
                if (Enum.IsDefined(typeof(Vessel.Situations), situation))
                {
                    trueSituations.Add(situation);
                }
                else
                {
                    throw new ArgumentException("Unknown vessel situation type: " + statestring);
                }
            }

            if (state != StartState.Editor)
            {
                actuatorState = trueSituations.Contains(vessel.situation);
                LoopThroughActuators(actuatorState);
            }
        }
コード例 #2
0
        public override void OnStart(PartModule.StartState state)
        {
            trackedAnimation = part.FindModelAnimators(animationName) [0];
            if (trackedAnimation == null)
            {
                JUtil.LogErrorMessage(this, "Could not find animation named '{0}' to track.", animationName);
                Destroy(this);
            }
            // Bloody Squad and their ConfigNodes that never work properly!
            try {
                ParseSet(componentToggles, ActuatorType.PartComponent);
                ParseSet(groupToggles, ActuatorType.PartComponentGroup);
                ParseSet(moduleToggles, ActuatorType.PartModule);
                ParseSet(textureToggles, ActuatorType.TransformTexture);
                ParseSet(shaderToggles, ActuatorType.TransformShader);
                ParseSet(numericToggles, ActuatorType.StraightParameter);
                ParseSet(controlCrewCapacity, ActuatorType.CrewCapacity);
            } catch {
                JUtil.LogErrorMessage(this, "Please check your configuration.");
                Destroy(this);
            }

            actuatorState = GetAnimationState();
            LoopThroughActuators(actuatorState);
        }
コード例 #3
0
        // I might actually want to run this OnUpdate....
        public override void OnFixedUpdate()
        {
            int difference = AlterCrewCapacity(part);

            if (!warningLogged && difference != 0)
            {
                JUtil.LogErrorMessage(this, "Somehow I ended up unable to correct the Crew Capacity properly. Remaining difference: {0}", difference);
                warningLogged = true;
            }
        }
コード例 #4
0
        private void SwitchState(bool state)
        {
            part.CrewCapacity = state ? capacityWhenTrue : capacityWhenFalse;
            int difference = AlterCrewCapacity(part);

            if (difference != 0)
            {
                JUtil.LogErrorMessage(this, "Somehow I ended up unable to correct the Crew Capacity properly. Remaining difference: {0}", difference);
            }
        }
コード例 #5
0
        public override void OnStart(PartModule.StartState state)
        {
            try {
                ParseSet(componentToggles, ActuatorType.PartComponent);
                ParseSet(groupToggles, ActuatorType.PartComponentGroup);
                ParseSet(moduleToggles, ActuatorType.PartModule);
                ParseSet(textureToggles, ActuatorType.TransformTexture);
                ParseSet(shaderToggles, ActuatorType.TransformShader);
                ParseSet(numericToggles, ActuatorType.StraightParameter);
                ParseSet(managedResources, ActuatorType.Resource);
                ParseSet(controlCrewCapacity, ActuatorType.CrewCapacity);
                ParseSet(managedNodes, ActuatorType.AttachmentNode);
            } catch {
                JUtil.LogErrorMessage(this, "Please check your configuration.");
                Destroy(this);
            }

            foreach (string eventName in new [] { "JSIGuiToggleComponents", "JSIGuiEnableComponents", "JSIGuiDisableComponents" })
            {
                Events [eventName].guiActive          = activeInFlight;
                Events [eventName].guiActiveEditor    = activeInEditor;
                Events [eventName].guiActiveUnfocused = activeWhenUnfocused;
                Events [eventName].externalToEVAOnly  = externalToEVAOnly;
                Events [eventName].unfocusedRange     = unfocusedActivationRange;
            }

            if (!string.IsNullOrEmpty(enableMenuString))
            {
                Events ["JSIGuiEnableComponents"].guiName = enableMenuString;
            }
            if (!string.IsNullOrEmpty(disableMenuString))
            {
                Events ["JSIGuiDisableComponents"].guiName = disableMenuString;
            }
            if (!string.IsNullOrEmpty(toggleMenuString))
            {
                Events ["JSIGuiToggleComponents"].guiName = toggleMenuString;
            }

            if ((HighLogic.LoadedSceneIsEditor && !spawned) || (HighLogic.LoadedSceneIsFlight && !persistAfterEditor))
            {
                currentState = areComponentsEnabled;
            }

            if (currentState)
            {
                Events ["JSIGuiEnableComponents"].active = false;
            }
            else
            {
                Events ["JSIGuiDisableComponents"].active = false;
            }

            Events ["JSIGuiToggleComponents"].active &= showToggleOption;

            if (!showEnableDisableOption)
            {
                Events ["JSIGuiEnableComponents"].active  = false;
                Events ["JSIGuiDisableComponents"].active = false;
            }
            spawned = true;

            if (HighLogic.LoadedSceneIsEditor)
            {
                StartCoroutine(DelayedLoop(0.05f));
            }
            else
            {
                LoopThroughActuators(currentState);
            }
        }
コード例 #6
0
        public override void OnStart(PartModule.StartState state)
        {
            componentList = componentName.Split(new [] { ',', ' ', '|' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string componentText in componentList)
            {
                Component thatComponent = part.FindModelComponent <Component> (componentText);
                if (thatComponent == null)
                {
                    JUtil.LogErrorMessage(this, "Target part component {0} was not found in part {1}. Selfdestructing the module...", componentText, part.name);
                    Destroy(this);
                }
            }
            JUtil.LogMessage(this, "Active in part {0}, handling {1} components", part.name, componentList.Length);

            foreach (string eventName in new [] { "JSIGuiToggleComponent", "JSIGuiEnableComponent", "JSIGuiDisableComponent" })
            {
                Events [eventName].guiActive          = activeInFlight;
                Events [eventName].guiActiveEditor    = activeInEditor;
                Events [eventName].guiActiveUnfocused = activeWhenUnfocused;
                Events [eventName].externalToEVAOnly  = externalToEVAOnly;
                Events [eventName].unfocusedRange     = unfocusedActivationRange;
            }

            if (!string.IsNullOrEmpty(enableMenuString))
            {
                Events ["JSIGuiEnableComponent"].guiName = enableMenuString;
            }
            if (!string.IsNullOrEmpty(disableMenuString))
            {
                Events ["JSIGuiDisableComponent"].guiName = disableMenuString;
            }
            if (!string.IsNullOrEmpty(toggleMenuString))
            {
                Events ["JSIGuiToggleComponent"].guiName = toggleMenuString;
            }

            if ((HighLogic.LoadedSceneIsEditor && !spawned) || (HighLogic.LoadedSceneIsFlight && !persistAfterEditor))
            {
                currentState = componentIsEnabled;
            }

            if (currentState)
            {
                Events ["JSIGuiEnableComponent"].active = false;
            }
            else
            {
                Events ["JSIGuiDisableComponent"].active = false;
            }

            Events ["JSIGuiToggleComponent"].active &= showToggleOption;

            if (!showEnableDisableOption)
            {
                Events ["JSIGuiEnableComponent"].active  = false;
                Events ["JSIGuiDisableComponent"].active = false;
            }

            spawned = true;
            LoopComponents(currentState);
        }
コード例 #7
0
        public Actuator(string configData, ActuatorType creatingType, Part thatPart)
        {
            savedNodePosition = faraway;

            type = creatingType;
            string remainder;

            if (configData.StartsWith("!", StringComparison.Ordinal))
            {
                inverted  = true;
                remainder = configData.Substring(1).Trim();
            }
            else
            {
                inverted  = false;
                remainder = configData;
            }

            string[] tokens = remainder.Split(',');
            switch (type)
            {
            case ActuatorType.PartComponent:
                moduleID = remainder;
                JUtil.LogMessage(this, "Controlling PartComponent with moduleID {0}, {1}", moduleID, inverted ? "inverted" : "regular");
                break;

            case ActuatorType.PartComponentGroup:
                moduleID = remainder;
                JUtil.LogMessage(this, "Controlling PartComponentGroup with groupID {0}, {1}", moduleID, inverted ? "inverted" : "regular");
                break;

            case ActuatorType.PartModule:
                int moduleIndex  = int.Parse(remainder.Split(',') [1]);
                var thoseModules = new List <PartModule> ();
                foreach (PartModule thatModule in thatPart.Modules)
                {
                    if (thatModule.ClassName == tokens [0].Trim())
                    {
                        thoseModules.Add(thatModule);
                    }
                }
                if (moduleIndex < thoseModules.Count)
                {
                    controlledModule = thoseModules [moduleIndex];
                }
                else
                {
                    JUtil.LogErrorMessage(this, "Could not find PartModule named {2} number {0} in part {1}", moduleIndex, thatPart.name, tokens [0].Trim());
                }
                JUtil.LogMessage(this, "Controlling PartModule named {0}, {1}", controlledModule.ClassName, inverted ? "inverted" : "regular");
                break;

            case ActuatorType.TransformTexture:

                if (tokens.Length == 3 || tokens.Length == 4)
                {
                    targetTransform = thatPart.FindModelTransform(tokens [0].Trim());
                    if (targetTransform == null)
                    {
                        throw new ArgumentException("Could not find model transform.");
                    }
                    if (GameDatabase.Instance.ExistsTexture(tokens [1].Trim()) && GameDatabase.Instance.ExistsTexture(tokens [2].Trim()))
                    {
                        falseString = tokens [1].Trim();
                        trueString  = tokens [2].Trim();
                        JUtil.LogMessage(this, "Controlling texture on transform '{0}', {1}", tokens [0].Trim(), inverted ? "inverted" : "regular");
                    }
                    else
                    {
                        throw new ArgumentException("Textures not found.");
                    }
                    if (tokens.Length == 4)
                    {
                        textureLayer = tokens [3].Trim();
                    }
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.TransformShader:
                if (tokens.Length == 3)
                {
                    targetTransform = thatPart.FindModelTransform(tokens [0].Trim());
                    if (targetTransform == null)
                    {
                        throw new ArgumentException("Could not find model transform.");
                    }
                    if (Shader.Find(tokens [1].Trim()) && Shader.Find(tokens [2].Trim()))
                    {
                        falseString = tokens [1].Trim();
                        trueString  = tokens [2].Trim();
                        JUtil.LogMessage(this, "Controlling shader on transform '{0}', {1}", tokens [0].Trim(), inverted ? "inverted" : "regular");
                    }
                    else
                    {
                        throw new ArgumentException("Shaders not found.");
                    }
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.StraightParameter:
                if (tokens.Length == 2)
                {
                    if (float.TryParse(tokens [1], out addToParameterWhenEnabled))
                    {
                        if (Array.IndexOf(knownStraightParameters, tokens [0].Trim()) >= 0)
                        {
                            nameOfParameter        = tokens [0].Trim();
                            originalParameterValue = GetParameter(nameOfParameter, thatPart);
                            JUtil.LogMessage(this, "Controlling parameter '{0}' on part {1}, {2}", nameOfParameter, thatPart.partName, inverted ? "inverted" : "regular");
                        }
                        else
                        {
                            throw new ArgumentException("Bad arguments, unknown straight parameter " + tokens [0]);
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Bad argument, maxTemp must be a float.");
                    }
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.Resource:
                if (tokens.Length == 2)
                {
                    if (float.TryParse(tokens [1], out maxAmount))
                    {
                        bool found = false;
                        resourceName = tokens [0].Trim();
                        foreach (PartResourceDefinition thatResource in PartResourceLibrary.Instance.resourceDefinitions)
                        {
                            found |= thatResource.name == resourceName;
                        }
                        if (!found)
                        {
                            throw new ArgumentException("Bad resource name.");
                        }
                        JUtil.LogMessage(this, "Controlling resource tank for resource {0} in part {1}, {2}", resourceName, thatPart.partName, inverted ? "inverted" : "regular");
                    }
                    else
                    {
                        throw new ArgumentException("Bad resource amount.");
                    }
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.CrewCapacity:
                if (tokens.Length == 1)
                {
                    switch (tokens [0].ToLowerInvariant())
                    {
                    case "regular":
                        inverted = false;
                        break;

                    case "inverted":
                        inverted = true;
                        break;

                    default:
                        throw new ArgumentException("I need a 'regular' or 'inverted' here.");
                    }
                    JUtil.LogMessage(this, "Controlling crew capacity in part {0}, {1}", thatPart.partName, inverted ? "inverted" : "regular");
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.AttachmentNode:
                if (tokens.Length == 1)
                {
                    nodeName = tokens [0].Trim();
                    var foundNode = thatPart.findAttachNode(nodeName);
                    if (foundNode == null)
                    {
                        throw new ArgumentException("Node not found.");
                    }
                    savedNodePosition = foundNode.position;
                    JUtil.LogMessage(this, "Managing attach node in part {0}, node name {1}, {2}", thatPart.partName, nodeName, inverted ? "inverted" : "regular");
                }
                else
                {
                    throw new ArgumentException("Node name missing.");
                }
                break;
            }
        }