コード例 #1
0
        protected override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            count            = Convert.ToInt32(node.GetValue("count"));
            removePassengers = ConfigNodeUtil.ParseValue <bool?>(node, "removePassengers", null) ?? true;

            // Legacy support from Contract Configurator 1.8.3
            if (node.HasValue("potentialPassenger"))
            {
                List <string>              passengerNames = ConfigNodeUtil.ParseValue <List <string> >(node, "potentialPassenger", new List <string>());
                ProtoCrewMember.Gender     gender         = ConfigNodeUtil.ParseValue <ProtoCrewMember.Gender>(node, "gender", Kerbal.RandomGender());
                ProtoCrewMember.KerbalType kerbalType     = ConfigNodeUtil.ParseValue <ProtoCrewMember.KerbalType>(node, "kerbalType", ProtoCrewMember.KerbalType.Tourist);
                string experienceTrait = ConfigNodeUtil.ParseValue <string>(node, "experienceTrait", Kerbal.RandomExperienceTrait());

                kerbals = passengerNames.Select(name => new Kerbal(gender, name, experienceTrait)).ToList();

                foreach (Kerbal kerbal in kerbals)
                {
                    kerbal.kerbalType = kerbalType;
                }
            }
            else
            {
                foreach (ConfigNode kerbalNode in node.GetNodes("KERBAL"))
                {
                    kerbals.Add(Kerbal.Load(kerbalNode));
                }
            }

            foreach (ConfigNode child in node.GetNodes("PASSENGER_DATA"))
            {
                ProtoCrewMember crew   = ConfigNodeUtil.ParseValue <ProtoCrewMember>(child, "passenger");
                bool            loaded = ConfigNodeUtil.ParseValue <bool>(child, "loaded");

                if (crew != null)
                {
                    passengers[crew] = loaded;
                }
            }
        }
コード例 #2
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            if (configNode.HasValue("passengerName"))
            {
                LoggingUtil.LogWarning(this, "The passengerName and gender attributes are obsolete since Contract Configurator 1.9.0, use kerbal instead.");
                valid &= ConfigNodeUtil.ParseValue <List <string> >(configNode, "passengerName", x => passengerName = x, this, new List <string>());
                valid &= ConfigNodeUtil.ParseValue <ProtoCrewMember.Gender>(configNode, "gender", x => gender = x, this, Kerbal.RandomGender());
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "experienceTrait", x => experienceTrait = x, this, Kerbal.RandomExperienceTrait());

                legacy = true;
            }
            else
            {
                valid &= ConfigNodeUtil.ParseValue <List <Kerbal> >(configNode, "kerbal", x => kerbals = x, this, new List <Kerbal>());
                legacy = false;
            }

            valid &= ConfigNodeUtil.ParseValue <int>(configNode, "count", x => count = x, this, 1, x => Validation.GE(x, 1));
            valid &= ConfigNodeUtil.ParseValue <ProtoCrewMember.KerbalType>(configNode, "kerbalType", x => kerbalType = x, this, ProtoCrewMember.KerbalType.Tourist);
            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "removePassengers", x => removePassengers = x, this, true);

            return(valid);
        }