void addKerbal(ProtoCrewMember pcm)
        {
            KerbalExt ext = new KerbalExt();

            ext.NewKerbal(pcm);
            SetExt(pcm, ext);
        }
        void onProtoCrewMemberSave(GameEvents.FromToAction <ProtoCrewMember, ConfigNode> action)
        {
            ProtoCrewMember pcm = action.from;
            //Debug.LogFormat ("[KerbalStats] saving ext for {0}", pcm.name);
            ConfigNode node      = action.to;
            ConfigNode kerbalExt = node.AddNode("KerbalExt");

            if (kerbals != null)
            {
                //Debug.Log ("    from kerbals");
                // The check shouldn't be necessary, but sometimes name changes
                // slip through the cracks (FIXME there is an event as of KSP
                // 1.3 which I need to add). The next load should take care of
                // the missing ext data.
                if (kerbals.ContainsKey(pcm.name))
                {
                    kerbals[pcm.name].Save(kerbalExt);
                }
            }
            else if (loading_kerbals != null)
            {
                //Debug.Log ("    from loading_kerbals");
            }
            else
            {
                //Debug.Log ("    from the ether");
                KerbalExt ext = new KerbalExt();
                ext.NewKerbal(pcm);
                ext.Save(kerbalExt);
            }
        }
        void onProtoCrewMemberLoad(GameEvents.FromToAction <ProtoCrewMember, ConfigNode> action)
        {
            if (loading_kerbals == null)
            {
                loading_kerbals = new List <KerbalPair>();
            }
            //Debug.LogFormat ("[KerbalStats] onProtoCrewMemberLoad: {0}", action);
            ProtoCrewMember pcm  = action.from;
            ConfigNode      node = action.to;
            string          name = pcm.name;

            if (name == null && node != null && node.HasValue("name"))
            {
                // it turns out onProtoCrewMemberLoad is sometimes fired too
                // early (before ProtoCrewMember is filled in)
                name = node.GetValue("name");
            }
            // Kerbals created on entering the astronaut complex do not have
            // a config node, and kerbals created before installing KS won't
            // have a KerbalExt
            if (node != null && node.HasNode("KerbalExt"))
            {
                //Debug.LogFormat ("[KerbalStats] loading ext for {0}", name);
                var kerbal = node.GetNode("KerbalExt");
                var ext    = new KerbalExt();
                ext.Load(pcm, kerbal);
                SetExt(pcm, ext);
            }
            else
            {
                //Debug.LogFormat ("[KerbalStats] creating ext for {0}", name);
                addKerbal(pcm);
            }
        }
 internal void SetExt(ProtoCrewMember pcm, KerbalExt ext)
 {
     if (loading_kerbals != null)
     {
         //Debug.Log("    loading_kerbals");
         loading_kerbals.Add(new KerbalPair(pcm, ext));
     }
     else if (kerbals != null)
     {
         //Debug.Log("    kerbals");
         kerbals[pcm.name] = ext;
     }
 }
Example #5
0
        public static string Get(ProtoCrewMember pcm, string parms)
        {
            var       modules = KerbalStats.current.kerbalext_modules;
            KerbalExt kerbal  = KerbalStats.current[pcm];
            string    system  = parms;

            if (parms.Contains(":"))
            {
                int index = parms.IndexOf(":");
                system = parms.Substring(0, index);
                parms  = parms.Substring(index + 1);
            }
            else
            {
                parms = "";
            }
            if (!modules.ContainsKey(system))
            {
                Debug.LogError("[KS] KerbalExt.Get: no such module: " + system);
                return(null);
            }
            return(modules[system].Get(kerbal, parms));
        }
 public KerbalPair(ProtoCrewMember pcm, KerbalExt ext)
 {
     this.pcm = pcm;
     this.ext = ext;
 }