コード例 #1
0
        /// <summary>
        /// Loads the <see cref="ControlBorderDrawStyle"/>s from file.
        /// </summary>
        /// <param name="filePath">The path to the file to load the <see cref="ControlBorderDrawStyle"/>s from.</param>
        /// <returns>The loaded <see cref="ControlBorderDrawStyle"/>s, where each element in the array contains the
        /// <see cref="ControlBorderDrawStyle"/> and can be indexed with the <see cref="ControlBorderSpriteType"/>.</returns>
        public static ControlBorderDrawStyle[] LoadDrawStyles(string filePath)
        {
            var ret = new ControlBorderDrawStyle[_numSprites];

            var lines = File.ReadAllLines(filePath);

            foreach (var line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                var l = line.Trim();
                if (l.Length == 0)
                {
                    continue;
                }

                var split = l.Split(':');
                if (split.Length == 2)
                {
                    var key = split[0];
                    ControlBorderDrawStyle value;

                    if (EnumHelper <ControlBorderDrawStyle> .TryParse(split[1], out value))
                    {
                        // Wild-card
                        if (StringComparer.OrdinalIgnoreCase.Equals(key, "*"))
                        {
                            for (var i = 0; i < ret.Length; i++)
                            {
                                ret[i] = value;
                            }
                            continue;
                        }

                        // Parse enum
                        ControlBorderSpriteType keyEnum;
                        if (EnumHelper <ControlBorderSpriteType> .TryParse(key, out keyEnum))
                        {
                            ret[(int)keyEnum] = value;
                            continue;
                        }
                    }
                }

                // Unable to parse
                const string errmsg = "Unable to parse line in file `{0}`: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, filePath, line);
                }
                Debug.Fail(string.Format(errmsg, filePath, line));
            }

            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Gets the <see cref="ISprite"/> for the given <see cref="ControlBorderSpriteType"/>.
        /// </summary>
        /// <param name="spriteType">The type of <see cref="ControlBorderSpriteType"/>.</param>
        /// <param name="value">The <see cref="ControlBorderDrawStyle"/> to assign to the <paramref name="spriteType"/>.</param>
        public void SetDrawStyle(ControlBorderSpriteType spriteType, ControlBorderDrawStyle value)
        {
            _drawStyles[(int)spriteType] = value;

            UpdateCanDraw();
        }
コード例 #3
0
ファイル: ControlBorder.cs プロジェクト: Vizzini/netgore
        /// <summary>
        /// Gets the <see cref="ISprite"/> for the given <see cref="ControlBorderSpriteType"/>.
        /// </summary>
        /// <param name="spriteType">The type of <see cref="ControlBorderSpriteType"/>.</param>
        /// <param name="value">The <see cref="ControlBorderDrawStyle"/> to assign to the <paramref name="spriteType"/>.</param>
        public void SetDrawStyle(ControlBorderSpriteType spriteType, ControlBorderDrawStyle value)
        {
            _drawStyles[(int)spriteType] = value;

            UpdateCanDraw();
        }
コード例 #4
0
ファイル: ControlBorder.cs プロジェクト: Vizzini/netgore
        /// <summary>
        /// Loads the <see cref="ControlBorderDrawStyle"/>s from file.
        /// </summary>
        /// <param name="filePath">The path to the file to load the <see cref="ControlBorderDrawStyle"/>s from.</param>
        /// <returns>The loaded <see cref="ControlBorderDrawStyle"/>s, where each element in the array contains the
        /// <see cref="ControlBorderDrawStyle"/> and can be indexed with the <see cref="ControlBorderSpriteType"/>.</returns>
        public static ControlBorderDrawStyle[] LoadDrawStyles(string filePath)
        {
            var ret = new ControlBorderDrawStyle[_numSprites];

            var lines = File.ReadAllLines(filePath);
            foreach (var line in lines)
            {
                if (string.IsNullOrEmpty(line))
                    continue;

                var l = line.Trim();
                if (l.Length == 0)
                    continue;

                var split = l.Split(':');
                if (split.Length == 2)
                {
                    var key = split[0];
                    ControlBorderDrawStyle value;

                    if (EnumHelper<ControlBorderDrawStyle>.TryParse(split[1], out value))
                    {
                        // Wild-card
                        if (StringComparer.OrdinalIgnoreCase.Equals(key, "*"))
                        {
                            for (var i = 0; i < ret.Length; i++)
                            {
                                ret[i] = value;
                            }
                            continue;
                        }

                        // Parse enum
                        ControlBorderSpriteType keyEnum;
                        if (EnumHelper<ControlBorderSpriteType>.TryParse(key, out keyEnum))
                        {
                            ret[(int)keyEnum] = value;
                            continue;
                        }
                    }
                }

                // Unable to parse
                const string errmsg = "Unable to parse line in file `{0}`: {1}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, filePath, line);
                Debug.Fail(string.Format(errmsg, filePath, line));
            }

            return ret;
        }