private void ArmGrapple(int index, TextMenu.Item ti)
        {
            ModuleGrappleNode thatClaw = null;

            foreach (PartModule thatModule in vessel.GetReferenceTransformPart().Modules)
            {
                thatClaw = thatModule as ModuleGrappleNode;
                if (thatClaw != null)
                {
                    break;
                }
            }

            if (thatClaw != null)
            {
                try
                {
                    ModuleAnimateGeneric clawAnimation = (vessel.GetReferenceTransformPart().Modules[thatClaw.deployAnimationController] as ModuleAnimateGeneric);
                    if (clawAnimation != null)
                    {
                        clawAnimation.Toggle();
                    }
                }
                catch (Exception e)
                {
                    JUtil.LogErrorMessage(this, "Exception trying to arm/disarm Grapple Node: {0}", e.Message);
                }
            }
        }
示例#2
0
        public void Start()
        {
            string[] tokens = scale.Split(',');

            if (tokens.Length == 2)
            {
                //comp = RasterPropMonitorComputer.Instantiate(internalProp);
                scaleEnds[0] = new VariableOrNumber(tokens[0], this);
                scaleEnds[1] = new VariableOrNumber(tokens[1], this);
                scaleEnds[2] = new VariableOrNumber(variableName, this);

                textIn  = JUtil.LoadPageDefinition(definitionIn);
                textOut = JUtil.LoadPageDefinition(definitionOut);

                float min = Mathf.Min(threshold.x, threshold.y);
                float max = Mathf.Max(threshold.x, threshold.y);
                threshold.x = min;
                threshold.y = max;

                persistence = new PersistenceAccessor(internalProp);
            }
            else
            {
                JUtil.LogErrorMessage(this, "Could not parse the 'scale' parameter: {0}", scale);
            }
        }
 /// <summary>
 /// Initializes the stores strings list.  If the list is already
 /// initialized, it instead validates that the new array matches the
 /// existing array.
 /// </summary>
 /// <param name="stringsArray"></param>
 internal void SetStoredStrings(string[] stringsArray)
 {
     if (stringsArray.Length > 0)
     {
         if (storedStrings.Count == 0)
         {
             for (int i = 0; i < stringsArray.Length; ++i)
             {
                 storedStrings.Add(stringsArray[i]);
             }
         }
         else
         {
             // We've already initialized this array.  Let's warn if we
             // are getting conflicting values.
             if (stringsArray.Length != storedStrings.Count)
             {
                 JUtil.LogErrorMessage(this, "Attempt to re-initialize storedStrings with a different-sized array was ignored.");
             }
             else
             {
                 for (int i = 0; i < stringsArray.Length; ++i)
                 {
                     if (storedStrings[i] != stringsArray[i])
                     {
                         JUtil.LogErrorMessage(this, "Attempt to re-initialize storedStrings with a different values was ignored.");
                         return;
                     }
                 }
             }
         }
     }
 }
示例#4
0
        public static string ProcessString(string input, RasterPropMonitorComputer rpmComp)
        {
            try
            {
                if (input.IndexOf(JUtil.VariableListSeparator[0], StringComparison.Ordinal) >= 0)
                {
                    string[] tokens = input.Split(JUtil.VariableListSeparator, StringSplitOptions.RemoveEmptyEntries);
                    if (tokens.Length != 2)
                    {
                        return("FORMAT ERROR");
                    }
                    else
                    {
                        RPMVesselComputer comp = RPMVesselComputer.Instance(rpmComp.vessel);
                        string[]          vars = tokens[1].Split(JUtil.VariableSeparator, StringSplitOptions.RemoveEmptyEntries);

                        var variables = new object[vars.Length];
                        for (int i = 0; i < vars.Length; i++)
                        {
                            variables[i] = rpmComp.ProcessVariable(vars[i].Trim(), comp);
                        }
                        string output = string.Format(fp, tokens[0], variables);
                        return(output.TrimEnd());
                    }
                }
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(rpmComp, "Bad format on string {0}: {1}", input, e);
            }

            return(input.TrimEnd());
        }
示例#5
0
        public void Configure(ConfigNode node)
        {
            ConfigNode[] pages = node.GetNodes("PAGE_DEFINITION");

            if (pages != null && pages.Length > 0)
            {
                definitions = new PageDefinition[pages.Length];

                for (int i = 0; i < pages.Length; ++i)
                {
                    string variableName = pages[i].GetValue("variableName");
                    string range        = pages[i].GetValue("range");
                    string page         = pages[i].GetValue("page");
                    if (string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(range) || string.IsNullOrEmpty(page))
                    {
                        JUtil.LogErrorMessage(this, "Incorrect page definition for page {0}", i);
                        definitions = null;
                        if (string.IsNullOrEmpty(definitionIn))
                        {
                            // Make sure we aren't crashing later.
                            definitionIn = definitionOut;
                        }
                        return;
                    }
                    definitions[i] = new PageDefinition(variableName, range, page);
                }
            }
        }
示例#6
0
        /// <summary>
        /// Is the current reference dock docked to something?
        /// </summary>
        /// <returns></returns>
        public bool DockDocked()
        {
            try
            {
                if (vessel == null)
                {
                    return(false);
                }

                ModuleDockingNode node = InferDockingNode(vessel);
                if (node != null)
                {
                    // Urk.  No enums or numerics to test state...
                    return(!string.IsNullOrEmpty(node.state) && (node.state == "Docked (docker)") || (node.state == "Docked (dockee)"));
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(this, "Exception in DockDocked: {0}", e);
            }
            return(false);
        }
示例#7
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

            lastOrientation = navBall.rotation;

            if (string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(range))
            {
                JUtil.LogErrorMessage(this, "variableName or range was null!");
                return;
            }
            string[] tokens = range.Split(',');
            if (tokens.Length != 2)
            {
                JUtil.LogErrorMessage(this, "range '{0}' did not have exactly two values!", range);
                return;
            }

            enablingVariable = new VariableOrNumberRange(rpmComp, variableName, tokens[0], tokens[1]);
        }
示例#8
0
        /// <summary>
        /// Is the current reference dock ready?
        /// </summary>
        /// <returns></returns>
        public bool DockReady()
        {
            try
            {
                if (vessel == null)
                {
                    return(false);
                }

                ModuleDockingNode node = InferDockingNode(vessel);
                if (node != null)
                {
                    // Urk.  No enums or numerics to test state...
                    return(node.state == "Ready");
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(this, "Exception in DockDocked: {0}", e);
            }
            return(false);
        }
        private static Texture2D LoadFont(object caller, InternalProp thisProp, string location)
        {
            Texture2D font = null;

            if (!string.IsNullOrEmpty(location))
            {
                try
                {
                    if (GameDatabase.Instance.ExistsTexture(location.EnforceSlashes()))
                    {
                        font = GameDatabase.Instance.GetTexture(location.EnforceSlashes(), false);
                        JUtil.LogMessage(caller, "Loading font texture from URL \"{0}\"", location);
                    }
                    else
                    {
                        font = (Texture2D)thisProp.FindModelTransform(location).GetComponent <Renderer>().material.mainTexture;
                        JUtil.LogMessage(caller, "Loading font texture from a transform named \"{0}\"", location);
                    }
                }
                catch (Exception)
                {
                    JUtil.LogErrorMessage(caller, "Failed loading font texture \"{0}\" - missing texture?", location);
                }
            }
            return(font);
        }
示例#10
0
        public void Start()
        {
            if (string.IsNullOrEmpty(hatchTransform))
            {
                JUtil.LogMessage(this, "Where's my transform?");
                return;
            }
            Transform actualTransform;

            if (internalProp == null)
            {
                actualTransform = internalModel.FindModelTransform(hatchTransform);
                if (!string.IsNullOrEmpty(internalAnimation))
                {
                    intAnim = internalModel.FindModelAnimators(internalAnimation)[0];
                }
            }
            else
            {
                actualTransform = internalProp.FindModelTransform(hatchTransform);
                if (!string.IsNullOrEmpty(internalAnimation))
                {
                    intAnim = internalProp.FindModelAnimators(internalAnimation)[0];
                }
            }
            if (!string.IsNullOrEmpty(internalAnimation) && intAnim == null)
            {
                JUtil.LogErrorMessage(this, "Animation name was not found.");
            }
            // Switching to using the stock button class because right now SmarterButton can't correctly handle doubleclick.
            InternalButton.Create(actualTransform.gameObject).OnDoubleTap(new InternalButton.InternalButtonDelegate(EVAClick));
        }
示例#11
0
        static JSIChatterer()
        {
            try
            {
                var loadedChattererAssy = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name == "Chatterer");

                if (loadedChattererAssy == null)
                {
                    chattererFound = false;

                    return;
                }

                //--- Process all the reflection info
                // MechJebCore
                chatterer_t = loadedChattererAssy.assembly.GetExportedTypes()
                              .SingleOrDefault(t => t.FullName == "Chatterer.chatterer");
                if (chatterer_t == null)
                {
                    JUtil.LogErrorMessage(null, "Did not find Chatterer.chatterer");
                    return;
                }

                MethodInfo txMethod = chatterer_t.GetMethod("VesselIsTransmitting", BindingFlags.Instance | BindingFlags.Public);
                if (txMethod == null)
                {
                    throw new NotImplementedException("txMethod");
                }
                chattererTx = DynamicMethodDelegateFactory.CreateFuncBool(txMethod);

                MethodInfo rxMethod = chatterer_t.GetMethod("VesselIsReceiving", BindingFlags.Instance | BindingFlags.Public);
                if (rxMethod == null)
                {
                    throw new NotImplementedException("rxMethod");
                }
                chattererRx = DynamicMethodDelegateFactory.CreateFuncBool(rxMethod);

                MethodInfo chatterMethod = chatterer_t.GetMethod("InitiateChatter", BindingFlags.Instance | BindingFlags.Public);
                if (chatterMethod == null)
                {
                    throw new NotImplementedException("chatterMethod");
                }
                chattererStartTalking = DynamicMethodDelegateFactory.CreateAction(chatterMethod);
            }
            catch (Exception e)
            {
                chatterer_t = null;
                JUtil.LogMessage(null, "Exception initializing JSIChatterer: {0}", e);
            }

            if (chatterer_t != null && chattererStartTalking != null)
            {
                chattererFound = true;
            }
            else
            {
                chattererFound = false;
            }
        }
示例#12
0
        public object ListElement(string resourceName, string valueType, bool stage)
        {
            double v = 0.0;

            try
            {
                ResourceData resource = nameResources[resourceName];

                switch (valueType)
                {
                case "":
                case "VAL":
                    v = stage ? resource.stage : resource.current;
                    break;

                case "DENSITY":
                    v = resource.density;
                    break;

                case "DELTA":
                    v = resource.delta;
                    break;

                case "DELTAINV":
                    v = -resource.delta;
                    break;

                case "MASS":
                    v = resource.density * (stage ? resource.stage : resource.current);
                    break;

                case "MAXMASS":
                    v = resource.density * (stage ? resource.stagemax : resource.max);
                    break;

                case "MAX":
                    v = stage ? resource.stagemax : resource.max;
                    break;

                case "PERCENT":
                    if (stage)
                    {
                        v = resource.stagemax > 0 ? resource.stage / resource.stagemax : 0d;
                    }
                    else
                    {
                        v = resource.max > 0 ? resource.current / resource.max : 0d;
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(this, "Error finding {0}-{2}: {1}", resourceName, e, valueType);
            }

            return(v);
        }
        public void SetSASMode(double mode)
        {
            int imode = (int)mode;

            VesselAutopilot.AutopilotMode autopilotMode;
            switch (imode)
            {
            case 0:
                autopilotMode = VesselAutopilot.AutopilotMode.StabilityAssist;
                break;

            case 1:
                autopilotMode = VesselAutopilot.AutopilotMode.Prograde;
                break;

            case 2:
                autopilotMode = VesselAutopilot.AutopilotMode.Retrograde;
                break;

            case 3:
                autopilotMode = VesselAutopilot.AutopilotMode.Normal;
                break;

            case 4:
                autopilotMode = VesselAutopilot.AutopilotMode.Antinormal;
                break;

            case 5:
                autopilotMode = VesselAutopilot.AutopilotMode.RadialIn;
                break;

            case 6:
                autopilotMode = VesselAutopilot.AutopilotMode.RadialOut;
                break;

            case 7:
                autopilotMode = VesselAutopilot.AutopilotMode.Target;
                break;

            case 8:
                autopilotMode = VesselAutopilot.AutopilotMode.AntiTarget;
                break;

            case 9:
                autopilotMode = VesselAutopilot.AutopilotMode.Maneuver;
                break;

            default:
                JUtil.LogErrorMessage(this, "SetSASMode: attempt to set a SAS mode with the invalid value {0}", imode);
                return;
            }

            if (vessel != null && vessel.Autopilot.CanSetMode(autopilotMode))
            {
                vessel.Autopilot.SetMode(autopilotMode);
                ForceUpdateSASModeToggleButtons(autopilotMode);
            }
        }
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            try
            {
                rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

                if (string.IsNullOrEmpty(layout))
                {
                    throw new ArgumentNullException("layout");
                }

                foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("RPM_GRAPHING_BACKGROUND"))
                {
                    if (node.GetValue("layout") == layout)
                    {
                        if (!node.HasValue("backgroundColor"))
                        {
                            JUtil.LogErrorMessage(this, "?!? no backgroundColor");
                        }
                        string s = node.GetValue("backgroundColor");
                        if (string.IsNullOrEmpty(s))
                        {
                            JUtil.LogErrorMessage(this, "backgroundColor is missing?");
                        }
                        backgroundColorValue = ConfigNode.ParseColor32(node.GetValue("backgroundColor"));

                        ConfigNode[] dataNodes = node.GetNodes("DATA_SET");

                        for (int i = 0; i < dataNodes.Length; i++)
                        {
                            try
                            {
                                dataSets.Add(new DataSet(dataNodes[i], rpmComp));
                            }
                            catch (ArgumentException e)
                            {
                                JUtil.LogErrorMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
                                throw;
                            }
                        }
                        break;
                    }
                }

                startupComplete = true;
            }

            catch
            {
                JUtil.AnnoyUser(this);
                throw;
            }
        }
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            try
            {
                ConfigNode moduleConfig = null;
                foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP"))
                {
                    if (node.GetValue("name") == internalProp.propName)
                    {
                        if (string.IsNullOrEmpty(variableName))
                        {
                            JUtil.LogErrorMessage(this, "Configuration failed in prop {0} ({1}), no variableName.", internalProp.propID, internalProp.propName);
                            throw new ArgumentNullException();
                        }

                        moduleConfig = node.GetNodes("MODULE")[moduleID];
                        ConfigNode[] variableNodes = moduleConfig.GetNodes("VARIABLESET");

                        for (int i = 0; i < variableNodes.Length; i++)
                        {
                            try
                            {
                                variableSets.Add(new CallbackAnimationSet(variableNodes[i], variableName, internalProp));
                            }
                            catch (ArgumentException e)
                            {
                                JUtil.LogErrorMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
                            }
                        }
                        break;
                    }
                }


                RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
                del = (Action <RPMVesselComputer, float>)Delegate.CreateDelegate(typeof(Action <RPMVesselComputer, float>), this, "OnCallback");
                float value = comp.ProcessVariable(variableName).MassageToFloat();
                for (int i = 0; i < variableSets.Count; ++i)
                {
                    variableSets[i].Update(comp, value);
                }
                comp.RegisterCallback(variableName, del);
                JUtil.LogMessage(this, "Configuration complete in prop {1} ({2}), supporting {0} callback animators.", variableSets.Count, internalProp.propID, internalProp.propName);
            }
            catch
            {
                JUtil.AnnoyUser(this);
                enabled = false;
                throw;
            }
        }
示例#16
0
            private static bool InstantiateHandler(ConfigNode node, Part ourPart, out Func <string, object> handlerFunction)
            {
                handlerFunction = null;
                var handlerConfiguration = new ConfigNode("MODULE");

                node.CopyTo(handlerConfiguration);
                string moduleName = node.GetValue("name");
                string methodName = node.GetValue("method");

                // Since we're working with part modules here, and starting in a pod config,
                // we'll keep one instance per pod, which will let them instantiate with their own config if needed.
                MonoBehaviour thatModule = null;

                foreach (PartModule potentialModule in ourPart.Modules)
                {
                    if (potentialModule.ClassName == moduleName)
                    {
                        thatModule = potentialModule;
                        break;
                    }
                }
                if (thatModule == null)
                {
                    try
                    {
                        thatModule = ourPart.AddModule(handlerConfiguration);
                    }
                    catch
                    {
                        JUtil.LogErrorMessage(null, "Caught exception when trying to instantiate module '{0}'. Something's fishy here", moduleName);
                    }
                }
                if (thatModule == null)
                {
                    JUtil.LogMessage(null, "Warning, variable handler module \"{0}\" could not be loaded. This could be perfectly normal.", moduleName);
                    return(false);
                }
                foreach (MethodInfo m in thatModule.GetType().GetMethods())
                {
                    if (m.Name == node.GetValue("method"))
                    {
                        try
                        {
                            handlerFunction = (Func <string, object>)Delegate.CreateDelegate(typeof(Func <string, object>), thatModule, m);
                        }
                        catch
                        {
                            JUtil.LogErrorMessage(null, "Error, incorrect variable handler configuration for module {0}", moduleName);
                            return(false);
                        }
                        break;
                    }
                }
                return(true);
            }
示例#17
0
        public void Start()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            bool startedOkay = true;

            for (int i = 0; i < part.Modules.Count; ++i)
            {
                if (part.Modules[i] is MultiModeEngine)
                {
                    if (mmeIndex == -1)
                    {
                        mmeIndex = i;
                        JUtil.LogMessage(this, "Start(): mmeIndex = {0}", i);
                    }
                    else
                    {
                        JUtil.LogErrorMessage(this, "Found more than one MultiModeEngine on {0} - I don't know what to do with it.", part.name);
                        startedOkay = false;
                    }
                }
                else if (part.Modules[i] is ModuleEngines)
                {
                    if (engineMode1Index == -1)
                    {
                        engineMode1Index = i;
                        JUtil.LogMessage(this, "Start(): engineMode1Index = {0}", i);
                    }
                    else if (engineMode2Index == -1)
                    {
                        engineMode2Index = i;
                        JUtil.LogMessage(this, "Start(): engineMode2Index = {0}", i);
                    }
                    else
                    {
                        JUtil.LogErrorMessage(this, "Found more than 2 ModuleEngines on {0} - I don't know what to do with them.", part.name);
                        startedOkay = false;
                    }
                }
            }

            if (engineMode1Index == -1 || !startedOkay)
            {
                JUtil.LogErrorMessage(this, "Unable to initialize - no ModuleEngine, or too many engines");
                Destroy(this);
                // No engines!
            }
            else
            {
                UpdateName();
            }
        }
示例#18
0
        /// <summary>
        /// Update the text mesh if it's changed.
        /// </summary>
        public void Update()
        {
            if (!string.IsNullOrEmpty(text_))
            {
                if (invalidated)
                {
                    if (font_ == null)
                    {
                        if (!fontNag)
                        {
                            JUtil.LogErrorMessage(this, "Font was not initialized");
                            JUtil.AnnoyUser(this);
                            fontNag = true;
                        }
                        return;
                    }

                    if (text_.Contains("["))
                    {
                        richText = true;
                        GenerateRichText();
                    }
                    else
                    {
                        richText = false;
                        GenerateText();
                    }

                    invalidated      = false;
                    invalidatedColor = false;
                }
                else if (invalidatedColor)
                {
                    if (richText)
                    {
                        GenerateRichText();
                    }
                    else
                    {
                        if (meshFilter_.mesh.colors32.Length > 0)
                        {
                            Color32[] newColor = new Color32[meshFilter_.mesh.colors32.Length];
                            for (int idx = 0; idx < newColor.Length; ++idx)
                            {
                                newColor[idx] = color_;
                            }
                            meshFilter_.mesh.colors32 = newColor;
                            meshFilter_.mesh.UploadMeshData(false);
                        }
                    }

                    invalidatedColor = false;
                }
            }
        }
示例#19
0
        internal int GetVar(string persistentVarName)
        {
            try
            {
                return(persistentVars[persistentVarName]);
            }
            catch
            {
                JUtil.LogErrorMessage(this, "Someone called GetVar({0}) without making sure the value existed", persistentVarName);
            }

            return(int.MinValue);
        }
示例#20
0
 public void Add(PartResource resource)
 {
     try
     {
         ResourceData res = Array.Find(rs, t => t.name == resource.info.name);
         res.current += (float)resource.amount;
         res.max     += (float)resource.maxAmount;
     }
     catch (Exception e)
     {
         JUtil.LogErrorMessage(this, "Error adding {0}: {1}", resource.info.name, e);
     }
 }
示例#21
0
 public void SetActive(Vessel.ActiveResource resource)
 {
     try
     {
         ResourceData res = Array.Find(rs, t => t.name == resource.info.name);
         res.stage    = (float)resource.amount;
         res.stagemax = (float)resource.maxAmount;
     }
     catch (Exception e)
     {
         JUtil.LogErrorMessage(this, "Error SetActive {0}: {1}", resource.info.name, e);
     }
 }
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            try
            {
                rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

                Transform textObjTransform = internalProp.FindModelTransform(transformName);
                textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform, "", Color.green, false, "TopLeft");
                // Force oneshot if there's no variables:
                oneshot |= !labelText.Contains("$&$");
                string sourceString = labelText.UnMangleConfigText();

                if (!string.IsNullOrEmpty(sourceString) && sourceString.Length > 1)
                {
                    // Alow a " character to escape leading whitespace
                    if (sourceString[0] == '"')
                    {
                        sourceString = sourceString.Substring(1);
                    }
                }
                spf = new StringProcessorFormatter(sourceString, rpmComp);

                if (!oneshot)
                {
                    rpmComp.UpdateDataRefreshRate(refreshRate);
                }

                if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor)))
                {
                    positiveColorValue = JUtil.ParseColor32(positiveColor, part, ref rpmComp);
                    negativeColorValue = JUtil.ParseColor32(negativeColor, part, ref rpmComp);
                    zeroColorValue     = JUtil.ParseColor32(zeroColor, part, ref rpmComp);
                    del = (Action <float>)Delegate.CreateDelegate(typeof(Action <float>), this, "OnCallback");
                    rpmComp.RegisterVariableCallback(variableName, del);
                    registeredVessel = vessel.id;

                    // Initialize the text color. Actually, callback registration took care of that
                }
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(this, "Start failed with exception {0}", e);
                spf = new StringProcessorFormatter("x", rpmComp);
            }
        }
示例#23
0
        /// <summary>
        /// Infers the docking node this vessel controls
        /// </summary>
        /// <param name="vessel"></param>
        /// <returns></returns>
        private static ModuleDockingNode InferDockingNode(Vessel vessel)
        {
            RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
            Part compPart          = comp.ReferencePart;
            uint launchId;

            if (compPart == null)
            {
                launchId = 0u;
            }
            else
            {
                launchId = compPart.launchID;
            }

            ModuleDockingNode node = null;
            Part referencePart     = vessel.GetReferenceTransformPart();

            if (referencePart != null)
            {
                node = referencePart.FindModuleImplementing <ModuleDockingNode>();
                if (node != null)
                {
                    //JUtil.LogMessage(vessel, "InferDockingNode: using reference part {0}", referencePart.name);
                    // The current reference part is a docking node.
                    return(node);
                }
            }
            else
            {
                JUtil.LogErrorMessage(vessel, "referencePart is null?");
            }

            for (int i = 0; i < vessel.parts.Count; ++i)
            {
                if (vessel.parts[i].launchID == launchId)
                {
                    node = vessel.parts[i].FindModuleImplementing <ModuleDockingNode>();
                    if (node != null)
                    {
                        //JUtil.LogMessage(vessel, "InferDockingNode: found a node on {0}", vessel.parts[i].name);
                        return(node);
                    }
                }
            }

            // We did not find a docking node.
            return(null);
        }
示例#24
0
 public void MarkPropellant(Propellant propel)
 {
     foreach (PartResource resource in propel.connectedResources)
     {
         try
         {
             ResourceData r = Array.Find(rs, t => t.name == resource.info.name);
             r.ispropellant = true;
         }
         catch (Exception e)
         {
             JUtil.LogErrorMessage(this, "Error in MarkPropellant({0}): {1}", resource.info.name, e);
         }
     }
 }
示例#25
0
        /// <summary>
        /// Set the named persistent variable to the value provided.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="broadcast">Broadcast the request to other parts of the same craft?</param>
        internal void SetPersistentVariable(string name, object value, bool broadcast)
        {
            if (name.Trim().Length == 0)
            {
                JUtil.LogErrorMessage(this, "Trying to set an empty variable name!");
                return;
            }
            persistentVars[name] = value;

            if (broadcast)
            {
                RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
                comp.SetPersistentVariable(name, value);
            }
        }
示例#26
0
        public static void PatchMaterial()
        {
            if (ranPatch)
            {
                return;
            }
            ranPatch = true;

            try
            {
                var scansatAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(assembly => assembly.name == "SCANsat");

                // no scansat, nothing to do
                if (scansatAssembly == null)
                {
                    return;
                }

                var jutil_t = scansatAssembly.assembly.GetExportedTypes().SingleOrDefault(t => t.FullName == "SCANsat.JUtil");

                // can't find the type? weird...
                if (jutil_t == null)
                {
                    JUtil.LogErrorMessage("scansat", "no jutil type found");
                    return;
                }

                var lineMatFieldInfo = jutil_t.GetField("LineMat");

                if (lineMatFieldInfo == null)
                {
                    JUtil.LogErrorMessage("scansat", "unable to find LineMat field info; valid fields are {0}",
                                          string.Join(", ", jutil_t.GetFields().Select(field => field.Name)));
                    return;
                }

                var lineMaterial = new Material(Shader.Find("KSP/Particles/Alpha Blended"));
                lineMaterial.hideFlags        = HideFlags.HideAndDontSave;
                lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;

                lineMatFieldInfo.SetValue(null, lineMaterial);
                JUtil.LogMessage("scansat", "patched linematerial");
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage("scansat", e.Message);
            }
        }
示例#27
0
        public void Start()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            for (int i = 0; i < part.Modules.Count; ++i)
            {
                if (part.Modules[i] is MultiModeEngine)
                {
                    if (mmeIndex == -1)
                    {
                        mmeIndex = i;
                        JUtil.LogMessage(this, "Start(): mmeIndex = {0}", i);
                    }
                    else
                    {
                        JUtil.LogErrorMessage(this, "Found more than one MultiModeEngine on {0} - I don't know what to do with it.", part.name);
                    }
                }
                else if (part.Modules[i] is ModuleEngines)
                {
                    if (engineMode1Index == -1)
                    {
                        engineMode1Index = i;
                        JUtil.LogMessage(this, "Start(): engineMode1Index = {0}", i);
                    }
                    else if (engineMode2Index == -1)
                    {
                        engineMode2Index = i;
                        JUtil.LogMessage(this, "Start(): engineMode2Index = {0}", i);
                    }
                    else
                    {
                        JUtil.LogErrorMessage(this, "Found more than 2 ModuleEngines on {0} - I don't know what to do with them.", part.name);
                    }
                }
            }

            if (engineMode1Index == -1)
            {
                Destroy(this);
                // No engines!
            }
            UpdateName();
        }
示例#28
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

            if (string.IsNullOrEmpty(definitionIn) && definitions != null)
            {
                for (int i = 0; i < definitions.Length; ++i)
                {
                    string[] varrange = definitions[i].range.Split(',');
                    range.Add(new VariableOrNumberRange(rpmComp, definitions[i].variableName, varrange[0], varrange[1]));
                    text.Add(JUtil.LoadPageDefinition(definitions[i].page));
                }
                definitions = null;
                initialized = true;
            }
            else
            {
                string[] tokens = scale.Split(',');

                if (tokens.Length == 2)
                {
                    legacyRange = new VariableOrNumberRange(rpmComp, variableName, tokens[0], tokens[1]);

                    float min = Mathf.Min(threshold.x, threshold.y);
                    float max = Mathf.Max(threshold.x, threshold.y);
                    threshold.x = min;
                    threshold.y = max;

                    text.Add(JUtil.LoadPageDefinition(definitionIn));

                    initialized = true;
                }
                else
                {
                    JUtil.LogErrorMessage(this, "Could not parse the 'scale' parameter: {0}", scale);
                }
            }

            text.Add(JUtil.LoadPageDefinition(definitionOut));
        }
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            try
            {
                backgroundColorValue = ConfigNode.ParseColor32(backgroundColor);

                cameraBody                 = new GameObject();
                cameraBody.name            = "RPMPFD" + cameraBody.GetInstanceID();
                cameraBody.layer           = drawingLayer;
                hudCamera                  = cameraBody.AddComponent <Camera>();
                hudCamera.enabled          = false;
                hudCamera.orthographic     = true;
                hudCamera.eventMask        = 0;
                hudCamera.farClipPlane     = 3f;
                hudCamera.orthographicSize = 1.0f;
                hudCamera.cullingMask      = 1 << drawingLayer;
                // does this actually work?
                hudCamera.backgroundColor      = backgroundColorValue;
                hudCamera.clearFlags           = CameraClearFlags.Depth | CameraClearFlags.Color;
                hudCamera.transparencySortMode = TransparencySortMode.Orthographic;
                hudCamera.transform.position   = Vector3.zero;
                hudCamera.transform.LookAt(new Vector3(0.0f, 0.0f, 1.5f), Vector3.up);

                if (!string.IsNullOrEmpty(progradeColor))
                {
                    progradeColorValue = ConfigNode.ParseColor32(progradeColor);
                }

                persistence = new PersistenceAccessor(internalProp);
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(this, "Start() failed with an exception: {0}", e);
                JUtil.AnnoyUser(this);
                throw;
            }

            startupComplete = true;
        }
示例#30
0
 /// <summary>
 /// Set the named persistent variable to the value provided.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="value"></param>
 internal void SetPersistentVariable(string name, object value)
 {
     try
     {
         if (name.Trim().Length == 0)
         {
             JUtil.LogErrorMessage(this, "Trying to set an empty variable name!");
             return;
         }
         persistentVars[name] = value;
         //JUtil.LogMessage(this, "Setting persistent var {0} to {1}", name, value);
     }
     catch
     {
         // Not needed?  Looks like the assignment will add the value.
         persistentVars.Add(name, value);
         //JUtil.LogMessage(this, "Adding persistent var {0} as {1}", name, value);
     }
 }