示例#1
0
        static public KeoCacheCollection LoadKeoCacheData(string fname)
        {
            KeoCacheCollection keoCache = null;

            Log.Info("LoadKeoCacheData, file:" + fname);
            if (File.Exists(fname))
            {
                Log.Info("File exists");

                ConfigNode file = ConfigNode.Load(fname);
                if (file != null)
                {
                    ConfigNode loadedCollectionNode = file.GetNode(KEOCACHE_COLLECTION);

                    if (loadedCollectionNode != null)
                    {
                        keoCache = KeoCacheCollection.LoadCollectionFromConfigNode(loadedCollectionNode);
                    }
                    else
                    {
                        Log.Info("loadedCollectionNode is null");
                    }
                }
                else
                {
                    Log.Info("Error loading file: " + fname);
                }
            }
            return(keoCache);
        }
示例#2
0
        public override void OnLoad(ConfigNode node)
        {
            Log.Info("KeoTravelBugModule.OnLoad");
            if (this.vessel != null)
            {
                Log.Info("vessel: " + this.vessel.vesselName);
            }
            ConfigNode loadedCollectionNode = node.GetNode(FileIO.KEOCACHE_COLLECTION);

            if (loadedCollectionNode != null)
            {
                Log.Info("OnLoad Loading KeoCacheCollection");
                tbKcc = KeoCacheCollection.LoadCollectionFromConfigNode(loadedCollectionNode);
            }
            base.OnLoad(node);
        }
示例#3
0
        public override void OnSave(ConfigNode node)
        {
            base.OnSave(node);
            Log.Info("KeoTravelBugModule.OnSave");
            if (this.vessel != null)
            {
                Log.Info("vessel: " + this.vessel.vesselName);
            }
            if (tbKcc != null)
            {
                Log.Info("OnSave Saving KeoCacheCollection, keocacheCollectionData.name: " + tbKcc.keocacheCollectionData.name);
                ConfigNode n = KeoCacheCollection.SaveCollectionToConfigNode(tbKcc);
                Log.Info("OnSave 2");
                var t = KeoCacheCollection.LoadCollectionFromConfigNode(n);

                node.RemoveNodes(FileIO.KEOCACHE_COLLECTION); // probably not necessory
                node.AddNode(FileIO.KEOCACHE_COLLECTION, n);
            }
            else
            {
                Log.Info("In OnSave, tbKss is null");
            }
        }
示例#4
0
        void LoadScenarios(ConfigNode node)
        {
#if false
            Log.Info("LoadScenarios");
            if (node.HasNode(SCENARIO))
            {
                activeKeoCacheCollections = new Dictionary <string, KeoCacheCollection>();

                var gNode = node.GetNode(SCENARIO);
                if (gNode != null)
                {
                    var aNode = gNode.GetNodes();

                    for (int i = 0; i < aNode.Length; i++)
                    {
                        ConfigNode loadedCollectionNode = aNode[i].GetNode(FileIO.KEOCACHE_COLLECTION);
                        var        cache = KeoCacheCollection.LoadCollectionFromConfigNode(loadedCollectionNode);
                        if (cache != null)
                        {
                            Log.Info("LoadScenarios, adding collectionId: " + cache.keocacheCollectionData.collectionId);
                            KeoScenario.activeKeoCacheCollections.Add(cache.keocacheCollectionData.collectionId, cache);
                        }
                    }
                }
#endif
        }

#if false
        void LoadTravelBugs(ConfigNode node)
        {
            if (node.HasNode(SCENARIO))
            {
                travelBugs = new Dictionary <string, TravelBug>();
                var bNode = node.GetNode(TRAVELBUGS);
                if (bNode != null)
                {
                    var bNodes = bNode.GetNodes();
                    for (int i = 0; i < bNodes.Length; i++)
                    {
                        var travelBug = new TravelBug();

                        bNodes[i].TryGetValue("id", ref travelBug.travelbugId);
                        //bNodes[i].TryGetValue("name", ref travelBug.name);
                        bNodes[i].TryGetValue("collectionId", ref travelBug.activeCollectionId);

                        var entries = bNodes[i].GetNodes();
                        for (int e = 0; e < entries.Count() - 1; e++)
                        {
                            TravelBugEntry tbe = new TravelBugEntry();
                            entries[e].TryGetValue("keocachId", ref tbe.keocachId);
                            //entries[e].TryGetValue("hintId", ref tbe.hintId);
                            entries[e].TryGetValue("timeFound", ref tbe.timeFound);

                            travelBug.entries.Add(tbe);
                        }

                        travelBugs.Add(travelBug.travelbugId, travelBug);
                    }
                }
            }
        }
        void GetActiveTravelBugs()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            Log.Info("GetActiveTravelBugs");
            Log.Info("FlightGlobals.Vessels.Count: " + FlightGlobals.Vessels.Count +
                     ", VesselsUnloaded.Count: " + FlightGlobals.VesselsUnloaded.Count +
                     ", VesselsLoaded.Count: " + FlightGlobals.VesselsLoaded.Count);
            activeTravelBugs = new Dictionary <string, TravelBugEntry>();
            usedKeoCaches    = new List <string>();

            for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
            {
                Vessel vessel = FlightGlobals.Vessels[i];
                //Log.Info("TravelBug_Window, i: " + i + ", vessel: " + vessel.GetDisplayName() + ",  loaded: " + vessel.loaded);
                // May need to use moduleHandlers here instead of partModules, needed if vessel is unloaded
                //
                //
                // if (moduleHandlers.ContainsKey(p.modules[i].moduleName)) {
                //
                if (vessel != null)
                {
                    if (!vessel.loaded)
                    {
                        for (int imh = vessel.protoVessel.protoPartSnapshots.Count - 1; imh >= 0; imh--)
                        {
                            ProtoPartSnapshot mh = vessel.protoVessel.protoPartSnapshots[imh];
                            for (int mi = mh.modules.Count - 1; mi >= 0; mi--)
                            {
                                ProtoPartModuleSnapshot module = mh.modules[mi];
                                if (module.moduleName == "KeoTravelBugModule")
                                {
                                    ConfigNode cn = module.moduleValues.GetNode(FileIO.KEOCACHE_COLLECTION);
                                    if (cn != null)
                                    {
                                        KeoCacheCollection tbKcc = KeoCacheCollection.LoadCollectionFromConfigNode(cn);
                                        if (tbKcc != null)
                                        {
                                            TravelBugEntry tbe = new TravelBugEntry(tbKcc.keocacheCollectionData.collectionId, vessel.vesselName, vessel.protoVessel.vesselID);

                                            activeTravelBugs.Add(tbe.keocachId, tbe);
                                        }
                                        FindKeoCaches();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        List <KeoTravelBugModule> vesselTravelBugs = vessel.FindPartModulesImplementing <KeoTravelBugModule>();

                        if (vesselTravelBugs != null)
                        {
                            Log.Info("vesselTravelBugs.count: " + vesselTravelBugs.Count);
                            for (int i1 = vesselTravelBugs.Count - 1; i1 >= 0; i1--)
                            {
                                KeoTravelBugModule traveBug = vesselTravelBugs[i1];
                                Log.Info("creating TravelBugentry # " + i1);
                                if (traveBug == null)
                                {
                                    Log.Info("traveBug is null");
                                }
                                if (traveBug.tbKcc != null)
                                {
                                    if (traveBug.tbKcc == null)
                                    {
                                        Log.Info("traveBug.tbKcc is null");
                                    }
                                    if (traveBug.tbKcc.keocacheCollectionData == null)
                                    {
                                        Log.Info("traveBug.tbKcc.keocacheCollectionData is null");
                                    }
                                    if (traveBug.tbKcc.keocacheCollectionData.collectionId == null)
                                    {
                                        Log.Info("traveBug.tbKcc.keocacheCollectionData.collectionId is null");
                                    }

                                    if (vessel == null)
                                    {
                                        Log.Info("vessel is null");
                                    }
                                    if (vessel.vesselName == null)
                                    {
                                        Log.Info("vessel.vesselName is null");
                                    }
                                    if (vessel.protoVessel == null)
                                    {
                                        Log.Info("vessel.protoVessel is null");
                                    }

                                    TravelBugEntry tbe = new TravelBugEntry(traveBug.tbKcc.keocacheCollectionData.collectionId, vessel.vesselName, vessel.protoVessel.vesselID);

                                    activeTravelBugs.Add(tbe.keocachId, tbe);
                                    FindKeoCaches();
                                }
                            }
                        }
                    }
                }
            }
        }
        void TravelBug_Window(int id)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Width(10);
            GUILayout.Label("Vessel", GUILayout.Width(175));
            GUILayout.Space(5);
            GUILayout.Label("Collection Name", GUILayout.Width(175));
            GUILayout.Space(5);
            GUILayout.Label("Collection Title", GUILayout.Width(175));
            GUILayout.EndHorizontal();

            //
            // If this starts to be inefficient, then a new method to gather all the travelbugs will need
            // to be written. that method will be called when this window is opened
            //
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(120), GUILayout.Width(615));
            for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
            {
                Vessel vessel = FlightGlobals.Vessels[i];
                Log.Info("TravelBug_Window, i: " + i + ", vessel: " + vessel.GetDisplayName() + ",  loaded: " + vessel.loaded);
                // May need to use moduleHandlers here instead of partModules, needed if vessel is unloaded
                //
                //
                // if (moduleHandlers.ContainsKey(p.modules[i].moduleName)) {
                //
                if (!vessel.loaded)
                {
                    for (int imh = vessel.protoVessel.protoPartSnapshots.Count - 1; imh >= 0; imh--)
                    {
                        Log.Info("imh: " + imh);
                        ProtoPartSnapshot mh = vessel.protoVessel.protoPartSnapshots[imh];
                        for (int mi = mh.modules.Count - 1; mi >= 0; mi--)
                        {
                            Log.Info("mi: " + mi);
                            ProtoPartModuleSnapshot module = mh.modules[mi];
                            if (module.moduleName == "KeoTravelBugModule")
                            {
                                ConfigNode cn = module.moduleValues.GetNode(FileIO.KEOCACHE_COLLECTION);
                                if (cn != null)
                                {
                                    KeoCacheCollection tbKcc = KeoCacheCollection.LoadCollectionFromConfigNode(cn);
                                    if (tbKcc != null)
                                    {
                                        DisplayTravelBugData(
                                            vessel.protoVessel.vesselID,
                                            vessel.vesselName,
                                            tbKcc.keocacheCollectionData.name,
                                            tbKcc.keocacheCollectionData.title);
                                    }
                                }

#if false
                                if (KeoScenario.activeKeoCacheCollections != null)
                                {
                                    string collectionId = module.moduleValues.GetValue("collectionID");
                                    Log.Info("collectionID: " + collectionId);
                                    activeKeoCacheCollection = KeoScenario.activeKeoCacheCollections[collectionId];

                                    if (activeKeoCacheCollection != null)
                                    {
                                        DisplayTravelBugData(
                                            vessel.protoVessel.vesselID,
                                            vessel.vesselName,
                                            activeKeoCacheCollection.keocacheCollectionData.name,
                                            activeKeoCacheCollection.keocacheCollectionData.title);
                                    }
                                }
#endif
                            }
                        }
                    }
                }
                else
                {
                    List <KeoTravelBugModule> vesselTravelBugs = vessel.FindPartModulesImplementing <KeoTravelBugModule>();

                    if (vesselTravelBugs != null)
                    {
                        for (int i1 = vesselTravelBugs.Count - 1; i1 >= 0; i1--)
                        {
                            KeoTravelBugModule traveBug = vesselTravelBugs[i1];

                            var c = traveBug.collectionID;
                            DisplayTravelBugData(vessel.id, vessel.vesselName, traveBug.tbKcc.keocacheCollectionData.name, traveBug.tbKcc.keocacheCollectionData.title);

#if false
                            if (KeoScenario.activeKeoCacheCollections != null)
                            {
                                activeKeoCacheCollection = KeoScenario.activeKeoCacheCollections[c];

                                if (activeKeoCacheCollection != null)
                                {
                                    DisplayTravelBugData(vessel.id, vessel.vesselName, activeKeoCacheCollection.keocacheCollectionData.name, activeKeoCacheCollection.keocacheCollectionData.title);
                                }
                            }
#endif
                        }
                    }
                }
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndScrollView();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close", GUILayout.Width(60)))
            {
                visibleTravelBug = false;
                visibleMenu      = true;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUI.DragWindow();
        }