Exemplo n.º 1
0
        public override void OnLoad(ConfigNode node)
        {
            if (core == null)
                return;

            ConfigNode vessels = node.GetNode("VESSELS");

            if (vessels != null)
            {
                for (int i = 0; i < vessels.GetNodes("VESSEL_NOTES").Length; i++)
                {
                    ConfigNode vesselNotes = vessels.GetNodes("VESSEL_NOTES")[i];

                    if (vesselNotes == null)
                        continue;

                    Vessel v;

                    try
                    {
                        Guid vID = new Guid(vesselNotes.GetValue("VESSEL_ID"));

                        if (vID == null)
                            continue;

                        v = FlightGlobals.Vessels.FirstOrDefault(a => a.id == vID);

                        if (v == null)
                            continue;
                    }
                    catch (Exception e)
                    {
                        v = null;
                        Debug.LogError("BetterNotes; error while loading vessel\n" + e);
                        continue;
                    }

                    Notes_Container n = new Notes_Container(v);

                    ConfigNode vesselStats = vesselNotes.GetNode("VESSEL_STATS");

                    if (vesselStats != null)
                    {
                        n.loadVitalStats(loadStats(vesselStats));
                    }

                    ConfigNode contracts = vesselNotes.GetNode("VESSEL_CONTRACTS");

                    if (contracts != null)
                    {
                        Notes_ContractContainer c = new Notes_ContractContainer();

                        if (contracts.HasValue("CONTRACTS"))
                            n.loadContracts(c, loadContracts(contracts));

                        if (contracts.HasValue("COMPLETED_CONTRACTS"))
                            n.loadContracts(c, loadCompletedContracts(contracts));
                    }

                    ConfigNode dataNotes = vesselNotes.GetNode("VESSEL_SCIENCE_DATA");

                    if (dataNotes != null)
                    {
                        n.loadDataNotes(loadData(dataNotes));
                    }

                    ConfigNode textNotes = vesselNotes.GetNode("VESSEL_TEXT_NOTES");

                    if (textNotes != null)
                    {
                        n.loadTextNotes(loadTextNotes(textNotes));
                    }

                    ConfigNode checkList = vesselNotes.GetNode("CHECK_LIST");

                    if (checkList != null)
                    {
                        n.loadCheckList(loadCheckList(checkList, false));
                    }

                    ConfigNode vesselLog = vesselNotes.GetNode("VESSEL_LOG");

                    if (vesselLog != null)
                    {
                        n.loadVesselLog(loadLog(vesselLog));
                    }

                    core.addNotes(n);
                }
            }

            ConfigNode archivedVessels = node.GetNode("ARCHIVED_VESSELS");

            if (archivedVessels != null)
            {
                for (int i = 0; i < archivedVessels.GetNodes("ARCHIVED_VESSEL_NOTES").Length; i++)
                {
                    ConfigNode vesselNotes = archivedVessels.GetNodes("ARCHIVED_VESSEL_NOTES")[i];

                    if (vesselNotes == null)
                        continue;

                    Guid vID;

                    try
                    {
                        vID = new Guid(vesselNotes.GetValue("VESSEL_ID"));
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("BetterNotes; error while loading archived vessel\n" + e);
                        continue;
                    }

                    if (vID == null)
                        continue;

                    string name = vesselNotes.parse("VESSEL_NAME", "");
                    double rTime = vesselNotes.parse("RECOVERY_TIME", 0d);
                    double mTime = vesselNotes.parse("MISSION_TIME", 0d);
                    VesselType vT = vesselNotes.parse("VESSEL_TYPE", VesselType.Unknown);

                    Notes_Archive_Container n = new Notes_Archive_Container(vID, name, rTime, mTime, vT);

                    ConfigNode crew = vesselNotes.GetNode("ARCHIVED_CREW");

                    if (crew != null)
                    {
                        n.loadCrewNotes(loadCrew(crew));
                    }

                    ConfigNode contracts = vesselNotes.GetNode("VESSEL_CONTRACTS");

                    if (contracts != null)
                    {
                        Notes_ContractContainer c = new Notes_ContractContainer();

                        if (contracts.HasValue("CONTRACTS"))
                            n.loadContracts(c, loadContracts(contracts));

                        if (contracts.HasValue("COMPLETED_CONTRACTS"))
                            n.loadContracts(c, loadCompletedContracts(contracts));
                    }

                    ConfigNode dataNotes = vesselNotes.GetNode("VESSEL_SCIENCE_DATA");

                    if (dataNotes != null)
                    {
                        n.loadDataNotes(loadData(dataNotes));
                    }

                    ConfigNode textNotes = vesselNotes.GetNode("VESSEL_TEXT_NOTES");

                    if (textNotes != null)
                    {
                        n.loadTextNotes(loadTextNotes(textNotes));
                    }

                    ConfigNode checkList = vesselNotes.GetNode("CHECK_LIST");

                    if (checkList != null)
                    {
                        n.loadCheckList(loadCheckList(checkList, true));
                    }

                    ConfigNode vesselLog = vesselNotes.GetNode("VESSEL_LOG");

                    if (vesselLog != null)
                    {
                        n.loadVesselLog(loadLog(vesselLog));
                    }

                    core.addArchivedNotes(n);
                }
            }
        }
Exemplo n.º 2
0
        private void onVesselRecovered(ProtoVessel v, bool q)
        {
            Notes_Container container = getNotes(v.vesselID);

            if (container == null)
                return;

            Notes_Archive_Container n = new Notes_Archive_Container(v.vesselID, v.vesselName, Planetarium.GetUniversalTime(), v.missionTime, v.vesselType);

            n.loadCheckList(container.CheckList);
            n.loadContracts(container.Contracts, container.Contracts.getAllActiveContractIDs.ToList());
            n.loadDataNotes(container.Data);
            n.loadTextNotes(container.Notes);
            n.loadVesselLog(container.Log);

            addArchivedNotes(n);
        }