예제 #1
0
파일: TextLayer.cs 프로젝트: notgull/teolib
        public static TextLayer CompileLayer(TextLayer layer)
        {
            char[][] data = layer.Data;
            char[][] flippeddata;
            if (layer.XYView)
            {
                flippeddata = new char[data.Length][];
                for (int j = 0; j < data.Length; j++)
                {
                    flippeddata [0] = new char[data [0].Length];
                }

                for (int k = 0; k < data.Length; k++)
                {
                    for (int l = data [0].Length - 1; l >= 0; l--)
                    {
                        int x = k;
                        int y = data [0].Length - 1;
                        y -= l;
                        flippeddata [x] [y] = data [k] [l];
                    }
                }
            }
            else
            {
                flippeddata = data;
            }

            TextLayer nLayer = new TextLayer(layer.Width, layer.Height, layer.xyView);
            TextMap   nMap   = new TextMap(flippeddata);

            nLayer.AppendMap(nMap);
            return(nLayer);
        }
예제 #2
0
파일: TextLayer.cs 프로젝트: notgull/teolib
        protected override TextMap internalClone()
        {
            TextLayer tl = new TextLayer(Width, Height);
            TextMap   tm = base.internalClone();

            tl.AppendMap(tm);
            return(tl);
        }
예제 #3
0
        private TextLayer MakeLayerInternal(int width, int height, bool xyView)
        {
            TextLayer layer = new TextLayer(width, height, xyView);

            this.width  = width;
            this.height = height;
            this.margin = height;
            collection.Add(layer);
            //this.Add (layer);
            return(layer);
        }
예제 #4
0
파일: TextLayer.cs 프로젝트: notgull/teolib
        /// <summary>
        /// Creates a text layer made entirely from one character
        /// </summary>
        /// <param name="c">The character</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public static TextLayer OneRepeatedChar(char c, int width, int height)
        {
            TextLayer tl = new TextLayer(width, height);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    tl.ChangeLetterAt(i, j, c);
                }
            }
            return(tl);
        }
예제 #5
0
파일: TextLayer.cs 프로젝트: notgull/teolib
        /// <summary>
        /// Merges this layer with another layer
        /// </summary>
        /// <returns>The merged layer</returns>
        /// <param name="other">Other layer</param>
        /// <param name="isOtherTop">If set to <c>true</c>, the other one is on top</param>
        public TextLayer MergeLayer(TextLayer other, bool isOtherTop)
        {
            TextLayer clone = (TextLayer)Clone();

            if (isOtherTop)
            {
                clone.AppendMap(other);
            }
            else
            {
                TextLayer result = (TextLayer)(other.Clone());
                result.AppendMap(clone);
                clone = result;
            }
            return(clone);
        }
예제 #6
0
파일: TextLayer.cs 프로젝트: notgull/teolib
        /*
         * public static TextLayer TiledMap(TextMap tm, int width, int height, int xTileStart, int yTileStart) {
         *      if (xTileStart > width || yTileStart > height)
         *              throw new ArgumentOutOfRangeException ("The tiling starting points cannot be outside the size!");
         *
         *      TextLayer tl = new TextLayer (width, height);
         *      if (xTileStart != 0) {
         *              int preTileWidth = xTileStart;
         *              int remainingTileWidth = preTileWidth;
         *              int requiredMaps = (int)Math.Floor ((double)(xTileStart / tm.Width));
         *              double remainderOfMap = xTileStart % tm.Width;
         *
         *              for (int i = 0; i < requiredMaps; i++) {
         *
         *              }
         *      }
         *
         *      return null;
         * }
         */

        /// <summary>
        /// Border with specified width and height.
        /// </summary>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public static TextLayer Border(int width, int height)
        {
            TextLayer tm = new TextLayer(width, height);

            tm.ChangeLetterAt(0, 0, '/');
            tm.ChangeLetterAt(width, 0, '\\');
            tm.ChangeLetterAt(0, height, '\\');
            tm.ChangeLetterAt(width, height, '/');

            for (int i = 1; i < width - 2; i++)
            {
                tm.ChangeLetterAt(i, 0, '‾');
                tm.ChangeLetterAt(i, height, '_');
            }

            for (int i = 0; i < height; i++)
            {
                tm.ChangeLetterAt(0, i, '|');
                tm.ChangeLetterAt(width, i, '|');
            }

            return(tm);
        }
예제 #7
0
 /// <summary>
 /// Adds the layer.
 /// </summary>
 /// <param name="tl">Text layer.</param>
 public void AddLayer(TextLayer tl)
 {
     collection.Add(tl);
 }
예제 #8
0
파일: TextLayer.cs 프로젝트: notgull/teolib
        /// <summary>
        /// Dialog with the specified width, height, dialog and charsPerLine.
        /// </summary>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="dialog">Dialog.</param>
        /// <param name="charsPerLine">Chars per line.</param>
        public static TextLayer Dialog(int width, int height, string dialog, int charsPerLine)
        {
            TextLayer tl             = new TextLayer(width, height);
            int       middleOfLayerX = Teolib.DivideThenFloor(width, 2);
            int       middleOfLayerY = Teolib.DivideThenFloor(height, 2);

            bool oddX = Teolib.IsNumberOdd(width);
            bool oddY = Teolib.IsNumberOdd(height);

            int requiredLines = Teolib.DivideThenCeil(dialog.Length, charsPerLine);     //Math.Ceiling (((decimal)(dialog.Length)) / (decimal)charsPerLine);
            int marginX       = Teolib.DivideThenFloor(width - charsPerLine, 2);        //Math.Floor (((decimal)(width - charsPerLine)) / 2);
            int marginY       = Teolib.DivideThenFloor(height - requiredLines, 2);      //Math.Floor (((decimal)(height - requiredLines)) / 2);

            List <string> lines           = new List <string> ();
            string        buffer          = "";
            int           currentPosition = 0;

            for (int i = 0; i < dialog.Length; i++)
            {
                buffer += dialog [i];
                currentPosition++;
                if (currentPosition + 1 >= charsPerLine || i == (dialog.Length - 1))
                {
                    lines.Add(buffer);
                    buffer          = "";
                    currentPosition = 0;
                }
            }

            currentPosition = 0;
            for (int i = marginY; i < marginY + requiredLines; i++)
            {
                string line = lines [currentPosition];
                int    start;
                int    limit;
                if (line.Length > charsPerLine)
                {
                    int requiredMargin = charsPerLine - line.Length;
                    int marginLeft;
                    int marginRight;
                    if (Teolib.IsNumberOdd(requiredMargin))
                    {
                        marginLeft  = Teolib.DivideThenFloor(requiredMargin, 2);
                        marginRight = Teolib.DivideThenCeil(requiredMargin, 2);
                    }
                    else
                    {
                        marginLeft = marginRight = requiredMargin / 2;
                    }
                    start = marginX + marginLeft;
                    limit = marginY - marginRight;
                }
                else
                {
                    start = marginX;
                    limit = marginX + charsPerLine;
                }
                int k = 0;
                for (int j = start; j < limit; j++)
                {
                    tl.ChangeLetterAt(j, i, line [k]);
                    k++;
                }
                currentPosition++;
            }

            return(tl);
        }
예제 #9
0
파일: TextLayer.cs 프로젝트: notgull/teolib
 /// <summary>
 /// Merges two layers.
 /// </summary>
 /// <returns>The merged layer</returns>
 /// <param name="bottom">Bottom.</param>
 /// <param name="top">Top.</param>
 public static TextLayer MergeLayers(TextLayer bottom, TextLayer top)
 {
     return(bottom.MergeLayer(top));
 }
예제 #10
0
파일: TextLayer.cs 프로젝트: notgull/teolib
 /// <summary>
 /// Merges this layer with another layer
 /// </summary>
 /// <returns>The merged layer</returns>
 /// <param name="other">Other layer</param>
 public TextLayer MergeLayer(TextLayer other)
 {
     return(MergeLayer(other, true));
 }