public override void OnSave(ConfigNode node)
        {
            base.OnSave(node);

            node.RemoveNodes("ScienceData");
            foreach(ScienceData data in storedData) {
                data.Save((ConfigNode)node.AddNode("ScienceData"));
            }
        }
예제 #2
0
 //called on GameSave event, refresh all data from loaded vessels and save to .sfs
 private void GameSaveTrigger(ConfigNode node)
 {
     //need to call save routines here
     if (node.HasNode("VMSNode")) //note that we do not load data at this point, our data storage is static so we know what's in the save file is old, invalid data
     {
         node.RemoveNodes("VMSNode"); //should only ever be on VMSnode in a file, remove all nodes to error trap it
     }
     node.AddNode(VesselModuleStaticData.SaveRoutine());
 }
예제 #3
0
        public static void OnSave(ConfigNode node, ImpactScienceData data)
        {
            ImpactMonitor.Log("Saving spectrometerr");

            node.RemoveNodes("ScienceData"); //** Prevent duplicates
            if (data != null)
            {
                ConfigNode storedDataNode = node.AddNode("ScienceData");
                ImpactMonitor.Log("saving data");
                data.SaveImpact(storedDataNode);
            }
        }
예제 #4
0
        private void SanitizeNode(ConfigNode module, ConfigNode[] templates)
        {
            string name = module.GetValue("name");

            if (module.HasNode("ScienceData"))
            {
                module.RemoveNodes("ScienceData");
            }
            if (name == "Log")
                module.ClearValues();

            ConfigNode template = templates.FirstOrDefault(t => t.GetValue("name") == name);
            if (template == null) return;
            ConfigNode.ValueList values = template.values;
            foreach (ConfigNode.Value val in values)
            {
                module.SetValue(val.name, val.value);
            }

            foreach (ConfigNode node in template.GetNodes()) //This should account for nested nodes, like RealChutes' PARACHUTE node
            {
                if (module.HasNode(node.name))
                {
                    foreach (ConfigNode.Value val in node.values)
                        module.GetNode(node.name).SetValue(val.name, val.value);
                }
            }

            foreach (ConfigNode node in module.GetNodes("MODULE"))
                SanitizeNode(node, templates);

            /*
            if (name.Contains("ModuleEngines"))
            {
                module.SetValue("staged", "False");
                module.SetValue("flameout", "False");
                module.SetValue("EngineIgnited", "False");
                module.SetValue("engineShutdown", "False");
                module.SetValue("currentThrottle", "0");
                module.SetValue("manuallyOverridden", "False");
            }
            else if (name == "ModuleScienceExperiment")
            {
                module.SetValue("Deployed", "False");
                module.SetValue("Inoperable", "False");
            }
            else if (name == "ModuleParachute")
            {
                module.SetValue("staged", "False");
                module.SetValue("persistentState", "STOWED");
            }
            else if (name == "Log")
            {
                module.ClearValues();
            }

            if (module.HasNode("ScienceData"))
            {
                module.RemoveNodes("ScienceData");
            }
            */
        }
        private static void InsertNode(ConfigNode newNode, ConfigNode subMod, int index)
        {
            string modName = subMod.name;

            ConfigNode[] oldValues = newNode.GetNodes(modName);
            if (index < oldValues.Length)
            {
                newNode.RemoveNodes(modName);
                int i = 0;
                for (; i < index; ++i)
                    newNode.AddNode(oldValues[i]);
                newNode.AddNode(subMod);
                for (; i < oldValues.Length; ++i)
                    newNode.AddNode(oldValues[i]);
            }
            else
                newNode.AddNode(subMod);
        }
예제 #6
0
파일: SCANsat.cs 프로젝트: DBT85/SCANsat
		public override void OnSave(ConfigNode node)
		{
			node.RemoveNodes("ScienceData"); //** Prevent duplicates
			foreach (ScienceData SCANData in storedData)
			{
				ConfigNode storedDataNode = node.AddNode("ScienceData");
				SCANData.Save(storedDataNode);
			}
			if (RPMList.Count > 0)
			{
				ConfigNode RPMPersistence = new ConfigNode("SCANsatRPM");
				foreach (RPMPersistence RPMMFD in RPMList)
				{
					ConfigNode RPMProp = new ConfigNode("Prop");
					RPMProp.AddValue("Prop ID", RPMMFD.RPMID);
					RPMProp.AddValue("Mode", RPMMFD.RPMMode);
					RPMProp.AddValue("Color", RPMMFD.RPMColor);
					RPMProp.AddValue("Zoom", RPMMFD.RPMZoom);
					RPMProp.AddValue("Lines", RPMMFD.RPMLines);
					RPMPersistence.AddNode(RPMProp);
				}
				node.AddNode(RPMPersistence);
			}
		}
예제 #7
0
        public void Update()
        {
            //Debug.Log("Start update!");//print("lock " + InputLockManager.IsLocked(ControlTypes.ALL_SHIP_CONTROLS));
            //if ((ControlTypes.ALL_SHIP_CONTROLS & (ControlTypes)InputLockManager.lockMask) == 0)
            //{
            //    print("not Locked");
            //}
            //else
            //{
            //    print("locked");
            //}
            //print("AGXLock state " + AGXLockSet);
            string errLine = "1";
            try
            {
                bool RootPartExists = new bool();
                errLine = "2";
                try
                {
                    errLine = "3";
                    if (FlightGlobals.ActiveVessel.parts.Count > 0) //we are actually checking null here on teh try-catch block, the if statement is a dummy
                    {
                        errLine = "4";
                    }
                    errLine = "5";
                    RootPartExists = true;
                }
                catch
                {
                    errLine = "6";
                    RootPartExists = false;
                }
                errLine = "7";

                if (flightNodeIsLoaded)
                {
                    if (RootPartExists)
                    {

                        errLine = "8";
                        if (AGXRoot != FlightGlobals.ActiveVessel.rootPart) //root part change, refresh stuff
                        {
                            // print("AGX Root change");
                            bool isDocking = false;
                            bool isUndocking = false;
                            try
                            {
                                if (FlightGlobals.ActiveVessel.parts.Contains(AGXRoot))
                                {
                                    isDocking = true;
                                    // print("AGX: Is a dock ");// + AGXRoot.ConstructID + " " + FlightGlobals.ActiveVessel.rootPart.ConstructID);
                                }
                                else if (oldShipParts.Contains(FlightGlobals.ActiveVessel.rootPart))
                                {
                                    isUndocking = true;
                                    //print("AGX: is an undock");
                                    //only clear actions if not a docking event
                                }
                                else
                                {
                                    //print("AGX: vessel switch");
                                    //CurrentVesselActions.Clear();
                                }
                            }
                            catch
                            {
                                //print("AGX: something was null in docking check");
                            }
                            errLine = "8a";
                            //print("Root part changed, AGX reloading");
                            //print("Root prt ch");
                            //if(!overrideRootChange) //no longer using DockingEvent
                            //{
                            errLine = "8b";
                            //print("Root part changed, AGX reloading B");
                            //loadFinished = false;

                            //CurrentVesselActions.Clear(); //we have saved old ship so clear actions
                            //if (!isDocking && !isUndocking)
                            //{
                            //    CurrentVesselActions.Clear();
                            //}
                            errLine = "24";
                            if (isDocking) //is a docking maneuver
                            {
                                DockingEvent();
                                RefreshCurrentActions();
                            }
                            if (isUndocking)
                            {
                                CheckListForMultipleVessels();
                                //RefreshCurrentActions();
                            }
                            //else //not a docking or undocking, load single node //this else closed at line 3792
                            //{
                            if (!isUndocking && !isDocking)
                            {
                                ConfigNode oldVsl = new ConfigNode();
                                errLine = "8c";
                                if (AGXRoot != null)
                                {
                                    errLine = "9";
                                    // print("Root part changed, AGX reloadinga");
                                    oldVsl = new ConfigNode(AGXRoot.vessel.rootPart.flightID.ToString());
                                    if (AGXFlightNode.HasNode(AGXRoot.vessel.rootPart.flightID.ToString()))
                                    {
                                        errLine = "10";
                                        //print("Root part changed, AGX reloadingb");
                                        oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.rootPart.flightID.ToString());
                                        AGXFlightNode.RemoveNode(AGXRoot.vessel.rootPart.flightID.ToString());
                                    }
                                    else if (AGXFlightNode.HasNode(AGXRoot.vessel.id.ToString()))
                                    {
                                        errLine = "10";
                                        //print("Root part changed, AGX reloadingb");
                                        oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.id.ToString());
                                        AGXFlightNode.RemoveNode(AGXRoot.vessel.id.ToString());
                                    }
                                    errLine = "11";
                                    //print("Root part changed, AGX reloadingc");
                                    if (oldVsl.HasValue("name"))
                                    {
                                        oldVsl.RemoveValue("name");
                                    }
                                    oldVsl.AddValue("name", AGXRoot.vessel.vesselName);
                                    errLine = "12";
                                    // errLine = "13";
                                    if (oldVsl.HasValue("currentKeyset"))
                                    {
                                        oldVsl.RemoveValue("currentKeyset");
                                    }
                                    oldVsl.AddValue("currentKeyset", CurrentKeySetFlight.ToString());
                                    errLine = "13";
                                    //errLine = "14";
                                    if (oldVsl.HasValue("groupNames"))
                                    {
                                        oldVsl.RemoveValue("groupNames");
                                    }
                                    oldVsl.AddValue("groupNames", SaveGroupNames(""));
                                    errLine = "14";
                                    //errLine = "15";
                                    if (oldVsl.HasValue("groupVisibility"))
                                    {
                                        oldVsl.RemoveValue("groupVisibility");
                                    }
                                    oldVsl.AddValue("groupVisibility", SaveGroupVisibility(""));
                                    errLine = "15";
                                    //errLine = "16";
                                    if (oldVsl.HasValue("groupVisibilityNames"))
                                    {
                                        errLine = "15b";
                                        oldVsl.RemoveValue("groupVisibilityNames");
                                        errLine = "15c";
                                    }
                                    errLine = "15d";

                                    oldVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                                    errLine = "16";
                                    if (oldVsl.HasValue("DirectActionState"))
                                    {
                                        errLine = "16b";
                                        oldVsl.RemoveValue("DirectActionState");
                                        errLine = "16c";
                                    }
                                    errLine = "16d";

                                    oldVsl.AddValue("DirectActionState", SaveDirectActionState(""));

                                    oldVsl.RemoveNodes("PART");

                                    foreach (Part p in AGXRoot.vessel.Parts)
                                    {
                                        errLine = "17";
                                        List<AGXAction> thisPartsActions = new List<AGXAction>();
                                        errLine = "18 ";
                                        //print("part 18a" + p.ConstructID + " " + CurrentVesselActions);
                                        thisPartsActions.AddRange(StaticData.CurrentVesselActions.FindAll(p2 => p2.ba.listParent.part == p));
                                        errLine = "18a";

                                        //errLine = "18";
                                        if (thisPartsActions.Count > 0)
                                        {
                                            errLine = "18b";
                                            ConfigNode partTemp = new ConfigNode("PART");
                                            errLine = "19";
                                            partTemp.AddValue("name", p.vessel.vesselName);
                                            partTemp.AddValue("vesselID", p.vessel.id);
                                            //partTemp.AddValue("relLocX", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).x);
                                            //partTemp.AddValue("relLocY", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).y);
                                            //partTemp.AddValue("relLocZ", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).z);
                                            partTemp.AddValue("flightID", p.flightID.ToString());
                                            errLine = "20";
                                            foreach (AGXAction agxAct in thisPartsActions)
                                            {
                                                errLine = "21";
                                                partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                                            }
                                            errLine = "22";

                                            oldVsl.AddNode(partTemp);
                                            errLine = "23";
                                        }
                                        errLine = "24";
                                    }

                                    //print("AGX Save old vessel "+ oldVsl);
                                    AGXFlightNode.AddNode(oldVsl);
                                    //print("Root part changed, AGX reloadingd " + oldVsl.GetValue("groupNames"));
                                }
                                errLine = "24a";

                                StaticData.CurrentVesselActions.Clear();
                                errLine = "24b";
                            }
                            errLine = "24c";
                            if (!isDocking)
                            {

                                errLine = "24d";
                                bool checkIsVab = true;
                                ConfigNode vslNode = new ConfigNode();
                                try
                                {
                                    if (FlightGlobals.ActiveVessel.landedAt == "Runway")
                                    {
                                        //print("Runway found");
                                        checkIsVab = false;
                                    }
                                    else
                                    {
                                        //print("runway not found");
                                        checkIsVab = true;
                                    }

                                }
                                catch
                                {
                                    //print("runway iffy");
                                    checkIsVab = true;
                                }
                                errLine = "24e";
                                if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString()))
                                {
                                    //print("AGX flight node found");
                                    vslNode = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.id.ToString());

                                }
                                else if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()))
                                {
                                    // print("AGX flightID found");
                                    vslNode = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString());

                                }
                                //else if(RootParts.HasNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()) && AGXRoot != null)  //replace with previously docked ship check, in other parts of code
                                //{
                                //    print("AGX root part found");
                                //    vslNode = oldVsl;
                                //    ConfigNode FoundRootPart = RootParts.GetNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString());
                                //    vslNode.RemoveValue("currentKeyset");
                                //    vslNode.AddValue("currentKeyset", FoundRootPart.GetValue("currentKeyset"));
                                //    vslNode.RemoveValue("groupVisibility");
                                //    vslNode.AddValue("groupVisibility", FoundRootPart.GetValue("groupVisibility"));
                                //    vslNode.RemoveValue("groupVisibilityNames");
                                //    vslNode.AddValue("groupVisibilityNames", FoundRootPart.GetValue("groupVisibilityNames"));
                                //    ShowAmbiguousMessage = false;
                                //}

                                else if (AGXEditorNodeFlight.HasNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, checkIsVab)))
                                {
                                    // print("AGX VAB1 ");// + FlightGlobals.ActiveVessel.vesselName + " " + FlightGlobals.ActiveVessel.rootPart.ConstructID);
                                    vslNode = AGXEditorNodeFlight.GetNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, checkIsVab));
                                    vslNode.name = FlightGlobals.ActiveVessel.rootPart.flightID.ToString();
                                    AGXFlightNode.AddNode(vslNode);
                                    // print("node check " + vslNode.ToString());
                                }
                                else if (AGXEditorNodeFlight.HasNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, !checkIsVab)))
                                {
                                    //print("AGX vab2");
                                    vslNode = AGXEditorNodeFlight.GetNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, !checkIsVab));
                                    vslNode.name = FlightGlobals.ActiveVessel.rootPart.flightID.ToString();
                                    AGXFlightNode.AddNode(vslNode);
                                }
                                else
                                {
                                    //print("AGX notfound");
                                    vslNode = new ConfigNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString());
                                    vslNode.AddValue("name", FlightGlobals.ActiveVessel.vesselName);
                                    vslNode.AddValue("currentKeyset", "1");
                                    vslNode.AddValue("groupNames", "");
                                    vslNode.AddValue("groupVisibility", "1011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111");
                                    vslNode.AddValue("groupVisibilityNames", "Group 1‣Group 2‣Group 3‣Group 4‣Group 5");
                                    vslNode.AddValue("DirectActionState", "");
                                    AGXFlightNode.AddNode(vslNode);
                                }
                                errLine = "24f";
                                CurrentKeySetFlight = Convert.ToInt32((string)vslNode.GetValue("currentKeyset"));
                                //LoadCurrentKeyBindings();
                                try
                                {
                                    if (CurrentKeySetFlight < 1 || CurrentKeySetFlight > 5)
                                    {
                                        CurrentKeySetFlight = 1;
                                    }
                                }
                                catch
                                {
                                    CurrentKeySetFlight = 1;
                                }
                                CurrentKeySetNameFlight = KeySetNamesFlight[CurrentKeySetFlight - 1];
                                LoadGroupNames(vslNode.GetValue("groupNames"));
                                LoadGroupVisibility(vslNode.GetValue("groupVisibility"));
                                LoadGroupVisibilityNames(vslNode.GetValue("groupVisibilityNames"));
                                //Debug.Log(vslNode);
                                if (vslNode.HasValue("DirectActionState"))
                                {
                                    //Debug.Log("has state");
                                    LoadDirectActionState(vslNode.GetValue("DirectActionState"));
                                }
                                else
                                {
                                    //Debug.Log("no state");
                                    LoadDirectActionState("");
                                }
                                errLine = "24fg";
                                foreach (ConfigNode prtNode in vslNode.nodes)
                                {

                                    float partDist = 100f;
                                    Part gamePart = new Part();
                                    if (prtNode.HasValue("flightID"))
                                    {
                                        errLine = "24h";
                                        try
                                        {
                                            uint flightIDFromFile = Convert.ToUInt32(prtNode.GetValue("flightID"));
                                            gamePart = FlightGlobals.ActiveVessel.parts.First(prt => prt.flightID == flightIDFromFile);
                                            partDist = 0f;
                                        }
                                        catch
                                        {
                                            continue; //bad FLightID in file, skip this action
                                        }
                                    }

                                    else
                                    {
                                        errLine = "24i";
                                        foreach (Part p in FlightGlobals.ActiveVessel.parts) //do a distance compare check, floats do not guarantee perfect decimal accuray so use part with least distance, should be zero distance in most cases
                                        {
                                            Vector3 partLoc = new Vector3((float)Convert.ToDouble(prtNode.GetValue("relLocX")), (float)Convert.ToDouble(prtNode.GetValue("relLocY")), (float)Convert.ToDouble(prtNode.GetValue("relLocZ")));
                                            float thisPartDist = Vector3.Distance(partLoc, FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position));
                                            if (thisPartDist < partDist)
                                            {
                                                gamePart = p;
                                                partDist = thisPartDist;
                                            }
                                        }
                                    }
                                    bool ShowAmbiguousMessage2 = true; //show actions ambiguous message?
                                    errLine = "24j";
                                    //if (ShowAmbiguousMessage && partDist < 0.3f)
                                    if (partDist < 0.3f)//do not show it if part found is more then 0.3meters off
                                    {
                                        ShowAmbiguousMessage2 = true;
                                    }
                                    else
                                    {
                                        ShowAmbiguousMessage2 = false;
                                    }
                                    errLine = "24k";
                                    //print("gamepart " + gamePart.ConstructID + " " + partDist);
                                    foreach (ConfigNode actNode in prtNode.nodes)
                                    {
                                        //print("node " + actNode + " " + gamePart.ConstructID);
                                        AGXAction actToAdd = AGextScenario.LoadAGXActionVer2(actNode, gamePart, ShowAmbiguousMessage2);
                                        //print("act to add " + actToAdd.ba);
                                        if (actToAdd.ba != null && !StaticData.CurrentVesselActions.Contains(actToAdd))
                                        {
                                            StaticData.CurrentVesselActions.Add(actToAdd);
                                        }
                                    }
                                }
                                errLine = "24l";
                                List<KSPActionGroup> CustomActions = new List<KSPActionGroup>();
                                CustomActions.Add(KSPActionGroup.Custom01); //how do you add a range from enum?
                                CustomActions.Add(KSPActionGroup.Custom02);
                                CustomActions.Add(KSPActionGroup.Custom03);
                                CustomActions.Add(KSPActionGroup.Custom04);
                                CustomActions.Add(KSPActionGroup.Custom05);
                                CustomActions.Add(KSPActionGroup.Custom06);
                                CustomActions.Add(KSPActionGroup.Custom07);
                                CustomActions.Add(KSPActionGroup.Custom08);
                                CustomActions.Add(KSPActionGroup.Custom09);
                                CustomActions.Add(KSPActionGroup.Custom10);

                                //errLine = "16";
                                // string AddGroup = "";
                                List<BaseAction> partAllActions = new List<BaseAction>(); //is all vessel actions, copy pasting code
                                foreach (Part p in FlightGlobals.ActiveVessel.parts)
                                {
                                    partAllActions.AddRange(p.Actions);
                                    foreach (PartModule pm in p.Modules)
                                    {
                                        partAllActions.AddRange(pm.Actions);
                                    }

                                    //foreach (BaseAction ba in partAllActions)
                                    //{
                                    //    print(ba.listParent.part + " " + ba.listParent.module.moduleName + " " + ba.name + " " + ba.guiName);
                                    //}
                                    // print("part orgpos " + p.ConstructID+ " "  + p.orgPos + " " + p.orgRot);
                                }
                                errLine = "24m";
                                foreach (BaseAction baLoad in partAllActions)
                                {
                                    foreach (KSPActionGroup agrp in CustomActions)
                                    {

                                        if ((baLoad.actionGroup & agrp) == agrp)
                                        {
                                            // errLine = "17";
                                            ////AddGroup = AddGroup + '\u2023' + (CustomActions.IndexOf(agrp) + 1).ToString("000") + baLoad.guiName;
                                            //partAGActions2.Add(new AGXAction() { group = CustomActions.IndexOf(agrp) + 1, prt = this.part, ba = baLoad, activated = false });
                                            AGXAction ToAdd = new AGXAction() { prt = baLoad.listParent.part, ba = baLoad, group = CustomActions.IndexOf(agrp) + 1, activated = false };
                                            List<AGXAction> Checking = new List<AGXAction>();
                                            Checking.AddRange(StaticData.CurrentVesselActions);
                                            Checking.RemoveAll(p => p.group != ToAdd.group);

                                            Checking.RemoveAll(p => p.prt != ToAdd.prt);

                                            Checking.RemoveAll(p => p.ba != ToAdd.ba);

                                            if (Checking.Count == 0)
                                            {

                                                StaticData.CurrentVesselActions.Add(ToAdd);

                                            }
                                        }
                                    }
                                    // errLine = "18";
                                }
                            }
                            //} //close backet on else statment that this is not dock/undock

                            errLine = "32";

                            AGXRoot = FlightGlobals.ActiveVessel.rootPart;
                            oldShipParts = new List<Part>(FlightGlobals.ActiveVessel.parts);

                            errLine = "32a";

                            overrideRootChange = false;
                            LastPartCount = FlightGlobals.ActiveVessel.parts.Count;
                            AGEditorSelectedParts.Clear();
                            PartActionsList.Clear();
                            RefreshCurrentActions();
                            loadFinished = true;
                            //print("sit " + FlightGlobals.ActiveVessel.situation.ToString());
                            errLine = "33";
                            CurrentKeySetNameFlight = KeySetNamesFlight[CurrentKeySetFlight - 1];
                            LoadCurrentKeyBindings();
                            errLine = "33a";
                            FlightSaveToFile(AGXFlightNode);//add save current vessel here
                            errLine = "33b";
                        }
                    }
                    errLine = "34";
                    if (LastPartCount != FlightGlobals.ActiveVessel.parts.Count) //parts count changed, remove any actions assigned to parts that have disconnected/been destroyed
                    {
                        print("Part count change, reload AGX");
                        if (FlightGlobals.ActiveVessel.parts.Count > LastPartCount)
                        {
                            DockingEvent();
                        }
                        else if (LastPartCount > FlightGlobals.ActiveVessel.parts.Count) //new count is larger was a docking op, see the dock gameevent to handle that //chaged again
                        {
                            CheckListForMultipleVessels();
                        }
                        AGEditorSelectedParts.Clear();
                        PartActionsList.Clear();
                        //LoadActionGroups();
                        RefreshCurrentActions();
                        LastPartCount = FlightGlobals.ActiveVessel.parts.Count;
                        oldShipParts = new List<Part>(FlightGlobals.ActiveVessel.parts);
                        errLine = "35";

                    }
                }
                errLine = "36";

                if (InputLockManager.GetControlLock("kOSTerminal") == ControlTypes.None && (ControlTypes.KSC_ALL & (ControlTypes)InputLockManager.lockMask) == 0)// && InputLockManager.IsLocked(ControlTypes.All))//&& !InputLockManager.IsLocked(ControlTypes.All))
                {

                    foreach (KeyCode KC in ActiveKeys)
                    {

                        errLine = "37";
                        if (Input.GetKeyDown(KC))
                        {
                            //print("keydown " + KC);
                            for (int i = 1; i <= 250; i = i + 1)
                            {
                                if (AGXguiKeys[i] == KC)
                                {
                                    //print("Key act for some reason " + i);
                                    ActivateActionGroupCheckModKeys(i);
                                }
                            }
                        }
                    }

                    foreach (KeyValuePair<int, KeyCode> kcPair in ActiveKeysDirect)
                    {
                        if (Input.GetKey(kcPair.Value) && !DirectKeysState[kcPair.Key])
                        {
                            ActivateActionGroupCheckModKeys(kcPair.Key, true, true);
                            DirectKeysState[kcPair.Key] = true;
                            //Debug.Log("turn on");
                        }
                        else if (!Input.GetKey(kcPair.Value) && DirectKeysState[kcPair.Key])
                        {
                            ActivateActionGroupCheckModKeys(kcPair.Key, true, false);
                            DirectKeysState[kcPair.Key] = false;
                            //Debug.Log("turn off");
                        }
                    }
                    foreach (KeyValuePair<int, KeyCode> kcPair2 in DefaultTen) //toggle groups if no actions are assigned
                    {
                        if (Input.GetKeyDown(kcPair2.Value))
                        {
                            if (AGXguiMod1Groups[kcPair2.Key] == Input.GetKey(AGXguiMod1Key) && AGXguiMod2Groups[kcPair2.Key] == Input.GetKey(AGXguiMod2Key))
                            {
                                if (kcPair2.Key <= 10)
                                {
                                    Dictionary<int, KSPActionGroup> CustomActions = new Dictionary<int, KSPActionGroup>();
                                    CustomActions.Add(1, KSPActionGroup.Custom01); //how do you add a range from enum?
                                    CustomActions.Add(2, KSPActionGroup.Custom02);
                                    CustomActions.Add(3, KSPActionGroup.Custom03);
                                    CustomActions.Add(4, KSPActionGroup.Custom04);
                                    CustomActions.Add(5, KSPActionGroup.Custom05);
                                    CustomActions.Add(6, KSPActionGroup.Custom06);
                                    CustomActions.Add(7, KSPActionGroup.Custom07);
                                    CustomActions.Add(8, KSPActionGroup.Custom08);
                                    CustomActions.Add(9, KSPActionGroup.Custom09);
                                    CustomActions.Add(10, KSPActionGroup.Custom10);
                                    FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(CustomActions[kcPair2.Key]);
                                    groupActivatedState[kcPair2.Key] = FlightGlobals.ActiveVessel.ActionGroups[CustomActions[kcPair2.Key]];
                                }
                                else
                                {
                                    groupActivatedState[kcPair2.Key] = !groupActivatedState[kcPair2.Key];
                                }
                            }
                        }
                    }
                }
                errLine = "38";
                //if (!ActiveActionsCalculated)
                //{
                //    CalculateActiveActions();
                // Debug.Log("AGX update middel A");
                //}
                if (Input.GetKeyDown(KeyCode.Mouse0) && ShowSelectedWin)
                {
                    errLine = "39";
                    Part selPart = new Part();
                    selPart = SelectPartUnderMouse();
                    if (selPart != null)
                    {
                        AddSelectedPart(selPart);
                    }
                    errLine = "40";
                }
                //Debug.Log("AGX update middel b");
                errLine = "41";
                if (RightClickDelay < 3)
                {
                    errLine = "42";
                    if (RightClickDelay == 2)
                    {
                        errLine = "43";
                        UIPartActionWindow UIPartsListThing = new UIPartActionWindow();
                        UIPartsListThing = (UIPartActionWindow)FindObjectOfType(typeof(UIPartActionWindow));
                        //UnityEngine.Object[] TempObj = FindObjectsOfType(typeof(UIPartActionWindow));
                        //print(TempObj.Length);
                        try
                        {
                            if (UIPartsListThing != null)
                            {
                                AddSelectedPart(UIPartsListThing.part);
                            }
                            // print(UIPartsListThing.part.name); //finds part right-clicked on
                            RightLickPartAdded = true;
                        }
                        catch
                        {
                            // print("nope!");
                            RightLickPartAdded = true;
                        }
                    }

                    RightClickDelay = RightClickDelay + 1;

                    errLine = "44";
                }
                //Debug.Log("AGX update middel c");
                errLine = "45";

                if (Input.GetKeyUp(KeyCode.Mouse1) && ShowSelectedWin && RightLickPartAdded == true)
                {
                    RightClickDelay = 0;
                    RightLickPartAdded = false;

                }
                errLine = "46";
                // Debug.Log("AGX update middel d");
                //foreach (Part p in FlightGlobals.ActiveVessel.Parts)
                //{
                //    foreach (PartModule pm in p.Modules)
                //    {
                //        foreach (BaseAction ba in pm.Actions)
                //        {
                //            print(p.partName + " " + pm.moduleName + " " + ba.name + " " + ba.guiName);
                //        }
                //    }
                //}
                if (ShowAGXMod)
                {
                    if (actionsCheckFrameCount >= 15) //this increments in the FixedUpdate frame now
                    {
                        CheckActionsActive();
                        //PartVesselChangeCheck();
                        actionsCheckFrameCount = 0;
                    }
                }
                //else
                //{
                //    actionsCheckFrameCount = actionsCheckFrameCount + (int)(Time.deltaTime * 1000f);
                //}
                //print("delta time " + actionsCheckFrameCount);
                errLine = "47";
                //Debug.Log("AGX update middel e2");
                //count down action cool downs
                groupCooldowns.RemoveAll(cd => cd.delayLeft > activationCoolDown); //remove actions from list that are finished cooldown, cooldown is in Update frame passes, pulled from .cfg
                foreach (AGXCooldown agCD in groupCooldowns)
                {
                    agCD.delayLeft = agCD.delayLeft + 1;

                }
                //Debug.Log("AGX update middel e");
                errLine = "48";
                if (RTFound)
                {
                    CheckRTQueue();
                }
                //Debug.Log("AGX update middel f");
                errLine = "49";
                //PrintPartActs();
                //print("landed " + FlightGlobals.ActiveVessel.landedAt);

                //if (test == null)
                //{
                //    Debug.Log("NULL");
                //}
                //else
                //{
                //    Debug.Log("found " + test.nodes.Count + " " + test.values.Count);
                //}
                //Debug.Log("btn font " + HighLogic.Skin.font +);// AGXBtnStyle.font + AGXBtnStyle.fontSize + AGXBtnStyle.fontStyle);
                //Debug.Log("End update!");
            }
            catch (Exception e)
            {
                print("AGX Update error: " + errLine + " " + e);
            }
        }
예제 #8
0
파일: Flight.cs 프로젝트: erendrake/AGExt
        public static ConfigNode FlightSaveToFile(ConfigNode origNode)  
        {
            //print("FlightSaveToFile " + AGXFlightNode);
            
            string errLine = "1";
            try
            {
                if (loadFinished)
                {
                    List<AGXAction> actionsToSave = new List<AGXAction>();
                    actionsToSave.AddRange(AllVesselsActions.Where(ag => ag.ba != null));
                    //foreach (AGXAction agAct in actionsToSave)
                    //{
                    //    print("FlightSave " + agAct.ba.name + " " + agAct.ba.listParent.part.ConstructID);
                    //}
                    if(loadedVessels.Contains(FlightGlobals.ActiveVessel))
                    {
                    ConfigNode thisVsl = new ConfigNode(FlightGlobals.ActiveVessel.id.ToString());
                    ConfigNode thisRootPart = new ConfigNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()); //copy values to root part save for future undockings
                    thisVsl.AddValue("name", FlightGlobals.ActiveVessel.vesselName);
                    thisRootPart.AddValue("name", thisVsl.GetValue("name")); //get the value from confignode rather then running all the calculations again, i think it's less processing
                    errLine = "13";
                    thisVsl.AddValue("currentKeyset", CurrentKeySet.ToString());
                    thisRootPart.AddValue("currentKeyset", thisVsl.GetValue("currentKeyset"));
                    errLine = "14";
                    thisVsl.AddValue("groupNames", SaveGroupNames(""));
                    thisRootPart.AddValue("groupNames", thisVsl.GetValue("groupNames"));
                    errLine = "15";
                    thisVsl.AddValue("groupVisibility", SaveGroupVisibility(""));
                    thisRootPart.AddValue("groupVisibility", thisVsl.GetValue("groupVisibility"));
                    errLine = "16";
                    thisVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                    thisRootPart.AddValue("groupVisibilityNames", thisVsl.GetValue("groupVisibilityNames"));
                    errLine = "17";

                        if(RootParts.HasNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()))
                        {
                            RootParts.RemoveNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString());
                        }
                        RootParts.AddNode(thisRootPart);
                        RootParts.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtRootParts.cfg");

                        


                    foreach (Part p in FlightGlobals.ActiveVessel.Parts)
                    {
                        List<AGXAction> thisPartsActions = new List<AGXAction>();
                        thisPartsActions.AddRange(actionsToSave.FindAll(p2 => p2.ba.listParent.part == p));
                        errLine = "18";
                        if (thisPartsActions.Count > 0)
                        {
                            //print("acts count " + thisPartsActions.Count);
                            ConfigNode partTemp = new ConfigNode("PART");
                            errLine = "19";
                            partTemp.AddValue("name", p.vessel.vesselName);
                            partTemp.AddValue("vesselID", p.vessel.id);
                            partTemp.AddValue("relLocX", p.orgPos.x);
                            partTemp.AddValue("relLocY", p.orgPos.y);
                            partTemp.AddValue("relLocZ", p.orgPos.z);
                            errLine = "20";
                            foreach (AGXAction agxAct in thisPartsActions)
                            {
                                //print("acts countb " + thisPartsActions.Count);
                                errLine = "21";
                                partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                            }
                            errLine = "22";

                            thisVsl.AddNode(partTemp);
                            errLine = "23";
                        }
                    }
                    if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString()))
                    {
                        AGXFlightNode.RemoveNode(FlightGlobals.ActiveVessel.id.ToString());
                    }
                    AGXFlightNode.AddNode(thisVsl);
                }
                    actionsToSave.RemoveAll(p3 => p3.ba.listParent.part.vessel == FlightGlobals.ActiveVessel);
                    //print("step1");

                    //foreach (AGXAction agAct in actionsToSave)
                    //{
                    //    print("FlightSaveFocusDone " + agAct.ba.name + " " + agAct.ba.listParent.part.ConstructID);
                    //}
                    //print("step2");
                    while (actionsToSave.Count > 0)
                    {
                        //print("step3");
                        //foreach (AGXAction agAct in actionsToSave)
                        //{
                        //    print("FlightSaveWhile " + agAct.ba.name + " " + agAct.ba.listParent.part.ConstructID);
                        //}
                        //print("step4");
                        Vessel vslToSave = actionsToSave.First().ba.listParent.part.vessel;
                        if(loadedVessels.Contains(vslToSave))
                        {
                        
                        ConfigNode thisVslNode = new ConfigNode(vslToSave.id.ToString());
                        if (AGXFlightNode.HasNode(vslToSave.id.ToString()))
                        {
                            thisVslNode = AGXFlightNode.GetNode(vslToSave.id.ToString());
                            thisVslNode.RemoveValue("name");
                            thisVslNode.AddValue("name", vslToSave.vesselName);
                        }
                        else
                        {
                            thisVslNode.AddValue("name", vslToSave.vesselName);
                            errLine = "13";
                            thisVslNode.AddValue("currentKeyset", "1");
                            errLine = "14";
                            thisVslNode.AddValue("groupNames", "");
                            errLine = "15";
                            thisVslNode.AddValue("groupVisibility", "");
                            errLine = "16";
                            thisVslNode.AddValue("groupVisibilityNames", "");
                        }
                        thisVslNode.RemoveNodes("PART");


                        foreach (Part p in vslToSave.parts)
                        {
                            List<AGXAction> thisPartsActions = new List<AGXAction>();
                            thisPartsActions.AddRange(actionsToSave.FindAll(p2 => p2.prt == p));
                            errLine = "18";
                            if (thisPartsActions.Count > 0)
                            {
                                ConfigNode partTemp = new ConfigNode("PART");
                                errLine = "19";
                                partTemp.AddValue("name", p.vessel.name);
                                partTemp.AddValue("vesselID", vslToSave.id.ToString());
                                partTemp.AddValue("relLocX", p.orgPos.x);
                                partTemp.AddValue("relLocY", p.orgPos.y);
                                partTemp.AddValue("relLocZ", p.orgPos.z);
                                errLine = "20";
                                foreach (AGXAction agxAct in thisPartsActions)
                                {
                                    errLine = "21";
                                    partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                                }
                                errLine = "22";

                                thisVslNode.AddNode(partTemp);
                                errLine = "23";
                            }
                        }
                        
                        if (AGXFlightNode.HasNode(vslToSave.id.ToString()))
                        {
                            AGXFlightNode.RemoveNode(vslToSave.id.ToString());
                        }
                        AGXFlightNode.AddNode(thisVslNode);
                        }
                        actionsToSave.RemoveAll(p3 => p3.ba.listParent.part.vessel == vslToSave);
                        if (vslToSave.loaded == false)
                        {
                            AllVesselsActions.RemoveAll(p4 => p4.ba.listParent.part.vessel == vslToSave);
                        }
                    }
                    //AGXBaseNode.RemoveNode("FLIGHT");
                    //AGXBaseNode.AddNode(AGXFlightNode);
                    //AGXBaseNode.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt.cfg");
                    return AGXFlightNode;
                }
                else
                {
                    return origNode;
                }
                //while(AllVesselsActions.Count>0)
                //{
                //    Vessel vslSaving = AllVesselsActions.First().prt.vessel;
                //    ConfigNode vslNode = new ConfigNode();

                //}
                //print("save 2g " + loadFinished + " " + AGXFlightNode);

                



                
            }
            catch (Exception e)
            {
                print("FlightSaveToFile error " + errLine + " " + e);
                return origNode;
            }
        }
예제 #9
0
파일: KAS_Shared.cs 프로젝트: ACCBizon/KAS
        public static ConfigNode SavePartSnapshot(Part part)
        {
            // Seems fine with a null vessel in 0.23 if some empty lists are allocated below
            ProtoPartSnapshot snapshot = new ProtoPartSnapshot(part, null);

            ConfigNode node = new ConfigNode("CONTENT_PART");

            snapshot.attachNodes = new List<AttachNodeSnapshot>();
            snapshot.srfAttachNode = new AttachNodeSnapshot("attach,-1");
            snapshot.symLinks = new List<ProtoPartSnapshot>();
            snapshot.symLinkIdxs = new List<int>();

            snapshot.Save(node);

            node.AddValue("kas_total_mass", part.mass+part.GetResourceMass());

            // Prune unimportant data
            node.RemoveValues("parent");
            node.RemoveValues("position");
            node.RemoveValues("rotation");
            node.RemoveValues("istg");
            node.RemoveValues("dstg");
            node.RemoveValues("sqor");
            node.RemoveValues("sidx");
            node.RemoveValues("attm");
            node.RemoveValues("srfN");
            node.RemoveValues("attN");
            node.RemoveValues("connected");
            node.RemoveValues("attached");
            node.RemoveValues("flag");

            node.RemoveNodes("ACTIONS");

            // Remove modules that are not in prefab since they won't load anyway
            var module_nodes = node.GetNodes("MODULE");
            var prefab_modules = part.partInfo.partPrefab.GetComponents<PartModule>();

            node.RemoveNodes("MODULE");

            for (int i = 0; i < prefab_modules.Length && i < module_nodes.Length; i++)
            {
                var module = module_nodes[i];
                var name = module.GetValue("name") ?? "";

                node.AddNode(module);

                if (name == "KASModuleContainer")
                {
                    // Containers get to keep their contents
                    module.RemoveNodes("EVENTS");
                }
                else if (name.StartsWith("KASModule"))
                {
                    // Prune the state of the KAS modules completely
                    module.ClearData();
                    module.AddValue("name", name);
                    continue;
                }

                module.RemoveNodes("ACTIONS");
            }

            return node;
        }
예제 #10
0
 //take data from VSM module Save routine and write to static data
 public static void SaveNodeData(VesselModuleSave vsm, ConfigNode node)
 {
     ConfigNode modNode = new ConfigNode(vsm.IDType()); //make our mod node, name is IDType
     if (VesselModuleConfigNodes.ContainsKey(vsm.IDType())) //do we already have an entry for this mod?
     {
         modNode = VesselModuleConfigNodes[vsm.IDType()]; //yes, refer to existing node
     }
     else
     {
         VesselModuleConfigNodes.Add(vsm.IDType(), modNode); //no, add mod to our mod list
     }
     if (modNode.HasNode(vsm.vessel.id.ToString())) //is this vessel already existant?
     {
         modNode.RemoveNodes(vsm.vessel.id.ToString()); //remove vessel if it exists, static node has old data in it
     }
     node.name = vsm.vessel.id.ToString();
     modNode.AddNode(node); //add node to static data, this adds to VesselModuleConfigNodes via reference
 }
예제 #11
0
        public override void OnSave(ConfigNode node)
        {
            string ErrLine = "1";
            //Debug.Log("AGX Saving Module start");
            try
            {
                node.RemoveNodes("ACTION");
                //node.RemoveNodes("TOGGLE");
                //node.RemoveNodes("HOLD");
                ErrLine = "2";
                List<AGXAction> actsToSave = new List<AGXAction>();
                ErrLine = "2a";
                actsToSave.AddRange(agxActionsThisPart);
                ErrLine = "2b";
                if (HighLogic.LoadedSceneIsEditor)
                {
                    //Debug.Log("AGX Editor save called by partmodule!");

                    ErrLine = "2c";

                    foreach (AGXAction agActSD in StaticData.CurrentVesselActions.Where(act => act.ba.listParent.part == this.part))
                    {
                        if (!actsToSave.Contains(agActSD))
                        {
                            actsToSave.Add(agActSD);
                        }
                    }
                }
                else if (HighLogic.LoadedSceneIsFlight)
                {
                    ErrLine = "2d";

                    foreach (AGXAction agActSD in StaticData.CurrentVesselActions.Where(act => act.ba.listParent.part == this.part))
                    {
                        if (!actsToSave.Contains(agActSD))
                        {
                            actsToSave.Add(agActSD);
                        }
                    }
                    //Debug.Log("AGX Partmodule Save action saved okay");
                }

                ErrLine = "3";
                foreach (AGXAction agAct in actsToSave)
                {
                    ErrLine = "4";
                    ConfigNode actionNode = new ConfigNode("ACTION");
                    ErrLine = "5";
                    if (agAct != null)
                    {
                        ErrLine = "5a";

                        actionNode = StaticData.SaveAGXActionVer2(agAct);
                    }
                    ErrLine = "6";
                    node.AddNode(actionNode);
                    ErrLine = "7";
                }
                //actions themselves are now saved
                ErrLine = "7a";
                if (HighLogic.LoadedSceneIsEditor)
                {
                    if (AGXEditor.LoadFinished)
                    {
                        //node.RemoveNodes("TOGGLE"); //not using confignode to save this stuff
                        //node.RemoveNodes("HOLD");
                        //ErrLine = "7b";

                        //ConfigNode toggleStates = new ConfigNode("TOGGLE");
                        //ConfigNode holdStates = new ConfigNode("HOLD");
                        //ErrLine = "7c";
                        //for (int i = 1; i <= 250; i++)
                        //{
                        //    ErrLine = "7ca";
                        //    if (AGXEditor.IsGroupToggle[i])
                        //    {
                        //        ErrLine = "7cb";
                        //        toggleStates.AddValue("toggle", i.ToString());
                        //    }
                        //    ErrLine = "7cc";
                        //    if (AGXEditor.isDirectAction[i])
                        //    {
                        //        ErrLine = "7cd";
                        //        holdStates.AddValue("hold", i.ToString());
                        //    }
                        //}
                        //ErrLine = "7d";
                        //node.AddNode(toggleStates);
                        //node.AddNode(holdStates);
                        //toggleNode = toggleStates;
                        //holdNode = holdStates;

                        node.SetValue("groupNames", AGXEditor.SaveGroupNames(""), true);
                        ErrLine = "7e";
                        node.SetValue("groupVisibility", AGXEditor.SaveGroupVisibility(""), true);
                        ErrLine = "7f";
                        node.SetValue("groupVisibilityNames", AGXEditor.SaveGroupVisibilityNames(""), true);
                        ErrLine = "7g";
                        node.SetValue("DirectActionState", AGXEditor.SaveDirectActionState(""), true);
                        node.SetValue("hasData", "true", true);
                    }
                }
                //else if (HighLogic.LoadedSceneIsFlight) //do not save data, we are not guaranteed to be the FLightGlobals.ActiveVessel
                //{
                //    //node.SetValue("groupNames", AGXFlight.SaveGroupNames(""), true);
                //    //ErrLine = "7e";
                //    //node.SetValue("groupVisibility", AGXFlight.SaveGroupVisibility(""), true);
                //    //ErrLine = "7f";
                //    //node.SetValue("groupVisibilityNames", AGXFlight.SaveGroupVisibilityNames(""), true);
                //    //ErrLine = "7g";
                //    //node.SetValue("DirectActionState", AGXFlight.SaveDirectActionState(""), true);
                //    //node.SetValue("hasData", "true", true);
                //}

                //Debug.Log("AGX PartModule Save Okay"); //temporary
                //Debug.Log("AGX Saving Module end" + StaticData.CurrentVesselActions.Count());
            }
            catch (Exception e)
            {
                print("AGX partModule OnSave fail: " + ErrLine + " " + e);
            }
        }
예제 #12
0
        public void SaveThisVessel()
        {
            string errLine = "1";
            try
            {
                if (vesselInstanceOK)
                {
                    ConfigNode thisVslNode = new ConfigNode(flightID.ToString());
                    errLine = "2";
                    if (AGXFlight.AGXFlightNode.HasNode(flightID.ToString()))
                    {
                        errLine = "3";
                        thisVslNode = AGXFlight.AGXFlightNode.GetNode(thisVsl.rootPart.flightID.ToString());
                        errLine = "4";
                        AGXFlight.AGXFlightNode.RemoveNode(thisVsl.rootPart.flightID.ToString());
                    }
                    errLine = "5";
                    thisVslNode.RemoveNodes("PART");
                    errLine = "6";
                    foreach (Part p in thisVsl.Parts)
                    {
                        errLine = "7";
                        List<AGXAction> thisPartsActions = new List<AGXAction>();
                        errLine = "8";
                        thisPartsActions.AddRange(actionsList.FindAll(p2 => p2.ba.listParent.part == p));
                        errLine = "18";
                        if (thisPartsActions.Count > 0)
                        {
                            //print("acts count " + thisPartsActions.Count);
                            ConfigNode partTemp = new ConfigNode("PART");
                            errLine = "19";
                            partTemp.AddValue("name", p.partInfo.name);
                            partTemp.AddValue("vesselName", p.vessel.vesselName);
                            //partTemp.AddValue("relLocX", FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position).x);
                            //partTemp.AddValue("relLocY", FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position).y);
                            //partTemp.AddValue("relLocZ", FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position).z);
                            partTemp.AddValue("flightID", p.flightID.ToString());
                            errLine = "20";
                            foreach (AGXAction agxAct in thisPartsActions)
                            {
                                //print("acts countb " + thisPartsActions.Count);
                                errLine = "21";
                                partTemp.AddNode(StaticData.SaveAGXActionVer2(agxAct));
                            }
                            errLine = "22";

                            thisVslNode.AddNode(partTemp);
                            errLine = "23";
                        }
                        errLine = "24";
                    }
                    errLine = "25";
                    if (AGXFlight.AGXFlightNode.HasNode(thisVsl.id.ToString()))
                    {
                        errLine = "26";
                        AGXFlight.AGXFlightNode.RemoveNode(thisVsl.id.ToString());
                    }
                    errLine = "27";
                    if (AGXFlight.AGXFlightNode.HasNode(thisVsl.rootPart.flightID.ToString()))
                    {
                        errLine = "28";
                        AGXFlight.AGXFlightNode.RemoveNode(thisVsl.rootPart.flightID.ToString());
                    }
                    errLine = "29";
                    //print("save node " + thisVsl);
                    AGXFlight.AGXFlightNode.AddNode(thisVslNode);
                }
            }
            catch (Exception e)
            {
                Debug.Log("AGX OtherVslSaveNode Fail " + errLine + " " + e);
            }
        }
예제 #13
0
파일: Flight.cs 프로젝트: erendrake/AGExt
        public void VesselOnRails(Vessel vsl)
        {
            print("Vessel on rails! " + vsl.name );
            partOldVessel.RemoveAll(vsl2 => vsl2.pVsl == vsl);
            List<AGXAction> UnloadVslActionsCheck = new List<AGXAction>();
            UnloadVslActionsCheck.AddRange(AllVesselsActions.Where(agx => agx.ba.listParent.part.vessel == vsl));
            //print("count check " + UnloadVslActionsCheck.Count + vsl.id.ToString());
            //foreach (AGXAction agact in UnloadVslActionsCheck)
            //{
            //    print("actionunload " + agact.ba.listParent.part.vessel.id.ToString() + " " + agact.ba.listParent.part.ConstructID);
            //}
            if (UnloadVslActionsCheck.Count > 0)
            {
                ConfigNode vslToUnload = new ConfigNode(vsl.id.ToString());
                if(AGXFlightNode.HasNode(vsl.id.ToString()))
                {
                    vslToUnload = AGXFlightNode.GetNode(vsl.id.ToString());
                    vslToUnload.RemoveNodes("PART");
                    AGXFlightNode.RemoveNode(vsl.id.ToString());
                }

                if (vsl == FlightGlobals.ActiveVessel)
                {
                    if(vslToUnload.HasValue("name"))
                    {
                        vslToUnload.RemoveValue("name");
                    }
                    vslToUnload.AddValue("name",FlightGlobals.ActiveVessel.vesselName);
                    if (vslToUnload.HasValue("currentKeyset"))
                    {
                        vslToUnload.RemoveValue("currentKeyset");
                    }
                    vslToUnload.AddValue("currentKeyset", CurrentKeySet.ToString());
                    if (vslToUnload.HasValue("groupNames"))
                    {
                        vslToUnload.RemoveValue("groupNames");
                    }
                    vslToUnload.AddValue("groupNames", SaveGroupNames(""));
                    if (vslToUnload.HasValue("groupVisibility"))
                    {
                        vslToUnload.RemoveValue("groupVisibility");
                    }
                    vslToUnload.AddValue("groupVisibility", SaveGroupVisibility(""));
                    if (vslToUnload.HasValue("groupVisibilityNames"))
                    {
                        vslToUnload.RemoveValue("groupVisibilityNames");
                    }
                    vslToUnload.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                }

                foreach (Part p in vsl.Parts)
                {
                    List<AGXAction> thisPartsActions = new List<AGXAction>();
                    thisPartsActions.AddRange(UnloadVslActionsCheck.FindAll(p2 => p2.ba.listParent.part == p));
                    //errLine = "18";
                    if (thisPartsActions.Count > 0)
                    {
                        ConfigNode partTemp = new ConfigNode("PART");
                        //errLine = "19";
                        partTemp.AddValue("name", p.vessel.vesselName);
                        partTemp.AddValue("vesselID", p.vessel.id);
                        partTemp.AddValue("relLocX", p.orgPos.x);
                        partTemp.AddValue("relLocY", p.orgPos.y);
                        partTemp.AddValue("relLocZ", p.orgPos.z);
                        //errLine = "20";
                        foreach (AGXAction agxAct in thisPartsActions)
                        {
                            //errLine = "21";
                            partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                        }
                       // errLine = "22";

                        vslToUnload.AddNode(partTemp);
                        //errLine = "23";
                    }
                }
                AGXFlightNode.AddNode(vslToUnload);
            }
            AllVesselsActions.RemoveAll(act2 => act2.ba.listParent.part.vessel == vsl);
            loadedVessels.Remove(vsl); //remove vessel from loaded vessels list

        }
예제 #14
0
        public override void OnSave(ConfigNode node)
        {
            base.OnSave(node);
            ConfigNode efficiencyNode;

            if (node.HasValue("reputationIndex"))
                node.SetValue("reputationIndex", reputationIndex.ToString());
            else
                node.AddValue("reputationIndex", reputationIndex.ToString());

            foreach (EfficiencyData data in efficiencyDataMap.Values)
            {
                efficiencyNode = new ConfigNode(kEfficiencyData);
                data.Save(efficiencyNode);
                node.AddNode(efficiencyNode);
            }

            node.RemoveNodes(kToolTip);
            foreach (ConfigNode toolTipNode in toolTips.Values)
                node.AddNode(toolTipNode);
        }
예제 #15
0
 public override void OnSave(ConfigNode node)
 {
     node.RemoveNodes("ScienceData"); //** Prevent duplicates
     foreach (ScienceData SCANData in storedData)
     {
         ConfigNode storedDataNode = node.AddNode("ScienceData");
         SCANData.Save(storedDataNode);
     }
 }
 public override void OnSave(ConfigNode node)
 {
     node.RemoveNodes("ScienceData");
     foreach (ScienceData storedData in storedScienceReports)
     {
         ConfigNode storedDataNode = node.AddNode("ScienceData");
         storedData.Save(storedDataNode);
     }
 }
예제 #17
0
        //call this when part count on vessel decrease to check for actions on split vessels
        public void CheckListForMultipleVessels()
        {
            //print("call checklistformulti");
            List<Vessel> curActsVessels = new List<Vessel>(); //find out if actions exist on vessel that left
            foreach (AGXAction agAct in StaticData.CurrentVesselActions)
            {
                if (!curActsVessels.Contains(agAct.ba.listParent.part.vessel))
                {
                    curActsVessels.Add(agAct.ba.listParent.part.vessel); //make a list of all vessels from actions in currentVesselActions list
                }
            }

            foreach (Vessel vsl2 in curActsVessels) //our list of vessels from actions in currentVesselActions lsit
            {
                if (vsl2 != FlightGlobals.ActiveVessel) //this runs only on the seperated vessel, not our focus vessel
                {
                    ConfigNode vsl2node = new ConfigNode(vsl2.rootPart.flightID.ToString()); //make our confignode
                    if (AGXFlightNode.HasNode(vsl2.rootPart.flightID.ToString())) //does this vessel exist in flight node?
                    {
                        vsl2node = AGXFlightNode.GetNode(vsl2.rootPart.flightID.ToString()); //vessel exists?  load existing node, this should not happend but might if the same vessel docks/undocks in the same scene multiple times
                        vsl2node.RemoveNodes("PART");
                        AGXFlightNode.RemoveNode(vsl2.rootPart.flightID.ToString());
                    }
                    else if (AGXFlightNode.HasNode(vsl2.id.ToString())) //does this vessel exist in flight node?
                    {
                        vsl2node = AGXFlightNode.GetNode(vsl2.id.ToString()); //vessel exists?  load existing node, this should not happend but might if the same vessel docks/undocks in the same scene multiple times
                        vsl2node.RemoveNodes("PART");
                        AGXFlightNode.RemoveNode(vsl2.id.ToString());
                    }
                    //RootPart elseif check here
                    else //new vessel, copy current values
                    {
                        vsl2node.AddValue("name", FlightGlobals.ActiveVessel.vesselName);
                        vsl2node.AddValue("currentKeyset", CurrentKeySetFlight.ToString());
                        //vsl2node.AddValue("groupNames", SaveGroupNames(""));
                        vsl2node.AddValue("groupVisibility", SaveGroupVisibility(""));
                        vsl2node.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                        vsl2node.AddValue("DirectActionState", SaveDirectActionState(""));
                    }
                    if (vsl2node.HasValue("groupNames"))
                    {
                        vsl2node.RemoveValue("groupNames");
                    }
                    vsl2node.AddValue("groupNames", SaveGroupNames(""));
                    foreach (Part p in vsl2.Parts) //cycle parts in separated vessel to find actions
                    {
                        List<AGXAction> thisPartsActions = new List<AGXAction>();
                        thisPartsActions.AddRange(StaticData.CurrentVesselActions.FindAll(p2 => p2.ba.listParent.part == p));
                        //errLine = "18";
                        if (thisPartsActions.Count > 0)
                        {
                            //print("acts count " + thisPartsActions.Count);
                            ConfigNode partTemp = new ConfigNode("PART");
                            //errLine = "19";
                            partTemp.AddValue("name", p.vessel.vesselName);
                            partTemp.AddValue("vesselID", p.vessel.id);
                            partTemp.AddValue("flightID", p.flightID.ToString());
                            // partTemp.AddValue("relLocX", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).x);
                            //partTemp.AddValue("relLocY", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).y);
                            //partTemp.AddValue("relLocZ", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).z);
                            //errLine = "20";
                            foreach (AGXAction agxAct in thisPartsActions)
                            {
                                //print("acts countb " + thisPartsActions.Count);
                                //errLine = "21";
                                partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                            }
                            //errLine = "22";

                            vsl2node.AddNode(partTemp);
                            //errLine = "23";
                        }
                    }

                    AGXFlightNode.AddNode(vsl2node);
                    StaticData.CurrentVesselActions.RemoveAll(ag => ag.ba.listParent.part.vessel == vsl2);

                }
            }
            RefreshCurrentActions();
        }
예제 #18
0
        public static ConfigNode PartSnapshot(Part part)
        {
            ConfigNode node = new ConfigNode("PART");
            ProtoPartSnapshot snapshot = null;
            try
            {
                // Seems fine with a null vessel in 0.23 if some empty lists are allocated below
                snapshot = new ProtoPartSnapshot(part, null);
            }
            catch
            {
                // workaround for command module
                KIS_Shared.DebugWarning("Error during part snapshot, spawning part for snapshot (workaround for command module)");
                Part p = (Part)UnityEngine.Object.Instantiate(part.partInfo.partPrefab);
                p.gameObject.SetActive(true);
                p.name = part.partInfo.name;
                p.InitializeModules();
                snapshot = new ProtoPartSnapshot(p, null);
                UnityEngine.Object.Destroy(p.gameObject);
            }
            snapshot.attachNodes = new List<AttachNodeSnapshot>();
            snapshot.srfAttachNode = new AttachNodeSnapshot("attach,-1");
            snapshot.symLinks = new List<ProtoPartSnapshot>();
            snapshot.symLinkIdxs = new List<int>();
            snapshot.Save(node);

            // Prune unimportant data
            node.RemoveValues("parent");
            node.RemoveValues("position");
            node.RemoveValues("rotation");
            node.RemoveValues("istg");
            node.RemoveValues("dstg");
            node.RemoveValues("sqor");
            node.RemoveValues("sidx");
            node.RemoveValues("attm");
            node.RemoveValues("srfN");
            node.RemoveValues("attN");
            node.RemoveValues("connected");
            node.RemoveValues("attached");
            node.RemoveValues("flag");

            node.RemoveNodes("ACTIONS");

            // Remove modules that are not in prefab since they won't load anyway
            var module_nodes = node.GetNodes("MODULE");
            var prefab_modules = part.partInfo.partPrefab.GetComponents<PartModule>();
            node.RemoveNodes("MODULE");

            for (int i = 0; i < prefab_modules.Length && i < module_nodes.Length; i++)
            {
                var module = module_nodes[i];
                var name = module.GetValue("name") ?? "";

                node.AddNode(module);

                if (name == "KASModuleContainer")
                {
                    // Containers get to keep their contents
                    module.RemoveNodes("EVENTS");
                }
                else if (name.StartsWith("KASModule"))
                {
                    // Prune the state of the KAS modules completely
                    module.ClearData();
                    module.AddValue("name", name);
                    continue;
                }

                module.RemoveNodes("ACTIONS");
            }

            return node;
        }
예제 #19
0
        public override void OnSave(ConfigNode node)
        {
            string ErrLine = "1";
            //Debug.Log("AGX Saving Module start" + StaticData.CurrentVesselActions.Count());
            try
            {
                node.RemoveNodes("ACTION");
                node.RemoveNodes("TOGGLE");
                node.RemoveNodes("HOLD");
                ErrLine = "2";
                List<AGXAction> actsToSave = new List<AGXAction>();
                ErrLine = "2a";
                actsToSave.AddRange(agxActionsThisPart);
                ErrLine = "2b";
                if(HighLogic.LoadedSceneIsEditor)
                {
                    ErrLine = "2c";
                    actsToSave.AddRange(StaticData.CurrentVesselActions.Where(act => act.ba.listParent.part == this.part));
                }
                else if(HighLogic.LoadedSceneIsFlight)
                {
                    ErrLine = "2d";
                    //if (StaticData.CurrentVesselActions == null)
                    //{
                    //    Debug.Log("AGX Partmodule Save CurrentVessels is null");
                     //}
                    //else
                    //{
                    //    Debug.Log("AGX Partmodule Save CurrentVessels is not null");
                    //}
                    //foreach (AGXAction testAct in StaticData.CurrentVesselActions)
                    //{
                    //    if(testAct == null)
                    //    {
                    //        Debug.Log("AGX Partmodule Save current action is null");
                    //    }
                    //    else
                    //    {
                    //        Debug.Log("AGX Partmodule Save action " + testAct.ToString());
                    //    }
                    //    if(testAct.ba.listParent.part == this.part)
                    //    {
                    //        Debug.Log("AGX Partmodule Save actions is on this part");
                    //    }
                    //    else
                    //    {
                    //        Debug.Log("AGX Partmodule Save actions is NOT on this part");
                    //    }
                    //}

                    actsToSave.AddRange(StaticData.CurrentVesselActions.Where(act => act.ba.listParent.part == this.part));
                    //Debug.Log("AGX Partmodule Save action saved okay");
                }

                    ErrLine = "3";
                    foreach (AGXAction agAct in actsToSave)
                    {
                        ErrLine = "4";
                        ConfigNode actionNode = new ConfigNode("ACTION");
                        ErrLine = "5";
                        if (agAct != null)
                        {
                            ErrLine = "5a";
                            actionNode = AGextScenario.SaveAGXActionVer2(agAct);
                        }
                        ErrLine = "6";
                        node.AddNode(actionNode);
                        ErrLine = "7";
                    }

                if (HighLogic.LoadedSceneIsEditor)
                {
                    ConfigNode toggleStates = new ConfigNode("TOGGLE");
                    ConfigNode holdStates = new ConfigNode("HOLD");
                    for (int i = 1; i <= 250; i++)
                    {
                        if (AGXEditor.IsGroupToggle[i])
                        {
                            toggleStates.AddValue("toggle", i.ToString());
                        }
                        if (AGXEditor.isDirectAction[i])
                        {
                            holdStates.AddValue("hold", i.ToString());
                        }
                    }
                    node.AddNode(toggleStates);
                    node.AddNode(holdStates);
                }
                //Debug.Log("AGX PartModule Save Okay"); //temporary
                //Debug.Log("AGX Saving Module end" + StaticData.CurrentVesselActions.Count());
            }
            catch (Exception e)
            {
                print("AGX partModule OnSave fail: " + ErrLine + " " + e);
            }
        }