예제 #1
0
        //saving/loading ----------------------------------------------------
        public bool SaveAs(string filePath, System.IO.MemoryStream previewImage = null)
        {
            var newElement = new XElement(SubmarineElement.Name,
                                          SubmarineElement.Attributes().Where(a => !string.Equals(a.Name.LocalName, "previewimage", StringComparison.InvariantCultureIgnoreCase) &&
                                                                              !string.Equals(a.Name.LocalName, "name", StringComparison.InvariantCultureIgnoreCase)),
                                          SubmarineElement.Elements());

            if (Type == SubmarineType.OutpostModule)
            {
                OutpostModuleInfo.Save(newElement);
                OutpostModuleInfo = new OutpostModuleInfo(this, newElement);
            }
            XDocument doc = new XDocument(newElement);

            doc.Root.Add(new XAttribute("name", Name));

            if (previewImage != null)
            {
                doc.Root.Add(new XAttribute("previewimage", Convert.ToBase64String(previewImage.ToArray())));
            }
            try
            {
                SaveUtil.CompressStringToFile(filePath, doc.ToString());
                Md5Hash.RemoveFromCache(filePath);
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Saving submarine \"" + filePath + "\" failed!", e);
                return(false);
            }

            return(true);
        }
예제 #2
0
        public SubmarineInfo(SubmarineInfo original)
        {
            Name                      = original.Name;
            DisplayName               = original.DisplayName;
            Description               = original.Description;
            Price                     = original.Price;
            InitialSuppliesSpawned    = original.InitialSuppliesSpawned;
            GameVersion               = original.GameVersion;
            Type                      = original.Type;
            SubmarineClass            = original.SubmarineClass;
            hash                      = !string.IsNullOrEmpty(original.FilePath) ? original.MD5Hash : null;
            Dimensions                = original.Dimensions;
            FilePath                  = original.FilePath;
            RequiredContentPackages   = new HashSet <string>(original.RequiredContentPackages);
            IsFileCorrupted           = original.IsFileCorrupted;
            SubmarineElement          = original.SubmarineElement;
            EqualityCheckVal          = original.EqualityCheckVal;
            RecommendedCrewExperience = original.RecommendedCrewExperience;
            RecommendedCrewSizeMin    = original.RecommendedCrewSizeMin;
            RecommendedCrewSizeMax    = original.RecommendedCrewSizeMax;
            Tags                      = original.Tags;
            if (original.OutpostModuleInfo != null)
            {
                OutpostModuleInfo = new OutpostModuleInfo(original.OutpostModuleInfo);
            }
#if CLIENT
            PreviewImage = original.PreviewImage != null ? new Sprite(original.PreviewImage) : null;
#endif
        }
예제 #3
0
 public OutpostModuleInfo(OutpostModuleInfo original)
 {
     Name                   = original.Name;
     moduleFlags            = new HashSet <string>(original.moduleFlags);
     allowAttachToModules   = new HashSet <string>(original.allowAttachToModules);
     allowedLocationTypes   = new HashSet <string>(original.allowedLocationTypes);
     SerializableProperties = new Dictionary <string, SerializableProperty>();
     GapPositions           = original.GapPositions;
     foreach (KeyValuePair <string, SerializableProperty> kvp in original.SerializableProperties)
     {
         SerializableProperties.Add(kvp.Key, kvp.Value);
         if (SerializableProperty.GetSupportedTypeName(kvp.Value.PropertyType) != null)
         {
             kvp.Value.TrySetValue(this, kvp.Value.GetValue(original));
         }
     }
 }
예제 #4
0
        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();
        }