public override void OnSave(ConfigNode node)
        {
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }

            // Boolean error = false;
            KCTDebug.Log("Writing to persistence.");
            base.OnSave(node);
            KCT_DataStorage kctVS = new KCT_DataStorage();

            node.AddNode(kctVS.AsConfigNode());
            foreach (KCT_KSC KSC in KCT_GameStates.KSCs)
            {
                if (KSC != null && KSC.KSCName != null && KSC.KSCName.Length > 0)
                {
                    node.AddNode(KSC.AsConfigNode());
                }
            }
            ConfigNode tech = new ConfigNode("TechList");

            foreach (KCT_TechItem techItem in KCT_GameStates.TechList)
            {
                KCT_TechStorageItem techNode = new KCT_TechStorageItem();
                techNode.FromTechItem(techItem);
                ConfigNode cnTemp = new ConfigNode("Tech");
                cnTemp = ConfigNode.CreateConfigFromObject(techNode, cnTemp);
                ConfigNode protoNode = new ConfigNode("ProtoNode");
                techItem.protoNode.Save(protoNode);
                cnTemp.AddNode(protoNode);
                tech.AddNode(cnTemp);
            }
            node.AddNode(tech);
        }
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            LoadTree();
#if KSP1_4
            // 1.4 Addition
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }
#endif
            KCTDebug.Log("Reading from persistence.");
            KCT_GameStates.KSCs.Clear();
            KCT_GameStates.ActiveKSC = null;
            //KCT_Utilities.SetActiveKSC("Stock");
            KCT_GameStates.InitAndClearTechList();
            KCT_GameStates.TechUpgradesTotal = 0;
            KCT_GameStates.SciPointsTotal    = -1;

            KCT_DataStorage kctVS = new KCT_DataStorage();
            ConfigNode      CN    = node.GetNode(kctVS.GetType().Name);
            if (CN != null)
            {
                ConfigNode.LoadObjectFromConfig(kctVS, CN);
            }

            foreach (ConfigNode ksc in node.GetNodes("KSC"))
            {
                string  name       = ksc.GetValue("KSCName");
                KCT_KSC loaded_KSC = new KCT_KSC(name);
                loaded_KSC.FromConfigNode(ksc);
                if (loaded_KSC != null && loaded_KSC.KSCName != null && loaded_KSC.KSCName.Length > 0)
                {
                    loaded_KSC.RDUpgrades[1] = KCT_GameStates.TechUpgradesTotal;
                    if (KCT_GameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                    {
                        KCT_GameStates.KSCs.Add(loaded_KSC);
                    }
                }
            }
            KCT_Utilities.SetActiveKSCToRSS();


            ConfigNode tmp = node.GetNode("TechList");
            if (tmp != null)
            {
                foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                {
                    KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem();
                    ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                    KCT_TechItem techItem = techStorageItem.ToTechItem();
                    techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                    KCT_GameStates.TechList.Add(techItem);
                }
            }

            KCT_GUI.CheckToolbar();
            KCT_GameStates.erroredDuringOnLoad.OnLoadFinish();
            //KerbalConstructionTime.DelayedStart();
        }
Exemple #3
0
        public override void OnSave(ConfigNode node)
        {
            if (Utilities.CurrentGameIsMission())
            {
                return;
            }

            KCTDebug.Log("Writing to persistence.");
            base.OnSave(node);
            var kctVS = new KCT_DataStorage();

            node.AddNode(kctVS.AsConfigNode());
            foreach (KSCItem KSC in KCTGameStates.KSCs.Where(x => x?.KSCName?.Length > 0))
            {
                node.AddNode(KSC.AsConfigNode());
            }
            var tech = new ConfigNode("TechList");

            foreach (TechItem techItem in KCTGameStates.TechList)
            {
                var techNode = new KCT_TechStorageItem();
                techNode.FromTechItem(techItem);
                var cnTemp = new ConfigNode("Tech");
                cnTemp = ConfigNode.CreateConfigFromObject(techNode, cnTemp);
                var protoNode = new ConfigNode("ProtoNode");
                techItem.ProtoNode.Save(protoNode);
                cnTemp.AddNode(protoNode);
                tech.AddNode(cnTemp);
            }
            node.AddNode(tech);

            KCT_GUI.GuiDataSaver.Save();
        }
Exemple #4
0
 // [Persistent] ConfigNode techNode = new ConfigNode();
 public override void OnEncodeToConfigNode()
 {
     base.OnEncodeToConfigNode();
     techBuildList.Clear();
     foreach (KCT_TechItem tech in GameStates.TechList)
     {
         KCT_TechStorageItem tSI = new KCT_TechStorageItem();
         techBuildList.Add(tSI.FromTechItem(tech));
     }
 }
Exemple #5
0
        public override void OnLoad(ConfigNode node)
        {
            KCTDebug.Log("Reading from persistence.");
            base.OnLoad(node);
            KCT_GameStates.KSCs.Clear();
            KCT_GameStates.ActiveKSC = null;
            //KCT_Utilities.SetActiveKSC("Stock");
            KCT_GameStates.TechList.Clear();
            KCT_GameStates.TechUpgradesTotal = 0;

            KCT_DataStorage kctVS = new KCT_DataStorage();
            ConfigNode      CN    = node.GetNode(kctVS.GetType().Name);

            if (CN != null)
            {
                ConfigNode.LoadObjectFromConfig(kctVS, CN);
            }

            foreach (ConfigNode ksc in node.GetNodes("KSC"))
            {
                string  name       = ksc.GetValue("KSCName");
                KCT_KSC loaded_KSC = new KCT_KSC(name);
                loaded_KSC.FromConfigNode(ksc);
                if (loaded_KSC != null && loaded_KSC.KSCName != null && loaded_KSC.KSCName.Length > 0)
                {
                    loaded_KSC.RDUpgrades[1] = KCT_GameStates.TechUpgradesTotal;
                    if (KCT_GameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                    {
                        KCT_GameStates.KSCs.Add(loaded_KSC);
                    }
                }
            }
            //KCT_Utilities.SetActiveKSCToRSS();
            KCT_Utilities.SetActiveKSC(KCT_GameStates.activeKSCName);


            ConfigNode tmp = node.GetNode("TechList");

            if (tmp != null)
            {
                foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                {
                    KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem();
                    ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                    KCT_TechItem techItem = techStorageItem.ToTechItem();
                    techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                    KCT_GameStates.TechList.Add(techItem);
                }
            }
            //KCT_GameStates.ActiveKSC.AsConfigNode().Save(KSPUtil.ApplicationRootPath + "/KSC.node");

            KerbalConstructionTime.DelayedStart();
            KCT_GUI.CheckToolbar();
            KCT_GameStates.erroredDuringOnLoad.OnLoadFinish();
        }
Exemple #6
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            LoadTree();

            if (Utilities.CurrentGameIsMission())
            {
                return;
            }

            KCTDebug.Log("Reading from persistence.");
            KCTGameStates.KSCs.Clear();
            KCTGameStates.ActiveKSC = null;
            KCTGameStates.InitAndClearTechList();
            KCTGameStates.TechUpgradesTotal = 0;
            KCTGameStates.SciPointsTotal    = -1;
            KCT_GUI.ResetUpgradePointCounts();

            var        kctVS = new KCT_DataStorage();
            ConfigNode cn    = node.GetNode(kctVS.GetType().Name);

            if (cn != null)
            {
                ConfigNode.LoadObjectFromConfig(kctVS, cn);
            }

            bool foundStockKSC = false;

            foreach (ConfigNode ksc in node.GetNodes("KSC"))
            {
                string name       = ksc.GetValue("KSCName");
                var    loaded_KSC = new KSCItem(name);
                loaded_KSC.FromConfigNode(ksc);
                if (loaded_KSC != null && loaded_KSC.KSCName != null && loaded_KSC.KSCName.Length > 0)
                {
                    loaded_KSC.RDUpgrades[1] = KCTGameStates.TechUpgradesTotal;
                    if (KCTGameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                    {
                        KCTGameStates.KSCs.Add(loaded_KSC);
                    }
                    foundStockKSC |= string.Equals(loaded_KSC.KSCName, Utilities._legacyDefaultKscId, StringComparison.OrdinalIgnoreCase);
                }
            }

            Utilities.SetActiveKSCToRSS();
            if (foundStockKSC)
            {
                TryMigrateStockKSC();
            }

            var protoTechNodes      = new Dictionary <string, ProtoTechNode>(); // list of all the protoTechNodes that have been researched
            var inDevProtoTechNodes = new Dictionary <string, ProtoTechNode>(); // list of all the protoTechNodes that are being researched

            // get the TechList node containing the TechItems with the tech nodes currently being researched from KCT's ConfigNode
            if (node.GetNode("TechList") is ConfigNode tmp)
            {
                foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                {
                    var techStorageItem = new KCT_TechStorageItem();
                    ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                    TechItem techItem = techStorageItem.ToTechItem();
                    techItem.ProtoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                    KCTGameStates.TechList.Add(techItem);

                    // save proto nodes that are in development
                    inDevProtoTechNodes.Add(techItem.ProtoNode.techID, techItem.ProtoNode);
                }
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                // get the nodes that have been researched from ResearchAndDevelopment
                protoTechNodes = Utilities.GetUnlockedProtoTechNodes();
                // iterate through all loaded parts to check if any of them should be experimental
                foreach (AvailablePart ap in PartLoader.LoadedPartsList)
                {
                    if (Utilities.PartIsUnlockedButNotPurchased(protoTechNodes, ap) || inDevProtoTechNodes.ContainsKey(ap.TechRequired))
                    {
                        Utilities.AddExperimentalPart(ap);
                    }
                }
            }

            KCTGameStates.ErroredDuringOnLoad.OnLoadFinish();
        }
        public override void OnLoad(ConfigNode node)
        {
            KCTDebug.Log("Reading from persistence.");
            base.OnLoad(node);
            KCT_GameStates.KSCs.Clear();
            KCT_GameStates.ActiveKSC = null;
            //KCT_Utilities.SetActiveKSC("Stock");
            KCT_GameStates.TechList.Clear();
            KCT_GameStates.TechUpgradesTotal = 0;

            KCT_DataStorage kctVS = new KCT_DataStorage();
            ConfigNode CN = node.GetNode(kctVS.GetType().Name);
            if (CN != null)
                ConfigNode.LoadObjectFromConfig(kctVS, CN);

            foreach (ConfigNode ksc in node.GetNodes("KSC"))
            {
                string name = ksc.GetValue("KSCName");
                KCT_KSC loaded_KSC = new KCT_KSC(name);
                loaded_KSC.FromConfigNode(ksc);
                if (loaded_KSC != null && loaded_KSC.KSCName != null && loaded_KSC.KSCName.Length > 0)
                {
                    loaded_KSC.RDUpgrades[1] = KCT_GameStates.TechUpgradesTotal;
                    if (KCT_GameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                        KCT_GameStates.KSCs.Add(loaded_KSC);
                }
            }
            KCT_Utilities.SetActiveKSCToRSS();
            //KCT_Utilities.SetActiveKSC(KCT_GameStates.activeKSCName);

            ConfigNode tmp = node.GetNode("TechList");
            if (tmp != null)
            {
                foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                {
                    KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem();
                    ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                    KCT_TechItem techItem = techStorageItem.ToTechItem();
                    techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                    KCT_GameStates.TechList.Add(techItem);
                }
            }
            //KCT_GameStates.ActiveKSC.AsConfigNode().Save(KSPUtil.ApplicationRootPath + "/KSC.node");

            KerbalConstructionTime.DelayedStart();
            KCT_GUI.CheckToolbar();
            KCT_GameStates.erroredDuringOnLoad.OnLoadFinish();
        }
 public override void OnSave(ConfigNode node)
 {
     // Boolean error = false;
     KCTDebug.Log("Writing to persistence.");
     base.OnSave(node);
     KCT_DataStorage kctVS = new KCT_DataStorage();
     node.AddNode(kctVS.AsConfigNode());
     foreach (KCT_KSC KSC in KCT_GameStates.KSCs)
     {
         if (KSC != null && KSC.KSCName != null && KSC.KSCName.Length > 0)
             node.AddNode(KSC.AsConfigNode());
     }
     ConfigNode tech = new ConfigNode("TechList");
     foreach (KCT_TechItem techItem in KCT_GameStates.TechList)
     {
         KCT_TechStorageItem techNode = new KCT_TechStorageItem();
         techNode.FromTechItem(techItem);
         ConfigNode cnTemp = new ConfigNode("Tech");
         cnTemp = ConfigNode.CreateConfigFromObject(techNode, cnTemp);
         ConfigNode protoNode = new ConfigNode("ProtoNode");
         techItem.protoNode.Save(protoNode);
         cnTemp.AddNode(protoNode);
         tech.AddNode(cnTemp);
     }
     node.AddNode(tech);
 }
 // [Persistent] ConfigNode techNode = new ConfigNode();
 public override void OnEncodeToConfigNode()
 {
     base.OnEncodeToConfigNode();
     techBuildList.Clear();
     foreach (KCT_TechItem tech in KCT_GameStates.TechList)
     {
         KCT_TechStorageItem tSI = new KCT_TechStorageItem();
         techBuildList.Add(tSI.FromTechItem(tech));
     }
 }
Exemple #10
0
        public override void OnLoad(ConfigNode node)
        {
            try
            {
                base.OnLoad(node);
                LoadTree();

                if (Utilities.CurrentGameIsMission())
                {
                    return;
                }

                KCTDebug.Log("Reading from persistence.");
                KCTGameStates.KSCs.Clear();
                KCTGameStates.ActiveKSC = null;
                KCTGameStates.InitAndClearTechList();
                KCTGameStates.TechUpgradesTotal = 0;
                KCTGameStates.SciPointsTotal    = -1;
                KCT_GUI.ResetUpgradePointCounts();

                var kctVS = new KCT_DataStorage();
                if (node.GetNode(kctVS.GetType().Name) is ConfigNode cn)
                {
                    ConfigNode.LoadObjectFromConfig(kctVS, cn);
                }

                bool foundStockKSC = false;
                foreach (ConfigNode ksc in node.GetNodes("KSC"))
                {
                    string name       = ksc.GetValue("KSCName");
                    var    loaded_KSC = new KSCItem(name);
                    loaded_KSC.FromConfigNode(ksc);
                    if (loaded_KSC?.KSCName?.Length > 0)
                    {
                        loaded_KSC.RDUpgrades[1] = KCTGameStates.TechUpgradesTotal;
                        if (KCTGameStates.KSCs.Find(k => k.KSCName == loaded_KSC.KSCName) == null)
                        {
                            KCTGameStates.KSCs.Add(loaded_KSC);
                        }
                        foundStockKSC |= string.Equals(loaded_KSC.KSCName, Utilities._legacyDefaultKscId, StringComparison.OrdinalIgnoreCase);
                    }
                }

                Utilities.SetActiveKSCToRSS();
                if (foundStockKSC)
                {
                    TryMigrateStockKSC();
                }

                var protoTechNodes      = new Dictionary <string, ProtoTechNode>(); // list of all the protoTechNodes that have been researched
                var inDevProtoTechNodes = new Dictionary <string, ProtoTechNode>(); // list of all the protoTechNodes that are being researched

                // get the TechList node containing the TechItems with the tech nodes currently being researched from KCT's ConfigNode
                if (node.GetNode("TechList") is ConfigNode tmp)
                {
                    foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
                    {
                        var techStorageItem = new KCT_TechStorageItem();
                        ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                        TechItem techItem = techStorageItem.ToTechItem();
                        techItem.ProtoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                        KCTGameStates.TechList.Add(techItem);

                        // save proto nodes that are in development
                        inDevProtoTechNodes.Add(techItem.ProtoNode.techID, techItem.ProtoNode);
                    }
                }
                if (HighLogic.LoadedSceneIsEditor)
                {
                    // get the nodes that have been researched from ResearchAndDevelopment
                    protoTechNodes = Utilities.GetUnlockedProtoTechNodes();
                    // iterate through all loaded parts to check if any of them should be experimental
                    foreach (AvailablePart ap in PartLoader.LoadedPartsList)
                    {
                        if (Utilities.PartIsUnlockedButNotPurchased(protoTechNodes, ap) || inDevProtoTechNodes.ContainsKey(ap.TechRequired))
                        {
                            Utilities.AddExperimentalPart(ap);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                KCTGameStates.ErroredDuringOnLoad = true;
                Debug.LogError("[KCT] ERROR! An error while KCT loading data occurred. Things will be seriously broken!");
                PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "errorPopup", "Error Loading KCT Data", "ERROR! An error occurred while loading KCT data. Things will be seriously broken! Please report this error to LRTR GitHub and attach the log file. The game will be UNPLAYABLE in this state!", "Understood", false, HighLogic.UISkin);
            }
        }