public ProjectData(GameDatabase gameDatabase, DatabaseObject projectTemplate, ValuesDictionary overrides) { ValuesDictionary = new ValuesDictionary(); ValuesDictionary.PopulateFromDatabaseObject(projectTemplate); if (overrides != null) { ValuesDictionary.ApplyOverrides(overrides); } }
public static Entity CreateEntity(Project project, string entityTemplateName, ValuesDictionary overrides, bool throwIfNotFound) { ValuesDictionary valuesDictionary = FindEntityValuesDictionary(entityTemplateName, throwIfNotFound); if (valuesDictionary != null) { valuesDictionary.ApplyOverrides(overrides); return(project.CreateEntity(valuesDictionary)); } return(null); }
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 ProjectData(GameDatabase gameDatabase, XElement projectNode, ValuesDictionary overrides, bool ignoreInvalidEntities) { Guid attributeValue = XmlUtils.GetAttributeValue(projectNode, "Guid", Guid.Empty); string attributeValue2 = XmlUtils.GetAttributeValue(projectNode, "Name", string.Empty); DatabaseObject databaseObject; if (attributeValue != Guid.Empty) { databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue, gameDatabase.ProjectTemplateType, throwIfNotFound: true); } else { if (string.IsNullOrEmpty(attributeValue2)) { throw new InvalidOperationException("Project template guid or name must be specified."); } databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue2, gameDatabase.ProjectTemplateType, throwIfNotFound: true); } ValuesDictionary = new ValuesDictionary(); ValuesDictionary.PopulateFromDatabaseObject(databaseObject); XElement xElement = XmlUtils.FindChildElement(projectNode, "Subsystems", throwIfNotFound: false); if (xElement != null) { ValuesDictionary.ApplyOverrides(xElement); } if (overrides != null) { ValuesDictionary.ApplyOverrides(overrides); } XElement xElement2 = XmlUtils.FindChildElement(projectNode, "Entities", throwIfNotFound: false); if (xElement2 != null) { EntityDataList = new EntityDataList(gameDatabase, xElement2, ignoreInvalidEntities); } }
public static List <FurnitureDesign> LoadFurniturePack(SubsystemTerrain subsystemTerrain, Stream stream) { using (ZipArchive zipArchive = ZipArchive.Open(stream, keepStreamOpen: true)) { List <ZipArchiveEntry> list = zipArchive.ReadCentralDir(); if (list.Count != 1 || list[0].FilenameInZip != "FurnitureDesigns.xml") { throw new InvalidOperationException("Invalid furniture pack."); } MemoryStream memoryStream = new MemoryStream(); zipArchive.ExtractFile(list[0], memoryStream); memoryStream.Position = 0L; XElement overridesNode = XElement.Load((Stream)memoryStream); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.ApplyOverrides(overridesNode); return(SubsystemFurnitureBlockBehavior.LoadFurnitureDesigns(subsystemTerrain, valuesDictionary)); } }
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 EntityData(GameDatabase gameDatabase, XElement entityNode) { Id = XmlUtils.GetAttributeValue <int>(entityNode, "Id"); Guid attributeValue = XmlUtils.GetAttributeValue(entityNode, "Guid", Guid.Empty); string attributeValue2 = XmlUtils.GetAttributeValue(entityNode, "Name", string.Empty); DatabaseObject databaseObject; if (attributeValue != Guid.Empty) { databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue, gameDatabase.EntityTemplateType, throwIfNotFound: true); } else { if (string.IsNullOrEmpty(attributeValue2)) { throw new InvalidOperationException("Entity template guid or name must be specified."); } databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue2, gameDatabase.EntityTemplateType, throwIfNotFound: true); } ValuesDictionary = new ValuesDictionary(); ValuesDictionary.PopulateFromDatabaseObject(databaseObject); ValuesDictionary.ApplyOverrides(entityNode); }
public static WorldInfo GetWorldInfo(string directoryName) { WorldInfo worldInfo = new WorldInfo(); worldInfo.DirectoryName = directoryName; worldInfo.LastSaveTime = DateTime.MinValue; List <string> list = new List <string>(); RecursiveEnumerateDirectory(directoryName, list, null, null); if (list.Count > 0) { foreach (string item in list) { DateTime fileLastWriteTime = Storage.GetFileLastWriteTime(item); if (fileLastWriteTime > worldInfo.LastSaveTime) { worldInfo.LastSaveTime = fileLastWriteTime; } try { worldInfo.Size += Storage.GetFileSize(item); } catch (Exception e2) { Log.Error(ExceptionManager.MakeFullErrorMessage($"Error getting size of file \"{item}\".", e2)); } } string text = Storage.CombinePaths(directoryName, "Project.xml"); try { if (Storage.FileExists(text)) { using (Stream stream = Storage.OpenFile(text, OpenFileMode.Read)) { XElement xElement = XmlUtils.LoadXmlFromStream(stream, null, throwOnError: true); worldInfo.SerializationVersion = XmlUtils.GetAttributeValue(xElement, "Version", "1.0"); VersionsManager.UpgradeProjectXml(xElement); XElement gameInfoNode = GetGameInfoNode(xElement); ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.ApplyOverrides(gameInfoNode); worldInfo.WorldSettings.Load(valuesDictionary); foreach (XElement item2 in (from e in GetPlayersNode(xElement).Elements() where XmlUtils.GetAttributeValue <string>(e, "Name") == "Players" select e).First().Elements()) { PlayerInfo playerInfo = new PlayerInfo(); worldInfo.PlayerInfos.Add(playerInfo); XElement xElement2 = (from e in item2.Elements() where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "CharacterSkinName" select e).FirstOrDefault(); if (xElement2 != null) { playerInfo.CharacterSkinName = XmlUtils.GetAttributeValue(xElement2, "Value", string.Empty); } } return(worldInfo); } } return(worldInfo); } catch (Exception e3) { Log.Error(ExceptionManager.MakeFullErrorMessage($"Error getting data from project file \"{text}\".", e3)); return(worldInfo); } } return(null); }