コード例 #1
0
ファイル: KethaneExtractor.cs プロジェクト: Jaidan/Kethane
        public override void OnLoad(ConfigNode config)
        {
            if (this.config == null)
            {
                this.config = new ConfigNode();
                config.CopyTo(this.config);
            }

            resources = this.config.GetNodes("Resource").Select(n => new Resource(n)).ToList();
        }
コード例 #2
0
ファイル: KIS_Shared.cs プロジェクト: Amorymeltzer/KIS
        public static Part CreatePart(ConfigNode partConfig, Vector3 position, Quaternion rotation, Part fromPart, Part coupleToPart = null, string srcAttachNodeID = null, AttachNode tgtAttachNode = null, OnPartCoupled onPartCoupled = null)
        {
            ConfigNode node_copy = new ConfigNode();
            partConfig.CopyTo(node_copy);
            ProtoPartSnapshot snapshot = new ProtoPartSnapshot(node_copy, null, HighLogic.CurrentGame);

            if (HighLogic.CurrentGame.flightState.ContainsFlightID(snapshot.flightID) || snapshot.flightID == 0)
            {
                snapshot.flightID = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);
            }
            snapshot.parentIdx = 0;
            snapshot.position = position;
            snapshot.rotation = rotation;
            snapshot.stageIndex = 0;
            snapshot.defaultInverseStage = 0;
            snapshot.seqOverride = -1;
            snapshot.inStageIndex = -1;
            snapshot.attachMode = (int)AttachModes.SRF_ATTACH;
            snapshot.attached = true;
            snapshot.connected = true;
            snapshot.flagURL = fromPart.flagURL;

            Part newPart = snapshot.Load(fromPart.vessel, false);

            newPart.transform.position = position;
            newPart.transform.rotation = rotation;
            newPart.missionID = fromPart.missionID;

            fromPart.vessel.Parts.Add(newPart);

            newPart.physicalSignificance = Part.PhysicalSignificance.NONE;
            newPart.PromoteToPhysicalPart();
            newPart.Unpack();
            newPart.InitializeModules();

            if (coupleToPart)
            {
                newPart.rigidbody.velocity = coupleToPart.rigidbody.velocity;
                newPart.rigidbody.angularVelocity = coupleToPart.rigidbody.angularVelocity;
            }
            else
            {
                if (fromPart.rigidbody)
                {
                    newPart.rigidbody.velocity = fromPart.rigidbody.velocity;
                    newPart.rigidbody.angularVelocity = fromPart.rigidbody.angularVelocity;
                }
                else
                {
                    // If fromPart is a carried container
                    newPart.rigidbody.velocity = fromPart.vessel.rootPart.rigidbody.velocity;
                    newPart.rigidbody.angularVelocity = fromPart.vessel.rootPart.rigidbody.angularVelocity;
                }
            }

            newPart.decouple();

            if (coupleToPart)
            {
                newPart.StartCoroutine(WaitAndCouple(newPart, coupleToPart, srcAttachNodeID, tgtAttachNode, onPartCoupled));
            }
            else
            {
                newPart.vessel.vesselType = VesselType.Unknown;
                //name container
                ModuleKISInventory inv = newPart.GetComponent<ModuleKISInventory>();
                if (inv)
                {
                    if (inv.invName != "")
                    {
                        newPart.vessel.vesselName = inv.part.partInfo.title + " | " + inv.invName;
                    }
                    else
                    {
                        newPart.vessel.vesselName = inv.part.partInfo.title;
                    }
                }
            }
            return newPart;
        }
コード例 #3
0
ファイル: KAS_Shared.cs プロジェクト: ACCBizon/KAS
        public static Part LoadPartSnapshot(Vessel vessel, ConfigNode node, Vector3 position, Quaternion rotation)
        {
            ConfigNode node_copy = new ConfigNode();
            node.CopyTo(node_copy);

            node_copy.RemoveValues("kas_total_mass");

            ProtoPartSnapshot snapshot = new ProtoPartSnapshot(node_copy, null, HighLogic.CurrentGame);

            if (HighLogic.CurrentGame.flightState.ContainsFlightID(snapshot.flightID))
                snapshot.flightID = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);

            snapshot.parentIdx = 0;
            snapshot.position = position;
            snapshot.rotation = rotation;
            snapshot.stageIndex = 0;
            snapshot.defaultInverseStage = 0;
            snapshot.seqOverride = -1;
            snapshot.inStageIndex = -1;
            snapshot.attachMode = (int)AttachModes.SRF_ATTACH;
            snapshot.attached = true;
            snapshot.connected = true;
            snapshot.flagURL = vessel.rootPart.flagURL;

            // Save properties that may be messed up by new colliders
            RigidbodyInertia rb_backup = new RigidbodyInertia(vessel.rootPart.rb);

            Part new_part = snapshot.Load(vessel, false);

            vessel.Parts.Add(new_part);

            if (vessel.packed)
            {
                GameEvents.onVesselWasModified.Fire(vessel);
            }
            else
            {
                // Request initialization as nonphysical to prevent explosions
                new_part.physicalSignificance = Part.PhysicalSignificance.NONE;

                // Disable all sub-objects with colliders
                List<Collider> re_enable = new List<Collider>();

                foreach (var collider in new_part.GetComponentsInChildren<Collider>())
                {
                    if (collider.gameObject.activeSelf)
                    {
                        re_enable.Add(collider);
                        collider.gameObject.SetActive(false);
                    }
                }

                new_part.StartCoroutine(WaitAndUnpack(new_part, re_enable));
            }

            rb_backup.Restore(vessel.rootPart.rb);

            return new_part;
        }
コード例 #4
0
        /// <summary>
        /// Merges global and local config nodes for an engine layout<para/>
        /// Local node values have priority if they are present; any non-specified local values are defaulted
        /// to the global value
        /// </summary>
        /// <param name="global"></param>
        /// <param name="local"></param>
        /// <returns></returns>
        private ConfigNode mergeNodes(ConfigNode global, ConfigNode local)
        {
            ConfigNode output = new ConfigNode("MOUNT");
            global.CopyTo(output);
            if (local.HasValue("canAdjustSize"))
            {
                output.RemoveValues("canAdjustSize");
                output.AddValue("canAdjustSize", local.GetBoolValue("canAdjustSize"));
            }
            if (local.HasValue("size"))
            {
                output.RemoveValues("size");
                output.AddValue("size", local.GetFloatValue("size"));
            }
            if (local.HasValue("minSize"))
            {
                output.RemoveValues("minSize");
                output.AddValue("minSize", local.GetFloatValue("minSize"));
            }
            if (local.HasValue("maxSize"))
            {
                output.RemoveValues("maxSize");
                output.AddValue("maxSize", local.GetFloatValue("maxSize"));
            }
            if (local.HasValue("engineSpacing"))
            {
                output.RemoveValues("engineSpacing");
                output.AddValue("engineSpacing", local.GetFloatValue("engineSpacing"));
            }
            if (local.HasValue("rotateEngines"))
            {
                output.RemoveValues("rotateEngines");
                output.AddValue("rotateEngines", local.GetStringValue("rotateEngines"));
            }

            return output;
        }
コード例 #5
0
        private static MethodInfo InstantiateHandler(ConfigNode node, RasterPropMonitor ourMonitor, out MonoBehaviour moduleInstance, out HandlerSupportMethods support)
        {
            moduleInstance = null;
            support.activate = null;
            support.buttonClick = null;
            support.buttonRelease = null;
            support.getHandlerReferences = null;
            if (node.HasValue("name") && node.HasValue("method"))
            {
                string moduleName = node.GetValue("name");
                string methodName = node.GetValue("method");

                var handlerConfiguration = new ConfigNode("MODULE");
                node.CopyTo(handlerConfiguration);

                MonoBehaviour thatModule = null;
                // Part modules are different in that they remain instantiated when you switch vessels, while the IVA doesn't.
                // Because of this RPM can't instantiate partmodule-based handlers itself -- there's no way to tell if this was done already or not.
                // Which means there can only be one instance of such a handler per pod, and it can't receive configuration values from RPM.
                if (node.HasValue("isPartModule"))
                {
                    foreach (PartModule potentialModule in ourMonitor.part.Modules)
                    {
                        if (potentialModule.ClassName == moduleName)
                        {
                            thatModule = potentialModule;
                            break;
                        }
                    }
                }
                else if (node.HasValue("multiHandler"))
                {

                    foreach (InternalModule potentialModule in ourMonitor.internalProp.internalModules)
                    {
                        if (potentialModule.ClassName == moduleName)
                        {
                            thatModule = potentialModule;
                            break;
                        }
                    }

                }

                if (thatModule == null && !node.HasValue("isPartModule"))
                {
                    try
                    {
                        thatModule = ourMonitor.internalProp.AddModule(handlerConfiguration);
                    }
                    catch
                    {
                        JUtil.LogErrorMessage(ourMonitor, "Caught exception when trying to instantiate module '{0}'. Something's fishy here", moduleName);
                    }
                }

                if (thatModule == null)
                {
                    JUtil.LogMessage(ourMonitor, "Warning, handler module \"{0}\" could not be loaded. This could be perfectly normal.", moduleName);
                    return null;
                }

                const string sigError = "Incorrect signature of the {0} method in {1}, ignoring option. If it doesn't work later, that's why.";

                if (node.HasValue("pageActiveMethod"))
                {
                    foreach (MethodInfo m in thatModule.GetType().GetMethods())
                    {
                        if (m.Name == node.GetValue("pageActiveMethod"))
                        {
                            try
                            {
                                support.activate = (Action<bool, int>)Delegate.CreateDelegate(typeof(Action<bool, int>), thatModule, m);
                            }
                            catch
                            {
                                JUtil.LogErrorMessage(ourMonitor, sigError, "page activation", moduleName);
                            }
                            break;
                        }
                    }
                }

                if (node.HasValue("buttonClickMethod"))
                {
                    foreach (MethodInfo m in thatModule.GetType().GetMethods())
                    {
                        if (m.Name == node.GetValue("buttonClickMethod"))
                        {
                            try
                            {
                                support.buttonClick = (Action<int>)Delegate.CreateDelegate(typeof(Action<int>), thatModule, m);
                            }
                            catch
                            {
                                JUtil.LogErrorMessage(ourMonitor, sigError, "button click", moduleName);
                            }
                            break;
                        }
                    }
                }

                if (node.HasValue("buttonReleaseMethod"))
                {
                    foreach (MethodInfo m in thatModule.GetType().GetMethods())
                    {
                        if (m.Name == node.GetValue("buttonReleaseMethod"))
                        {
                            try
                            {
                                support.buttonRelease = (Action<int>)Delegate.CreateDelegate(typeof(Action<int>), thatModule, m);
                            }
                            catch
                            {
                                JUtil.LogErrorMessage(ourMonitor, sigError, "button release", moduleName);
                            }
                            break;
                        }
                    }
                }

                if (node.HasValue("getHandlerReferencesMethod"))
                {
                    foreach (MethodInfo m in thatModule.GetType().GetMethods())
                    {
                        if (m.Name == node.GetValue("getHandlerReferencesMethod"))
                        {
                            try
                            {
                                support.getHandlerReferences = (Action<MonoBehaviour, MonoBehaviour>)Delegate.CreateDelegate(typeof(Action<MonoBehaviour, MonoBehaviour>), thatModule, m);
                            }
                            catch
                            {
                                JUtil.LogErrorMessage(ourMonitor, sigError, "handler references", moduleName);
                            }
                            break;
                        }
                    }
                }

                moduleInstance = thatModule;
                foreach (MethodInfo m in thatModule.GetType().GetMethods())
                {
                    if (m.Name == methodName)
                    {
                        return m;
                    }
                }

            }
            return null;
        }
コード例 #6
0
ファイル: KAS_Shared.cs プロジェクト: xxApvxx/KAS
        public static ProtoPartSnapshot LoadProtoPartSnapshot(ConfigNode node)
        {
            ConfigNode node_copy = new ConfigNode();
            node.CopyTo(node_copy);

            node_copy.RemoveValues("kas_total_mass");
            node_copy.RemoveValues("kas_total_cost");

            return new ProtoPartSnapshot(node_copy, null, HighLogic.CurrentGame);
        }
コード例 #7
0
 public override void OnLoad(ConfigNode config)
 {
     if (this.config == null)
     {
         this.config = new ConfigNode();
         config.CopyTo(this.config);
     }
 }
コード例 #8
0
        public override void OnLoad(ConfigNode node)
        {
            if (Global.Debug2) Utils.Log("OnLoad start");

            // save the original config
            originalConfig = new ConfigNode();
            node.CopyTo(originalConfig);

            loadConfig(node);
        }
コード例 #9
0
            private static bool InstantiateHandler(ConfigNode node, PartModule ourComp, 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 ourComp.part.Modules) {
                    if (potentialModule.ClassName == moduleName) {
                        thatModule = potentialModule;
                        break;
                    }
                }
                if (thatModule == null) {
                    thatModule = ourComp.part.AddModule(handlerConfiguration);
                }
                if (thatModule == null) {
                    JUtil.LogMessage(ourComp, "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(ourComp, "Error, incorrect variable handler configuration for module {0}", moduleName);
                            return false;
                        }
                        break;
                    }
                }
                return true;
            }
コード例 #10
0
        public RSSLoadInfo(ConfigNode RSSnode)
        {
            useEpoch = RSSnode.TryGetValue("Epoch", ref epoch);
            RSSnode.TryGetValue("wrap", ref doWrap);
            RSSnode.TryGetValue("compressNormals", ref compressNormals);
            RSSnode.TryGetValue("spheresOnly", ref spheresOnly);
            RSSnode.TryGetValue("orbitCalc", ref orbitCalc);
            RSSnode.TryGetValue("defaultAtmoScale", ref defaultAtmoScale);
            RSSnode.TryGetValue("SSAtmoScale", ref SSAtmoScale);

            node = new ConfigNode();
            RSSnode.CopyTo(node);
            // get spherical scaledspace mesh
            if (ScaledSpace.Instance != null)
            {
                //print("*RSS* Printing ScaledSpace Transforms");
                foreach (Transform t in ScaledSpace.Instance.scaledSpaceTransforms)
                {
                    /*print("***** TRANSFROM: " + t.name);
                    Utils.PrintTransformUp(t);
                    Utils.PrintTransformRecursive(t);*/
                    if (t.name.Equals("Jool"))
                        joolMesh = (MeshFilter)t.GetComponent(typeof(MeshFilter));
                }
                //print("*RSS* InverseScaleFactor = " + ScaledSpace.InverseScaleFactor);
            }
        }
コード例 #11
0
ファイル: KethaneDetector.cs プロジェクト: Jaidan/Kethane
        public override void OnLoad(ConfigNode config)
        {
            if (this.config == null)
            {
                this.config = new ConfigNode();
                config.CopyTo(this.config);
            }

            resources = this.config.GetNodes("Resource").Select(n => n.GetValue("Name")).ToList();
            if (resources.Count == 0)
            {
                resources = KethaneController.ResourceDefinitions.Select(r => r.Resource).ToList();
            }
        }
コード例 #12
0
ファイル: KASModuleContainer.cs プロジェクト: vosechu/KAS
 public void Load(ConfigNode node)
 {
     if (node.name == "CONTENT" && node.HasValue("qty"))
     {
         pristine_count += int.Parse(node.GetValue("qty"));
     }
     else if (node.name == "CONTENT_PART" && node.HasValue("kas_total_mass"))
     {
         ConfigNode nodeD = new ConfigNode();
         node.CopyTo(nodeD);
         instance_mass += float.Parse(node.GetValue("kas_total_mass"));
         instances.Add(nodeD);
     }
 }
コード例 #13
0
        private static bool InstantiateHandler(ConfigNode node, InternalModule ourSwitch, out Action<bool> actionCall, out Func<bool> stateCall)
        {
            actionCall = null;
            stateCall = null;
            var handlerConfiguration = new ConfigNode("MODULE");
            node.CopyTo(handlerConfiguration);
            string moduleName = node.GetValue("name");
            string stateMethod = string.Empty;
            if (node.HasValue("stateMethod"))
                stateMethod = node.GetValue("stateMethod");

            InternalModule thatModule = null;
            foreach (InternalModule potentialModule in ourSwitch.internalProp.internalModules)
                if (potentialModule.ClassName == moduleName) {
                    thatModule = potentialModule;
                    break;
                }

            if (thatModule == null)
                thatModule = ourSwitch.internalProp.AddModule(handlerConfiguration);
            if (thatModule == null)
                return false;
            foreach (MethodInfo m in thatModule.GetType().GetMethods()) {
                if (m.Name == node.GetValue("actionMethod")) {
                    actionCall = (Action<bool>)Delegate.CreateDelegate(typeof(Action<bool>), thatModule, m);
                }
                if (!string.IsNullOrEmpty(stateMethod) && m.Name == stateMethod) {
                    stateCall = (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), thatModule, m);
                }
            }
            return actionCall != null;
        }
コード例 #14
0
ファイル: DudeCore.cs プロジェクト: TheDude1972/KSP
        //ModifyNode applies the ConfigNode mod as a 'patch' to ConfigNode original, then returns the patched ConfigNode.
        // it uses FindConfigNodeIn(src, nodeType, nodeName, nodeTag) to recurse.
        public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
        {
            ConfigNode newNode = new ConfigNode(original.name);
            original.CopyTo(newNode);

            foreach (ConfigNode.Value val in mod.values)
            {
                if (val.name[0] == '@')
                {
                    // Modifying a value: Format is @key = value or @key,index = value
                    string valName = val.name.Substring(1);
                    int index = 0;
                    if (valName.Contains(","))
                    {
                        int.TryParse(valName.Split(',')[1], out index);
                        valName = valName.Split(',')[0];
                    }
                    newNode.SetValue(valName, val.value, index);
                }
                else if (val.name[0] == '!')
                {
                    // Parsing: Format is @key = value or @key,index = value
                    string valName = val.name.Substring(1);
                    int index = 0;
                    if (valName.Contains(","))
                    {
                        int.TryParse(valName.Split(',')[1], out index);
                        valName = valName.Split(',')[0];
                    } // index is useless right now, but some day it might not be.
                    newNode.RemoveValue(valName);
                }
                else
                {
                    newNode.AddValue(val.name, val.value);
                }
            }

            foreach (ConfigNode subMod in mod.nodes)
            {
                if (subMod.name[0] == '@')
                {
                    // Modifying a node: Format is @NODETYPE {...}, @NODETYPE[Name] {...} or @NODETYPE[Name,Tag] {...}
                    ConfigNode subNode = null;

                    if (subMod.name.Contains("["))
                    { // format @NODETYPE[Name] {...} or @NODETYPE[Name, Tag] {...}
                        string nodeType = subMod.name.Substring(1).Split('[')[0].Trim();
                        string nodeName = subMod.name.Split('[')[1].Replace("]", "").Trim();
                        string nodeTag = null;
                        if (nodeName.Contains(","))
                        { //format @NODETYPE[Name, Tag] {...}
                            nodeTag = nodeName.Split(',')[1];
                            nodeName = nodeName.Split(',')[0];
                        }
                        subNode = FindConfigNodeIn(newNode, nodeType, nodeName, nodeTag);
                    }
                    else
                    { // format @NODETYPE {...}
                        string nodeType = subMod.name.Substring(1);
                        subNode = newNode.GetNode(nodeType);
                    }
                    // find the original subnode to modify, modify it, remove the original and add the modified.
                    if (subNode == null)
                    {
                        print("Could not find node to modify: " + subMod.name);
                    }
                    else
                    {
                        ConfigNode newSubNode = ModifyNode(subNode, subMod);
                        newNode.nodes.Remove(subNode);
                        newNode.nodes.Add(newSubNode);
                    }

                }
                else if (subMod.name[0] == '!')
                {
                    // Removing a node: Format is !NODETYPE {}, !NODETYPE[Name] {} or !NODETYPE[Name,Tag] {}

                    ConfigNode subNode;

                    if (subMod.name.Contains("["))
                    { // format !NODETYPE[Name] {} or !NODETYPE[Name, Tag] {}
                        string nodeType = subMod.name.Substring(1).Split('[')[0].Trim();
                        string nodeName = subMod.name.Split('[')[1].Replace("]", "").Trim();
                        string nodeTag = null;
                        if (nodeName.Contains(","))
                        { //format !NODETYPE[Name, Tag] {}
                            nodeTag = nodeName.Split(',')[1];
                            nodeName = nodeName.Split(',')[0];
                        }
                        subNode = FindConfigNodeIn(newNode, nodeType, nodeName, nodeTag);
                    }
                    else
                    { // format !NODETYPE {}
                        string nodeType = subMod.name.Substring(1);
                        subNode = newNode.GetNode(nodeType);
                    }
                    if (subNode != null)
                        newNode.nodes.Remove(subNode);

                }
                else
                {
                    // this is a full node, not a mod, so just add it as a new subnode.
                    newNode.AddNode(subMod);
                }
            }
            return newNode;
        }