public static void save_colors() { if (p_c__ == null) { return; } WorldInfo i = WorldsManager.GetWorldInfo(API_WE_Mod.API_WE.n_w); var path = Storage.CombinePaths(n_w, "Project.xml"); if (!Storage.FileExists(path)) { return; } var xelement = (XElement)null; using (var stream = Storage.OpenFile(path, OpenFileMode.Read)) { xelement = XmlUtils.LoadXmlFromStream(stream, null, true); } var gameInfoNode = GetGameInfoNode(xelement); var valuesDictionary = new ValuesDictionary(); valuesDictionary.ApplyOverrides(gameInfoNode); i.WorldSettings.Save(valuesDictionary, true); Log.Warning("cur palette " + valuesDictionary.GetValue <ValuesDictionary>("Palette").GetValue <string>("Colors")); valuesDictionary.SetValue("Palette", Save()); gameInfoNode.RemoveNodes(); valuesDictionary.Save(gameInfoNode); Log.Warning("cur palette 2 " + valuesDictionary.GetValue <ValuesDictionary>("Palette").GetValue <string>("Colors")); using (var stream = Storage.OpenFile(path, OpenFileMode.Create)) { XmlUtils.SaveXmlToStream(xelement, stream, null, true); } Log.Warning("Color saves"); p_c__ = null; }
public static string CreateFurniturePack(string name, ICollection <FurnitureDesign> designs) { MemoryStream memoryStream = new MemoryStream(); using (ZipArchive zipArchive = ZipArchive.Create(memoryStream, keepStreamOpen: true)) { ValuesDictionary valuesDictionary = new ValuesDictionary(); SubsystemFurnitureBlockBehavior.SaveFurnitureDesigns(valuesDictionary, designs); XElement xElement = new XElement("FurnitureDesigns"); valuesDictionary.Save(xElement); MemoryStream memoryStream2 = new MemoryStream(); xElement.Save((Stream)memoryStream2); memoryStream2.Position = 0L; zipArchive.AddStream("FurnitureDesigns.xml", memoryStream2); } memoryStream.Position = 0L; return(ImportFurniturePack(name, memoryStream)); }
public static void ChangeWorld(string directoryName, WorldSettings worldSettings) { string path = Storage.CombinePaths(directoryName, "Project.xml"); if (!Storage.FileExists(path)) { return; } XElement xElement = null; using (Stream stream = Storage.OpenFile(path, OpenFileMode.Read)) { xElement = XmlUtils.LoadXmlFromStream(stream, null, throwOnError: true); } XElement gameInfoNode = GetGameInfoNode(xElement); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.ApplyOverrides(gameInfoNode); GameMode value = valuesDictionary.GetValue <GameMode>("GameMode"); worldSettings.Save(valuesDictionary, liveModifiableParametersOnly: true); gameInfoNode.RemoveNodes(); valuesDictionary.Save(gameInfoNode); using (Stream stream2 = Storage.OpenFile(path, OpenFileMode.Create)) { XmlUtils.SaveXmlToStream(xElement, stream2, null, throwOnError: true); } if (worldSettings.GameMode != value) { if (worldSettings.GameMode == GameMode.Adventure) { TakeWorldSnapshot(directoryName, "AdventureRestart"); } else { DeleteWorldSnapshot(directoryName, "AdventureRestart"); } } }
public static WorldInfo CreateWorld(WorldSettings worldSettings) { string unusedWorldDirectoryName = GetUnusedWorldDirectoryName(); Storage.CreateDirectory(unusedWorldDirectoryName); if (!ValidateWorldName(worldSettings.Name)) { throw new InvalidOperationException($"World name \"{worldSettings.Name}\" is invalid."); } int num; if (string.IsNullOrEmpty(worldSettings.Seed)) { num = (int)(long)(Time.RealTime * 1000.0); } else if (worldSettings.Seed == "0") { num = 0; } else { num = 0; int num2 = 1; string seed = worldSettings.Seed; foreach (char c in seed) { num += c * num2; num2 += 29; } } ValuesDictionary valuesDictionary = new ValuesDictionary(); worldSettings.Save(valuesDictionary, liveModifiableParametersOnly: false); valuesDictionary.SetValue("WorldDirectoryName", unusedWorldDirectoryName); valuesDictionary.SetValue("WorldSeed", num); ValuesDictionary valuesDictionary2 = new ValuesDictionary(); valuesDictionary2.SetValue("Players", new ValuesDictionary()); DatabaseObject databaseObject = DatabaseManager.GameDatabase.Database.FindDatabaseObject("GameProject", DatabaseManager.GameDatabase.ProjectTemplateType, throwIfNotFound: true); XElement xElement = new XElement("Project"); XmlUtils.SetAttributeValue(xElement, "Guid", databaseObject.Guid); XmlUtils.SetAttributeValue(xElement, "Name", "GameProject"); XmlUtils.SetAttributeValue(xElement, "Version", VersionsManager.SerializationVersion); XElement xElement2 = new XElement("Subsystems"); xElement.Add(xElement2); XElement xElement3 = new XElement("Values"); XmlUtils.SetAttributeValue(xElement3, "Name", "GameInfo"); valuesDictionary.Save(xElement3); xElement2.Add(xElement3); XElement xElement4 = new XElement("Values"); XmlUtils.SetAttributeValue(xElement4, "Name", "Players"); valuesDictionary2.Save(xElement4); xElement2.Add(xElement4); using (Stream stream = Storage.OpenFile(Storage.CombinePaths(unusedWorldDirectoryName, "Project.xml"), OpenFileMode.Create)) { XmlUtils.SaveXmlToStream(xElement, stream, null, throwOnError: true); } return(GetWorldInfo(unusedWorldDirectoryName)); }