private List <string> ParseDataExpandString <T>(ConfigNode dataExpandNode, string key) { List <T> values = null; bool valid = ConfigNodeUtil.ParseValue <List <T> >(dataExpandNode, key, x => values = x, this); if (!valid || values == null) { return(null); } // Check that we actually got a deterministic value if (!dataNode.IsDeterministic(key)) { LoggingUtil.LogError(this, ErrorPrefix() + ": Values captured in a DATA_EXPAND node must be deterministic (the value needs to be fixed when loaded on game startup."); return(null); } List <string> results = new List <string>(); foreach (T t in values) { Type type; results.Add(PersistentDataStore.OutputValue(t, out type)); } return(results); }
public PersistentDataStore() { Instance = this; }
protected override void OnSave(ConfigNode node) { try { node.SetValue("type", "ConfiguredContract"); node.AddValue("subtype", subType); if (!string.IsNullOrEmpty(title)) { node.AddValue("title", title.Replace("\n", "&br;")); } if (!string.IsNullOrEmpty(description)) { node.AddValue("description", description.Replace("\n", "&br;")); } if (!string.IsNullOrEmpty(synopsis)) { node.AddValue("synopsis", synopsis.Replace("\n", "&br;")); } if (!string.IsNullOrEmpty(completedMessage)) { node.AddValue("completedMessage", completedMessage.Replace("\n", "&br;")); } if (!string.IsNullOrEmpty(notes)) { node.AddValue("notes", notes.Replace("\n", "&br;")); } node.AddValue("hash", hash); if (targetBody != null) { node.AddValue("targetBody", targetBody.name); } // Store the unique data if (uniqueData.Any()) { ConfigNode dataNode = new ConfigNode("UNIQUE_DATA"); node.AddNode(dataNode); foreach (KeyValuePair <string, object> p in uniqueData.Where(p => p.Value != null)) { PersistentDataStore.StoreToConfigNode(dataNode, p.Key, p.Value); } } foreach (ContractBehaviour behaviour in behaviours) { ConfigNode child = new ConfigNode("BEHAVIOUR"); behaviour.Save(child); node.AddNode(child); } // Store requirements if (requirements == null) { requirements = new List <ContractRequirement>(); if (contractType != null) { foreach (ContractRequirement requirement in contractType.Requirements) { requirements.Add(requirement); } } } foreach (ContractRequirement requirement in requirements) { ConfigNode child = new ConfigNode("REQUIREMENT"); if (child.nodes.Count > 0) { requirement.Save(child); node.AddNode(child); } } } catch (Exception e) { LoggingUtil.LogError(this, "Error saving contract '" + subType + "' to persistance file!"); LoggingUtil.LogException(e); ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.CONTRACT_SAVE, e, this); SetState(State.Failed); } }