示例#1
0
文件: Level.cs 项目: Altenhh/GDNET
        /// <summary>
        /// Decompresses a level's string.
        /// </summary>
        /// <param name="level">A local level.</param>
        /// <returns>The decompressed level string.</returns>
        public static string DecompressLevel(LocalLevel level)
        {
            if (!level.LevelString.StartsWith("H4sIAAAAAAAA"))
            {
                throw new ArgumentException("The provided level string is invalid.");
            }

            return(Encoding.ASCII.GetString(LocalLevelManager.Decompress(Base64.DecodeToBytes(level.LevelString))));
        }
示例#2
0
        public static LocalLevel Load(string levelString)
        {
            var lvl   = new LocalLevel();
            var props = typeof(LocalLevel).GetProperties();

            foreach (var prop in props)
            {
                var attrs = prop.GetCustomAttributes(false);

                foreach (var attr in attrs)
                {
                    if (attr is GdXmlAttribute gdattr)
                    {
                        prop.SetValue(lvl, LocalLevelManager.GetPair(levelString, gdattr.Key, prop.PropertyType).Value);
                    }
                }
            }

            return(lvl);
        }