public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemParticles = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true); m_componentGui = base.Entity.FindComponent <ComponentGui>(throwOnError: true); m_componentHumanModel = base.Entity.FindComponent <ComponentHumanModel>(throwOnError: true); m_componentBody = base.Entity.FindComponent <ComponentBody>(throwOnError: true); m_componentOuterClothingModel = base.Entity.FindComponent <ComponentOuterClothingModel>(throwOnError: true); m_componentVitalStats = base.Entity.FindComponent <ComponentVitalStats>(throwOnError: true); m_componentLocomotion = base.Entity.FindComponent <ComponentLocomotion>(throwOnError: true); m_componentPlayer = base.Entity.FindComponent <ComponentPlayer>(throwOnError: true); SteedMovementSpeedFactor = 1f; Insulation = 0f; LeastInsulatedSlot = ClothingSlot.Feet; m_clothes[ClothingSlot.Head] = new List <int>(); m_clothes[ClothingSlot.Torso] = new List <int>(); m_clothes[ClothingSlot.Legs] = new List <int>(); m_clothes[ClothingSlot.Feet] = new List <int>(); ValuesDictionary value = valuesDictionary.GetValue <ValuesDictionary>("Clothes"); SetClothes(ClothingSlot.Head, HumanReadableConverter.ValuesListFromString <int>(';', value.GetValue <string>("Head"))); SetClothes(ClothingSlot.Torso, HumanReadableConverter.ValuesListFromString <int>(';', value.GetValue <string>("Torso"))); SetClothes(ClothingSlot.Legs, HumanReadableConverter.ValuesListFromString <int>(';', value.GetValue <string>("Legs"))); SetClothes(ClothingSlot.Feet, HumanReadableConverter.ValuesListFromString <int>(';', value.GetValue <string>("Feet"))); Display.DeviceReset += Display_DeviceReset; }
public WorldPalette(ValuesDictionary valuesDictionary) { string[] array = valuesDictionary.GetValue("Colors", new string(';', 15)).Split(';'); if (array.Length != 16) { throw new InvalidOperationException("Invalid colors."); } Colors = array.Select((string s, int i) => (!string.IsNullOrEmpty(s)) ? HumanReadableConverter.ConvertFromString <Color>(s) : DefaultColors[i]).ToArray(); string[] array2 = valuesDictionary.GetValue("Names", new string(';', 15)).Split(';'); if (array2.Length != 16) { throw new InvalidOperationException("Invalid color names."); } Names = array2.Select((string s, int i) => (!string.IsNullOrEmpty(s)) ? s : LanguageControl.Get(GetType().Name, i)).ToArray(); string[] names = Names; int num = 0; while (true) { if (num < names.Length) { if (!VerifyColorName(names[num])) { break; } num++; continue; } return; } throw new InvalidOperationException("Invalid color name."); }
public override void Save(ValuesDictionary valuesDictionary) { base.Save(valuesDictionary); GarbageCollectDesigns(); ValuesDictionary valuesDictionary2 = new ValuesDictionary(); valuesDictionary.SetValue("FurnitureDesigns", valuesDictionary2); SaveFurnitureDesigns(valuesDictionary2, m_furnitureDesigns.Where((FurnitureDesign d) => d != null).ToArray()); ValuesDictionary valuesDictionary3 = new ValuesDictionary(); valuesDictionary.SetValue("FurnitureSets", valuesDictionary3); int num = 0; foreach (FurnitureSet furnitureSet in FurnitureSets) { ValuesDictionary valuesDictionary4 = new ValuesDictionary(); valuesDictionary3.SetValue(num.ToString(CultureInfo.InvariantCulture), valuesDictionary4); valuesDictionary4.SetValue("Name", furnitureSet.Name); if (furnitureSet.ImportedFrom != null) { valuesDictionary4.SetValue("ImportedFrom", furnitureSet.ImportedFrom); } string value = HumanReadableConverter.ValuesListToString(';', (from d in GetFurnitureSetDesigns(furnitureSet) select d.Index).ToArray()); valuesDictionary4.SetValue("Indices", value); num++; } }
public void LoadProperties(object eventsTarget, XElement node) { IEnumerable <PropertyInfo> runtimeProperties = GetType().GetRuntimeProperties(); foreach (XAttribute attribute in node.Attributes()) { if (!attribute.IsNamespaceDeclaration && !attribute.Name.LocalName.StartsWith("_")) { if (attribute.Name.LocalName.Contains('.')) { string[] array = attribute.Name.LocalName.Split('.', StringSplitOptions.None); if (array.Length != 2) { throw new InvalidOperationException($"Attached property reference must have form \"TypeName.PropertyName\", property \"{attribute.Name.LocalName}\" in widget of type \"{GetType().FullName}\"."); } Type type = FindTypeFromXmlName(array[0], (attribute.Name.NamespaceName != string.Empty) ? attribute.Name.NamespaceName : node.Name.NamespaceName); string setterName = "Set" + array[1]; MethodInfo methodInfo = type.GetRuntimeMethods().FirstOrDefault((MethodInfo mi) => mi.Name == setterName && mi.IsPublic && mi.IsStatic); if (!(methodInfo != null)) { throw new InvalidOperationException($"Attached property public static setter method \"{setterName}\" not found, property \"{attribute.Name.LocalName}\" in widget of type \"{GetType().FullName}\"."); } ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length != 2 || !(parameters[0].ParameterType == typeof(Widget))) { throw new InvalidOperationException($"Attached property setter method must take 2 parameters and first one must be of type Widget, property \"{attribute.Name.LocalName}\" in widget of type \"{GetType().FullName}\"."); } object obj = HumanReadableConverter.ConvertFromString(parameters[1].ParameterType, attribute.Value); methodInfo.Invoke(null, new object[2] { this, obj }); } else { PropertyInfo propertyInfo = runtimeProperties.Where((PropertyInfo pi) => pi.Name == attribute.Name.LocalName).FirstOrDefault(); if (!(propertyInfo != null)) { throw new InvalidOperationException($"Property \"{attribute.Name.LocalName}\" not found in widget of type \"{GetType().FullName}\"."); } if (attribute.Value.StartsWith("{") && attribute.Value.EndsWith("}")) { string name = attribute.Value.Substring(1, attribute.Value.Length - 2); object value = ContentManager.Get(propertyInfo.PropertyType, name); propertyInfo.SetValue(this, value, null); } else { object obj2 = HumanReadableConverter.ConvertFromString(propertyInfo.PropertyType, attribute.Value); if (propertyInfo.PropertyType == typeof(string)) { obj2 = ((string)obj2).Replace("\\n", "\n").Replace("\\t", "\t"); } propertyInfo.SetValue(this, obj2, null); } } } } }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { ComponentBody = base.Entity.FindComponent <ComponentBody>(throwOnError: true); ComponentHealth = base.Entity.FindComponent <ComponentHealth>(throwOnError: true); ComponentSpawn = base.Entity.FindComponent <ComponentSpawn>(throwOnError: true); ComponentCreatureSounds = base.Entity.FindComponent <ComponentCreatureSounds>(throwOnError: true); ComponentCreatureModel = base.Entity.FindComponent <ComponentCreatureModel>(throwOnError: true); ComponentLocomotion = base.Entity.FindComponent <ComponentLocomotion>(throwOnError: true); m_subsystemPlayerStats = base.Project.FindSubsystem <SubsystemPlayerStats>(throwOnError: true); ConstantSpawn = valuesDictionary.GetValue <bool>("ConstantSpawn"); Category = valuesDictionary.GetValue <CreatureCategory>("Category"); DisplayName = valuesDictionary.GetValue <string>("DisplayName"); if (DisplayName.StartsWith("[") && DisplayName.EndsWith("]")) { string[] lp = DisplayName.Substring(1, DisplayName.Length - 2).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); DisplayName = LanguageControl.GetDatabase("DisplayName", lp[1]); } m_killVerbs = HumanReadableConverter.ValuesListFromString <string>(',', valuesDictionary.GetValue <string>("KillVerbs")); if (m_killVerbs.Length == 0) { throw new InvalidOperationException("Must have at least one KillVerb"); } if (!MathUtils.IsPowerOf2((long)Category)) { throw new InvalidOperationException("A single category must be assigned for creature."); } }
public static void SaveSettings() { try { XElement xElement = new XElement("Settings"); foreach (PropertyInfo item in from pi in typeof(SettingsManager).GetRuntimeProperties() where pi.GetMethod.IsStatic && pi.GetMethod.IsPublic && pi.SetMethod.IsPublic select pi) { try { string value = HumanReadableConverter.ConvertToString(item.GetValue(null, null)); XElement node = XmlUtils.AddElement(xElement, "Setting"); XmlUtils.SetAttributeValue(node, "Name", item.Name); XmlUtils.SetAttributeValue(node, "Value", value); } catch (Exception ex) { Log.Warning($"Setting \"{item.Name}\" could not be saved. Reason: {ex.Message}"); } } using (Stream stream = Storage.OpenFile("config:/Settings.xml", OpenFileMode.Create)) { XmlUtils.SaveXmlToStream(xElement, stream, null, throwOnError: true); } Log.Information("Saved settings"); } catch (Exception e) { ExceptionManager.ReportExceptionToUser("Saving settings failed.", e); } }
public override void Save(ValuesDictionary valuesDictionary) { base.Save(valuesDictionary); string value = HumanReadableConverter.ValuesListToString(';', m_leavesToCheck.ToArray()); valuesDictionary.SetValue("LeavesToCheck", value); }
public override void Save(ValuesDictionary valuesDictionary) { base.Save(valuesDictionary); string value = HumanReadableConverter.ValuesListToString(';', m_magnets.ToArray()); valuesDictionary.SetValue("Magnets", value); }
public override void Load(ValuesDictionary valuesDictionary) { base.Load(valuesDictionary); m_subsystemPlayers = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true); string value = valuesDictionary.GetValue <string>("Magnets"); m_magnets = new DynamicArray <Vector3>(HumanReadableConverter.ValuesListFromString <Vector3>(';', value)); }
public override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap) { ValuesDictionary valuesDictionary2 = new ValuesDictionary(); valuesDictionary.SetValue("Clothes", valuesDictionary2); valuesDictionary2.SetValue("Head", HumanReadableConverter.ValuesListToString(';', m_clothes[ClothingSlot.Head].ToArray())); valuesDictionary2.SetValue("Torso", HumanReadableConverter.ValuesListToString(';', m_clothes[ClothingSlot.Torso].ToArray())); valuesDictionary2.SetValue("Legs", HumanReadableConverter.ValuesListToString(';', m_clothes[ClothingSlot.Legs].ToArray())); valuesDictionary2.SetValue("Feet", HumanReadableConverter.ValuesListToString(';', m_clothes[ClothingSlot.Feet].ToArray())); }
public string SaveSaplingData(SaplingData saplingData) { m_stringBuilder.Length = 0; m_stringBuilder.Append(HumanReadableConverter.ConvertToString(saplingData.Point)); m_stringBuilder.Append(';'); m_stringBuilder.Append(HumanReadableConverter.ConvertToString(saplingData.Type)); m_stringBuilder.Append(';'); m_stringBuilder.Append(HumanReadableConverter.ConvertToString(saplingData.MatureTime)); return(m_stringBuilder.ToString()); }
public override void Load(ValuesDictionary valuesDictionary) { base.Load(valuesDictionary); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); string value = valuesDictionary.GetValue <string>("LeavesToCheck"); Point3[] array = HumanReadableConverter.ValuesListFromString <Point3>(';', value); foreach (Point3 item in array) { m_leavesToCheck.Add(item); } }
public static void SetAttributeValue(XElement node, string attributeName, object value) { string value2 = HumanReadableConverter.ConvertToString(value); XAttribute xAttribute = node.Attribute(attributeName); if (xAttribute != null) { xAttribute.Value = value2; } else { node.Add(new XAttribute(attributeName, value2)); } }
public SaplingData LoadSaplingData(string data) { string[] array = data.Split(';', StringSplitOptions.None); if (array.Length != 3) { throw new InvalidOperationException("Invalid sapling data string."); } return(new SaplingData { Point = HumanReadableConverter.ConvertFromString <Point3>(array[0]), Type = HumanReadableConverter.ConvertFromString <TreeType>(array[1]), MatureTime = HumanReadableConverter.ConvertFromString <double>(array[2]) }); }
public static object GetAttributeValue(XElement node, string attributeName, Type type, object defaultValue) { XAttribute xAttribute = node.Attribute(attributeName); if (xAttribute != null) { try { return(HumanReadableConverter.ConvertFromString(type, xAttribute.Value)); } catch (Exception) { return(defaultValue); } } return(defaultValue); }
public override void Save(ValuesDictionary valuesDictionary) { base.Save(valuesDictionary); ValuesDictionary valuesDictionary2 = new ValuesDictionary(); valuesDictionary.SetValue("Blocks", valuesDictionary2); foreach (KeyValuePair <Point3, T> blocksDatum in m_blocksData) { valuesDictionary2.SetValue(HumanReadableConverter.ConvertToString(blocksDatum.Key), blocksDatum.Value.SaveString()); } ValuesDictionary valuesDictionary3 = new ValuesDictionary(); valuesDictionary.SetValue("Items", valuesDictionary3); foreach (KeyValuePair <int, T> itemsDatum in m_itemsData) { valuesDictionary3.SetValue(HumanReadableConverter.ConvertToString(itemsDatum.Key), itemsDatum.Value.SaveString()); } }
public override void Save(ValuesDictionary valuesDictionary) { ValuesDictionary valuesDictionary2 = new ValuesDictionary(); valuesDictionary.SetValue("MovingBlockSets", valuesDictionary2); int num = 0; foreach (MovingBlockSet movingBlockSet in m_movingBlockSets) { ValuesDictionary valuesDictionary3 = new ValuesDictionary(); valuesDictionary2.SetValue(num.ToString(CultureInfo.InvariantCulture), valuesDictionary3); valuesDictionary3.SetValue("Position", movingBlockSet.Position); valuesDictionary3.SetValue("TargetPosition", movingBlockSet.TargetPosition); valuesDictionary3.SetValue("Speed", movingBlockSet.Speed); valuesDictionary3.SetValue("Acceleration", movingBlockSet.Acceleration); valuesDictionary3.SetValue("Drag", movingBlockSet.Drag); if (movingBlockSet.Smoothness != Vector2.Zero) { valuesDictionary3.SetValue("Smoothness", movingBlockSet.Smoothness); } if (movingBlockSet.Id != null) { valuesDictionary3.SetValue("Id", movingBlockSet.Id); } if (movingBlockSet.Tag != null) { valuesDictionary3.SetValue("Tag", movingBlockSet.Tag); } StringBuilder stringBuilder = new StringBuilder(); foreach (MovingBlock block in movingBlockSet.Blocks) { stringBuilder.Append(HumanReadableConverter.ConvertToString(block.Value)); stringBuilder.Append(','); stringBuilder.Append(HumanReadableConverter.ConvertToString(block.Offset.X)); stringBuilder.Append(','); stringBuilder.Append(HumanReadableConverter.ConvertToString(block.Offset.Y)); stringBuilder.Append(','); stringBuilder.Append(HumanReadableConverter.ConvertToString(block.Offset.Z)); stringBuilder.Append(';'); } valuesDictionary3.SetValue("Blocks", stringBuilder.ToString()); num++; } }
public override void Load(ValuesDictionary valuesDictionary) { base.Load(valuesDictionary); m_subsystemItemsScanner = base.Project.FindSubsystem <SubsystemItemsScanner>(throwOnError: true); foreach (KeyValuePair <string, object> item in valuesDictionary.GetValue <ValuesDictionary>("Blocks")) { Point3 key = HumanReadableConverter.ConvertFromString <Point3>(item.Key); T value = new T(); value.LoadString((string)item.Value); m_blocksData[key] = value; } foreach (KeyValuePair <string, object> item2 in valuesDictionary.GetValue <ValuesDictionary>("Items")) { int key2 = HumanReadableConverter.ConvertFromString <int>(item2.Key); T value2 = new T(); value2.LoadString((string)item2.Value); m_itemsData[key2] = value2; } m_subsystemItemsScanner.ItemsScanned += GarbageCollectItems; }
public override void Update() { if (m_rectangle.IsClicked) { DialogsManager.ShowDialog(this, new TextBoxDialog("Enter Color", GetColorString(), 20, delegate(string s) { if (s != null) { try { m_color.RGB = HumanReadableConverter.ConvertFromString <Color>(s); } catch { DialogsManager.ShowDialog(this, new MessageDialog("Invalid Color", "Use R,G,B or #HEX notation, e.g. 255,92,13 or #FF5C0D", LanguageControl.Get("Usual", "ok"), null, null)); } } })); } if (m_sliderR.IsSliding) { m_color.R = (byte)m_sliderR.Value; } if (m_sliderG.IsSliding) { m_color.G = (byte)m_sliderG.Value; } if (m_sliderB.IsSliding) { m_color.B = (byte)m_sliderB.Value; } if (m_okButton.IsClicked) { Dismiss(m_color); } if (base.Input.Cancel || m_cancelButton.IsClicked) { Dismiss(null); } UpdateControls(); }
public static void RepairWorldIfNeeded(string directoryName) { try { string text = Storage.CombinePaths(directoryName, "Project.xml"); if (!TestXmlFile(text, "Project")) { Log.Warning($"Project file at \"{text}\" is corrupt or nonexistent. Will try copying data from the backup file. If that fails, will try making a recovery project file."); string text2 = Storage.CombinePaths(directoryName, "Project.bak"); if (TestXmlFile(text2, "Project")) { Storage.CopyFile(text2, text); } else { string path = Storage.CombinePaths(directoryName, "Chunks.dat"); if (!Storage.FileExists(path)) { throw new InvalidOperationException("Recovery project file could not be generated because chunks file does not exist."); } XElement xElement = ContentManager.Get <XElement>("RecoveryProject"); using (Stream stream = Storage.OpenFile(path, OpenFileMode.Read)) { TerrainSerializer14.ReadTOCEntry(stream, out int cx, out int cz, out int _); Vector3 vector = new Vector3(16 * cx, 255f, 16 * cz); xElement.Element("Subsystems").Element("Values").Element("Value") .Attribute("Value") .SetValue(HumanReadableConverter.ConvertToString(vector)); } using (Stream stream2 = Storage.OpenFile(text, OpenFileMode.Create)) { XmlUtils.SaveXmlToStream(xElement, stream2, null, throwOnError: true); } } } } catch (Exception) { throw new InvalidOperationException("The world files are corrupt and could not be repaired."); } }
public override void Save(ValuesDictionary valuesDictionary) { ValuesDictionary valuesDictionary2 = new ValuesDictionary(); valuesDictionary.SetValue("Chunks", valuesDictionary2); foreach (SpawnChunk value2 in m_chunks.Values) { if (value2.LastVisitedTime.HasValue) { ValuesDictionary valuesDictionary3 = new ValuesDictionary(); valuesDictionary2.SetValue(HumanReadableConverter.ConvertToString(value2.Point), valuesDictionary3); valuesDictionary3.SetValue("IsSpawned", value2.IsSpawned); valuesDictionary3.SetValue("LastVisitedTime", value2.LastVisitedTime.Value); string value = SaveSpawnsData(value2.SpawnsData); if (!string.IsNullOrEmpty(value)) { valuesDictionary3.SetValue("SpawnsData", value); } } } }
public static ValuesDictionary Save() { var valuesDictionary = new ValuesDictionary(); var str1 = string.Join(";", p_c__.Select((c, i) => { return(HumanReadableConverter.ConvertToString(c)); })); var str2 = string.Join(";", WorldPalette.DefaultNames.Select((n, i) => { if (!(n == WorldPalette.DefaultNames[i])) { return(n); } return(string.Empty); })); valuesDictionary.SetValue("Colors", str1); valuesDictionary.SetValue("Names", str2); return(valuesDictionary); }
public override void Load(ValuesDictionary valuesDictionary) { m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemPlayers = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true); m_subsystemViews = base.Project.FindSubsystem <SubsystemGameWidgets>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); foreach (KeyValuePair <string, object> item in valuesDictionary.GetValue <ValuesDictionary>("Chunks")) { ValuesDictionary valuesDictionary2 = (ValuesDictionary)item.Value; SpawnChunk spawnChunk = new SpawnChunk(); spawnChunk.Point = HumanReadableConverter.ConvertFromString <Point2>(item.Key); spawnChunk.IsSpawned = valuesDictionary2.GetValue <bool>("IsSpawned"); spawnChunk.LastVisitedTime = valuesDictionary2.GetValue <double>("LastVisitedTime"); string value = valuesDictionary2.GetValue("SpawnsData", string.Empty); if (!string.IsNullOrEmpty(value)) { LoadSpawnsData(value, spawnChunk.SpawnsData); } m_chunks[spawnChunk.Point] = spawnChunk; } }
public override void Load(ValuesDictionary valuesDictionary) { base.Load(valuesDictionary); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_subsystemSoundMaterials = base.Project.FindSubsystem <SubsystemSoundMaterials>(throwOnError: true); m_subsystemItemsScanner = base.Project.FindSubsystem <SubsystemItemsScanner>(throwOnError: true); m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true); m_subsystemParticles = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); ValuesDictionary value = valuesDictionary.GetValue <ValuesDictionary>("FurnitureDesigns"); foreach (FurnitureDesign item in LoadFurnitureDesigns(base.SubsystemTerrain, value)) { m_furnitureDesigns[item.Index] = item; } foreach (ValuesDictionary item2 in valuesDictionary.GetValue <ValuesDictionary>("FurnitureSets").Values.Where((object v) => v is ValuesDictionary)) { string value2 = item2.GetValue <string>("Name"); string value3 = item2.GetValue <string>("ImportedFrom", null); string value4 = item2.GetValue <string>("Indices"); int[] array = HumanReadableConverter.ValuesListFromString <int>(';', value4); FurnitureSet furnitureSet = new FurnitureSet { Name = value2, ImportedFrom = value3 }; m_furnitureSets.Add(furnitureSet); int[] array2 = array; foreach (int num in array2) { if (num >= 0 && num < m_furnitureDesigns.Length && m_furnitureDesigns[num] != null) { m_furnitureDesigns[num].FurnitureSet = furnitureSet; } } } m_subsystemItemsScanner.ItemsScanned += GarbageCollectDesigns; }
public static void LoadSettings() { try { if (Storage.FileExists("config:/Settings.xml")) { using (Stream stream = Storage.OpenFile("config:/Settings.xml", OpenFileMode.Read)) { foreach (XElement item in XmlUtils.LoadXmlFromStream(stream, null, throwOnError: true).Elements()) { string name = "<unknown>"; try { name = XmlUtils.GetAttributeValue <string>(item, "Name"); string attributeValue = XmlUtils.GetAttributeValue <string>(item, "Value"); PropertyInfo propertyInfo = (from pi in typeof(SettingsManager).GetRuntimeProperties() where pi.Name == name && pi.GetMethod.IsStatic && pi.GetMethod.IsPublic && pi.SetMethod.IsPublic select pi).FirstOrDefault(); if (propertyInfo != null) { object value = HumanReadableConverter.ConvertFromString(propertyInfo.PropertyType, attributeValue); propertyInfo.SetValue(null, value, null); } } catch (Exception ex) { Log.Warning($"Setting \"{name}\" could not be loaded. Reason: {ex.Message}"); } } } Log.Information("Loaded settings."); } } catch (Exception e) { ExceptionManager.ReportExceptionToUser("Loading settings failed.", e); } }
public override void Load(ValuesDictionary valuesDictionary) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); m_subsystemAnimatedTextures = base.Project.FindSubsystem <SubsystemAnimatedTextures>(throwOnError: true); m_shader = ContentManager.Get <Shader>("Shaders/AlphaTested"); foreach (ValuesDictionary value9 in valuesDictionary.GetValue <ValuesDictionary>("MovingBlockSets").Values) { Vector3 value = value9.GetValue <Vector3>("Position"); Vector3 value2 = value9.GetValue <Vector3>("TargetPosition"); float value3 = value9.GetValue <float>("Speed"); float value4 = value9.GetValue <float>("Acceleration"); float value5 = value9.GetValue <float>("Drag"); Vector2 value6 = value9.GetValue("Smoothness", Vector2.Zero); string value7 = value9.GetValue <string>("Id", null); object value8 = value9.GetValue <object>("Tag", null); List <MovingBlock> list = new List <MovingBlock>(); string[] array = value9.GetValue <string>("Blocks").Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string obj2 in array) { MovingBlock item = default(MovingBlock); string[] array2 = obj2.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); item.Value = HumanReadableConverter.ConvertFromString <int>(array2[0]); item.Offset.X = HumanReadableConverter.ConvertFromString <int>(array2[1]); item.Offset.Y = HumanReadableConverter.ConvertFromString <int>(array2[2]); item.Offset.Z = HumanReadableConverter.ConvertFromString <int>(array2[3]); list.Add(item); } AddMovingBlockSet(value, value2, value3, value4, value5, value6, list, value7, value8, testCollision: false); } }
public static void LoadBlocksData(string data) { Dictionary <Block, bool> dictionary = new Dictionary <Block, bool>(); data = data.Replace("\r", string.Empty); string[] array = data.Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries); string[] array2 = null; for (int i = 0; i < array.Length; i++) { string[] array3 = array[i].Split(';'); if (i == 0) { array2 = new string[array3.Length - 1]; Array.Copy(array3, 1, array2, 0, array3.Length - 1); continue; } if (array3.Length != array2.Length + 1) { throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 2), (array3.Length != 0) ? array3[0] : LanguageControl.Get("Usual", "unknown"))); } string typeName = array3[0]; if (string.IsNullOrEmpty(typeName)) { continue; } Block block = m_blocks.FirstOrDefault((Block v) => v.GetType().Name == typeName); if (block == null) { throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 3), typeName)); } if (dictionary.ContainsKey(block)) { throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 4), typeName)); } dictionary.Add(block, value: true); Dictionary <string, FieldInfo> dictionary2 = new Dictionary <string, FieldInfo>(); foreach (FieldInfo runtimeField in block.GetType().GetRuntimeFields()) { if (runtimeField.IsPublic && !runtimeField.IsStatic) { dictionary2.Add(runtimeField.Name, runtimeField); } } for (int j = 1; j < array3.Length; j++) { string text = array2[j - 1]; string text2 = array3[j]; if (!string.IsNullOrEmpty(text2)) { if (!dictionary2.TryGetValue(text, out FieldInfo value)) { throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 5), text)); } object obj = null; if (text2.StartsWith("#")) { string refTypeName = text2.Substring(1); obj = ((!string.IsNullOrEmpty(refTypeName)) ? ((object)(m_blocks.FirstOrDefault((Block v) => v.GetType().Name == refTypeName) ?? throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 6), refTypeName))).BlockIndex) : ((object)block.BlockIndex)); } else { obj = HumanReadableConverter.ConvertFromString(value.FieldType, text2); } value.SetValue(block, obj); } } } }
public override void ConvertProjectXml(XElement projectNode) { XmlUtils.SetAttributeValue(projectNode, "Version", TargetVersion); foreach (XElement item in from e in projectNode.Element("Subsystems").Elements() where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Pickables" select e) { foreach (XElement item2 in from e in item.Elements("Values") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Pickables" select e) { foreach (XElement item3 in item2.Elements("Values")) { foreach (XElement item4 in from e in item3.Elements("Value") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Value" select e) { int num = ConvertValue(XmlUtils.GetAttributeValue <int>(item4, "Value")); XmlUtils.SetAttributeValue(item4, "Value", num); } } } } foreach (XElement item5 in from e in projectNode.Element("Subsystems").Elements() where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Projectiles" select e) { foreach (XElement item6 in from e in item5.Elements("Values") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Projectiles" select e) { foreach (XElement item7 in item6.Elements("Values")) { foreach (XElement item8 in from e in item7.Elements("Value") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Value" select e) { int num2 = ConvertValue(XmlUtils.GetAttributeValue <int>(item8, "Value")); XmlUtils.SetAttributeValue(item8, "Value", num2); } } } } foreach (XElement item9 in from e in projectNode.Element("Subsystems").Elements() where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "CollapsingBlockBehavior" select e) { foreach (XElement item10 in from e in item9.Elements("Values") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "CollapsingBlocks" select e) { foreach (XElement item11 in item10.Elements("Values")) { foreach (XElement item12 in from e in item11.Elements("Value") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Value" select e) { int num3 = ConvertValue(XmlUtils.GetAttributeValue <int>(item12, "Value")); XmlUtils.SetAttributeValue(item12, "Value", num3); } } } } foreach (XElement item13 in projectNode.Element("Entities").Elements()) { foreach (XElement item14 in from e in item13.Elements("Values") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Clothing" select e) { foreach (XElement item15 in from e in item14.Elements("Values") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Clothes" select e) { foreach (XElement item16 in item15.Elements()) { string attributeValue = XmlUtils.GetAttributeValue <string>(item16, "Value"); int[] array = HumanReadableConverter.ValuesListFromString <int>(';', attributeValue); for (int i = 0; i < array.Length; i++) { array[i] = ConvertValue(array[i]); } string value = HumanReadableConverter.ValuesListToString(';', array); XmlUtils.SetAttributeValue(item16, "Value", value); } } } } string[] inventoryNames = new string[6] { "Inventory", "CreativeInventory", "CraftingTable", "Chest", "Furnace", "Dispenser" }; foreach (XElement item17 in projectNode.Element("Entities").Elements()) { foreach (XElement item18 in from e in item17.Elements("Values") where inventoryNames.Contains(XmlUtils.GetAttributeValue(e, "Name", string.Empty)) select e) { foreach (XElement item19 in from e in item18.Elements("Values") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Slots" select e) { foreach (XElement item20 in item19.Elements()) { foreach (XElement item21 in from e in item20.Elements("Value") where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Contents" select e) { int num4 = ConvertValue(XmlUtils.GetAttributeValue <int>(item21, "Value")); XmlUtils.SetAttributeValue(item21, "Value", num4); } } } } } }
public ValuesDictionary Save() { ValuesDictionary valuesDictionary = new ValuesDictionary(); string value = string.Join(";", Colors.Select((Color c, int i) => (!(c == DefaultColors[i])) ? HumanReadableConverter.ConvertToString(c) : string.Empty)); string value2 = string.Join(";", Names.Select((string n, int i) => (!(n == LanguageControl.Get(GetType().Name, i))) ? n : string.Empty)); valuesDictionary.SetValue("Colors", value); valuesDictionary.SetValue("Names", value2); return(valuesDictionary); }
public object Parse(DatabaseObject context) { Match match = m_regEx.Match(Procedure); if (match.Success && match.Length == Procedure.Length) { string value = match.Groups[1].Value; DatabaseObject databaseObject = ResolveReference(context, value); if (databaseObject != null) { if (databaseObject.Type.SupportsValue) { return(databaseObject.Value); } return(databaseObject.Name); } return($"%'{value}' not found%"); } return(m_regEx.Replace(Procedure, delegate(Match m) { string value2 = m.Groups[1].Value; DatabaseObject databaseObject2 = ResolveReference(context, value2); return (databaseObject2 != null) ? (databaseObject2.Type.SupportsValue ? HumanReadableConverter.ConvertToString(databaseObject2.Value) : databaseObject2.Name) : $"%'{value2}' not found%"; })); }