partial void InitProjectSpecific() { string previewImageData = SubmarineElement.GetAttributeString("previewimage", ""); if (!string.IsNullOrEmpty(previewImageData)) { try { using (System.IO.MemoryStream mem = new System.IO.MemoryStream(Convert.FromBase64String(previewImageData))) { var texture = TextureLoader.FromStream(mem, path: FilePath, compress: false); if (texture == null) { throw new Exception("PreviewImage texture returned null"); } PreviewImage = new Sprite(texture, sourceRectangle: null, newOffset: null, path: FilePath); } } catch (Exception e) { DebugConsole.ThrowError("Loading the preview image of the submarine \"" + Name + "\" failed. The file may be corrupted.", e); GameAnalyticsManager.AddErrorEventOnce("Submarine..ctor:PreviewImageLoadingFailed", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, "Loading the preview image of the submarine \"" + Name + "\" failed. The file may be corrupted."); PreviewImage = null; } } }
private void Init() { DisplayName = TextManager.Get("Submarine.Name." + Name, true); if (string.IsNullOrEmpty(DisplayName)) { DisplayName = Name; } Description = TextManager.Get("Submarine.Description." + Name, true); if (string.IsNullOrEmpty(Description)) { Description = SubmarineElement.GetAttributeString("description", ""); } GameVersion = new Version(SubmarineElement.GetAttributeString("gameversion", "0.0.0.0")); if (Enum.TryParse(SubmarineElement.GetAttributeString("tags", ""), out SubmarineTag tags)) { Tags = tags; } Dimensions = SubmarineElement.GetAttributeVector2("dimensions", Vector2.Zero); RecommendedCrewSizeMin = SubmarineElement.GetAttributeInt("recommendedcrewsizemin", 0); RecommendedCrewSizeMax = SubmarineElement.GetAttributeInt("recommendedcrewsizemax", 0); RecommendedCrewExperience = SubmarineElement.GetAttributeString("recommendedcrewexperience", "Unknown"); //backwards compatibility (use text tags instead of the actual text) if (RecommendedCrewExperience == "Beginner") { RecommendedCrewExperience = "CrewExperienceLow"; } else if (RecommendedCrewExperience == "Intermediate") { RecommendedCrewExperience = "CrewExperienceMid"; } else if (RecommendedCrewExperience == "Experienced") { RecommendedCrewExperience = "CrewExperienceHigh"; } RequiredContentPackages.Clear(); string[] contentPackageNames = SubmarineElement.GetAttributeStringArray("requiredcontentpackages", new string[0]); foreach (string contentPackageName in contentPackageNames) { RequiredContentPackages.Add(contentPackageName); } InitProjectSpecific(); }
public SubmarineInfo(string filePath, string hash = "", XElement element = null, bool tryLoad = true) { FilePath = filePath; if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) { LastModifiedTime = File.GetLastWriteTime(filePath); } try { Name = DisplayName = Path.GetFileNameWithoutExtension(filePath); } catch (Exception e) { DebugConsole.ThrowError("Error loading submarine " + filePath + "!", e); } if (!string.IsNullOrWhiteSpace(hash)) { this.hash = new Md5Hash(hash); } IsFileCorrupted = false; RequiredContentPackages = new HashSet <string>(); if (element == null && tryLoad) { Reload(); } else { SubmarineElement = element; } Name = SubmarineElement.GetAttributeString("name", null) ?? Name; Init(); }
private void Init() { DisplayName = TextManager.Get("Submarine.Name." + Name, true); if (string.IsNullOrEmpty(DisplayName)) { DisplayName = Name; } Description = TextManager.Get("Submarine.Description." + Name, true); if (string.IsNullOrEmpty(Description)) { Description = SubmarineElement.GetAttributeString("description", ""); } EqualityCheckVal = SubmarineElement.GetAttributeInt("checkval", 0); Price = SubmarineElement.GetAttributeInt("price", 1000); InitialSuppliesSpawned = SubmarineElement.GetAttributeBool("initialsuppliesspawned", false); GameVersion = new Version(SubmarineElement.GetAttributeString("gameversion", "0.0.0.0")); if (Enum.TryParse(SubmarineElement.GetAttributeString("tags", ""), out SubmarineTag tags)) { Tags = tags; } Dimensions = SubmarineElement.GetAttributeVector2("dimensions", Vector2.Zero); RecommendedCrewSizeMin = SubmarineElement.GetAttributeInt("recommendedcrewsizemin", 0); RecommendedCrewSizeMax = SubmarineElement.GetAttributeInt("recommendedcrewsizemax", 0); RecommendedCrewExperience = SubmarineElement.GetAttributeString("recommendedcrewexperience", "Unknown"); if (SubmarineElement?.Attribute("type") != null) { if (Enum.TryParse(SubmarineElement.GetAttributeString("type", ""), out SubmarineType type)) { Type = type; if (Type == SubmarineType.OutpostModule) { OutpostModuleInfo = new OutpostModuleInfo(this, SubmarineElement); } } } if (Type == SubmarineType.Player) { if (SubmarineElement?.Attribute("class") != null) { if (Enum.TryParse(SubmarineElement.GetAttributeString("class", "Undefined"), out SubmarineClass submarineClass)) { SubmarineClass = submarineClass; } } } else { SubmarineClass = SubmarineClass.Undefined; } //backwards compatibility (use text tags instead of the actual text) if (RecommendedCrewExperience == "Beginner") { RecommendedCrewExperience = "CrewExperienceLow"; } else if (RecommendedCrewExperience == "Intermediate") { RecommendedCrewExperience = "CrewExperienceMid"; } else if (RecommendedCrewExperience == "Experienced") { RecommendedCrewExperience = "CrewExperienceHigh"; } RequiredContentPackages.Clear(); string[] contentPackageNames = SubmarineElement.GetAttributeStringArray("requiredcontentpackages", new string[0]); foreach (string contentPackageName in contentPackageNames) { RequiredContentPackages.Add(contentPackageName); } InitProjectSpecific(); }