Ejemplo n.º 1
0
        public override void OnLoad(ConfigNode node)
        {
            try
            {
                lastMCButton            = ConfigNodeUtil.ParseValue <MissionControlButton>(node, "lastMCButton", MissionControlButton.All);
                DisplayOfferedOrbits    = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayOfferedOrbits", (bool?)ContractDefs.DisplayOfferedOrbits).Value;
                DisplayOfferedWaypoints = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayOfferedWaypoints", (bool?)ContractDefs.DisplayOfferedWaypoints).Value;
                DisplayActiveOrbits     = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayActiveOrbits", (bool?)true).Value;
                DisplayActiveWaypoints  = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayActiveWaypoints", (bool?)true).Value;

                foreach (ConfigNode groupNode in node.GetNodes("CONTRACT_GROUP"))
                {
                    string groupName = groupNode.GetValue("group");

                    if (ContractGroup.contractGroups.ContainsKey(groupName))
                    {
                        ContractGroup group = ContractGroup.contractGroups[groupName];

                        ContractGroupDetails details = new ContractGroupDetails(group);
                        details.enabled = ConfigNodeUtil.ParseValue <bool>(groupNode, "enabled");

                        contractGroupDetails[group.name] = details;
                    }
                    else
                    {
                        LoggingUtil.LogWarning(this, "Couldn't find contract group with name '" + groupName + "'");
                    }
                }

                foreach (ConfigNode stateNode in node.GetNodes("CONTRACT_STATE"))
                {
                    string typeName = stateNode.GetValue("type");
                    if (!string.IsNullOrEmpty(typeName))
                    {
                        Type contractType = null;
                        try
                        {
                            contractType = ConfigNodeUtil.ParseTypeValue(typeName);
                            StockContractDetails details = new StockContractDetails(contractType);
                            details.enabled = ConfigNodeUtil.ParseValue <bool>(stateNode, "enabled");

                            stockContractDetails[contractType] = details;

                            ContractDisabler.SetContractState(contractType, details.enabled);
                        }
                        catch (ArgumentException)
                        {
                            LoggingUtil.LogWarning(this, "Couldn't find contract type with name '" + typeName + "'");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LoggingUtil.LogError(this, "Error loading ContractConfiguratorSettings from persistance file!");
                LoggingUtil.LogException(e);
                ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_LOAD, e, "ContractConfiguratorSettings");
            }
        }
Ejemplo n.º 2
0
        public override void OnLoad(ConfigNode node)
        {
            try
            {
                base.OnLoad(node);

                ConfigNode dataNode = node.GetNode("DATA");
                if (dataNode != null)
                {
                    // Handle individual values
                    foreach (ConfigNode.Value pair in dataNode.values)
                    {
                        string typeName = pair.value.Remove(pair.value.IndexOf(":"));
                        string value    = pair.value.Substring(typeName.Length + 1);
                        Type   type     = ConfigNodeUtil.ParseTypeValue(typeName);

                        if (type == typeof(string))
                        {
                            data[pair.name] = value;
                        }
                        else if (type.Name == "List`1")
                        {
                            BaseParser parser = BaseParser.NewParser(type);
                            if (parser == null)
                            {
                                throw new Exception("Couldn't read list of values of type '" + type.GetGenericArguments().First().Name + "'.");
                            }
                            data[pair.name] = parser.ParseExpressionGeneric("", value, null);
                        }
                        else
                        {
                            // Get the ParseValue method
                            MethodInfo parseValueMethod = typeof(ConfigNodeUtil).GetMethods().Where(m => m.Name == "ParseSingleValue").Single();
                            parseValueMethod = parseValueMethod.MakeGenericMethod(new Type[] { type });

                            // Invoke the ParseValue method
                            data[pair.name] = parseValueMethod.Invoke(null, new object[] { pair.name, value, false });
                        }
                    }

                    // Handle config nodes
                    foreach (ConfigNode childNode in dataNode.GetNodes())
                    {
                        configNodes[childNode.name] = childNode;
                    }
                }
            }
            catch (Exception e)
            {
                LoggingUtil.LogError(this, "Error loading PersistentDataStore from persistance file!");
                LoggingUtil.LogException(e);
                ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_LOAD, e, "PersistentDataStore");
            }
        }
Ejemplo n.º 3
0
        protected override void OnLoad(ConfigNode node)
        {
            try
            {
                subType          = node.GetValue("subtype");
                contractType     = ContractType.GetContractType(subType);
                title            = ConfigNodeUtil.ParseValue <string>(node, "title", contractType != null ? contractType.title : subType);
                description      = ConfigNodeUtil.ParseValue <string>(node, "description", contractType != null ? contractType.description : "");
                synopsis         = ConfigNodeUtil.ParseValue <string>(node, "synopsis", contractType != null ? contractType.synopsis : "");
                completedMessage = ConfigNodeUtil.ParseValue <string>(node, "completedMessage", contractType != null ? contractType.completedMessage : "");
                notes            = ConfigNodeUtil.ParseValue <string>(node, "notes", contractType != null ? contractType.notes : "");
                hash             = ConfigNodeUtil.ParseValue <int>(node, "hash", contractType != null ? contractType.hash : 0);
                targetBody       = ConfigNodeUtil.ParseValue <CelestialBody>(node, "targetBody", null);

                // Load the unique data
                ConfigNode dataNode = node.GetNode("UNIQUE_DATA");
                if (dataNode != null)
                {
                    // Handle individual values
                    foreach (ConfigNode.Value pair in dataNode.values)
                    {
                        string typeName = pair.value.Remove(pair.value.IndexOf(":"));
                        string value    = pair.value.Substring(typeName.Length + 1);
                        Type   type     = ConfigNodeUtil.ParseTypeValue(typeName);

                        // Prevents issues with vessels not getting loaded in some scenes (ie. VAB)
                        if (type == typeof(Vessel))
                        {
                            type = typeof(Guid);
                        }

                        if (type == typeof(string))
                        {
                            uniqueData[pair.name] = value;
                        }
                        else
                        {
                            // Get the ParseValue method
                            MethodInfo parseValueMethod = typeof(ConfigNodeUtil).GetMethods().Where(m => m.Name == "ParseSingleValue").Single();
                            parseValueMethod = parseValueMethod.MakeGenericMethod(new Type[] { type });

                            // Invoke the ParseValue method
                            uniqueData[pair.name] = parseValueMethod.Invoke(null, new object[] { pair.name, value, false });
                        }
                    }
                }

                foreach (ConfigNode child in node.GetNodes("BEHAVIOUR"))
                {
                    ContractBehaviour behaviour = ContractBehaviour.LoadBehaviour(child, this);
                    behaviours.Add(behaviour);
                }

                foreach (ConfigNode child in node.GetNodes("REQUIREMENT"))
                {
                    ContractRequirement requirement = ContractRequirement.LoadRequirement(child);
                    requirements.Add(requirement);
                }

                // If the contract type is null, then it likely means that it was uninstalled
                if (contractType == null)
                {
                    LoggingUtil.LogWarning(this, "Error loading contract for contract type '" + subType +
                                           "'.  The contract type either failed to load or was uninstalled.");
                    try
                    {
                        if (ContractState == State.Active || ContractState == State.Offered)
                        {
                            SetState(ContractState == State.Active ? State.Failed : State.Withdrawn);
                        }
                    }
                    catch { }
                    return;
                }

                OnContractLoaded.Fire(this);
            }
            catch (Exception e)
            {
                LoggingUtil.LogError(this, "Error loading contract from persistance file!");
                LoggingUtil.LogException(e);
                ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.CONTRACT_LOAD, e, this);

                try
                {
                    SetState(State.Failed);
                }
                catch { }
            }
        }