Example #1
0
        public StageData(string path, bool bossStage)
        {
            this.path = path;
            string[] stageData;
            int      currentLine;

            try
            {
                stageData   = Regex.Split(Encoding.ASCII.GetString(FileSys.Read(path)), @"\r\n?|\n");
                currentLine = 0;
            }
            catch
            {
                throw new Exception("ステージデータ「" + path + "」を読み込めません><");
            }
            try
            {
                numRows = int.Parse(stageData[currentLine]);
                currentLine++;
                numCols = int.Parse(stageData[currentLine]);
                currentLine++;
            }
            catch
            {
                throw new Exception("ステージデータ「" + path + "」の第" + (currentLine + 1) + "行のマップのサイズの指定がおかしいです><");
            }
            mapData = new string[numRows];
            for (int row = 0; row < numRows; row++)
            {
                try
                {
                    mapData[row] = stageData[currentLine];
                    currentLine++;
                }
                catch (IndexOutOfRangeException)
                {
                    throw new Exception("ステージデータ「" + path + "」の高さが指定されたものに一致しません><");
                }
                if (mapData[row].Length != numCols)
                {
                    throw new Exception("ステージデータ「" + path + "」の第" + (currentLine + 1) + "行の幅が指定されたものに一致しません><");
                }
            }
            List <string[]> thingDataList = new List <string[]>();

            while (currentLine < stageData.Length)
            {
                thingDataList.Add(stageData[currentLine].Split(' '));
                currentLine++;
            }
            thingData      = thingDataList.ToArray();
            this.bossStage = bossStage;
        }
Example #2
0
        /// <summary>
        /// 指定したファイルから画像を読み込み、その
        /// System.Drawing.Bitmap を返す。
        ///
        /// 画像の読み込み時には、System.FileSysを
        /// 利用するので、このファイルシステムにadd onされた
        /// アーカイバ等のなかのファイルであっても読める。
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        static public Bitmap LoadToBitmap(string filename)
        {
            try
            {
                // 実在するなら、そのまま読み込めば良い
                string realfile = FileSys.IsRealExist(filename);
                if (realfile != null)
                {
                    return(new Bitmap(realfile));
                }

                // memory stream経由で読み込むように修正

                byte[] data = FileSys.Read(filename);
                if (data == null)
                {
                    return(null);
                }

                using (MemoryStream stream = new MemoryStream(data))
                {
                    return(new Bitmap(stream));
                }
            }
            catch { }
            return(null);

            /*
             * Surface surface = new Surface();
             * if (surface.Load(filename) != YanesdkResult.NoError)
             *      return null;
             *
             * // Bitmap.FromHbitmap(surface.HBitmap);のほうがいいか?
             *
             * int w = surface.Width;
             * int h = surface.Height;
             *
             * Bitmap bitmap = new Bitmap(w,h);
             * BitmapData bmpdata;
             * if (surface.CheckRGB888())
             * {
             *      bmpdata = bitmap.LockBits(new Rectangle(0, 0, w, h),
             *              ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
             *
             *      // 画像コピー
             *      unsafe
             *      {
             *              // 最悪なのことにalignされている(´ω`)
             *
             *              byte* dst = (byte*)bmpdata.Scan0;
             *              int dst_pitch = bmpdata.Stride;
             *              byte* src = (byte*)surface.Pixels;
             *              int src_pitch = surface.Pitch;
             *
             *              for (int y = 0; y < h; ++y)
             *              {
             *                      for (int i = 0; i < w * 3; i += 3)
             *                      {
             *                              // しかもR,G,B逆かよ!(`ω´)
             *                              dst[i + 0] = src[i + 2];
             *                              dst[i + 1] = src[i + 1];
             *                              dst[i + 2] = src[i + 0];
             *                      }
             *                      src += src_pitch;
             *                      dst += dst_pitch;
             *              }
             *      }
             * }
             * else
             * {
             *      bmpdata = bitmap.LockBits(new Rectangle(0, 0, w, h),
             *              ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
             *
             *      // 画像コピー
             *      unsafe
             *      {
             *              // 最悪なのことにalignされている(´ω`)
             *
             *              byte* dst = (byte*)bmpdata.Scan0;
             *              int dst_pitch = bmpdata.Stride;
             *              byte* src = (byte*)surface.Pixels;
             *              int src_pitch = surface.Pitch;
             *
             *              for (int y = 0; y < h; ++y)
             *              {
             *                      for (int i = 0; i < w * 4; i += 4)
             *                      {
             *                              // しかもR,G,B逆かよ!(`ω´)
             *                              dst[i + 0] = src[i + 2];
             *                              dst[i + 1] = src[i + 1];
             *                              dst[i + 2] = src[i + 0];
             *                              dst[i + 3] = src[i + 3];
             *                      }
             *                      src += src_pitch;
             *                      dst += dst_pitch;
             *              }
             *      }
             * }
             *
             * bitmap.UnlockBits(bmpdata);
             *
             * return bitmap;
             */
        }
Example #3
0
        /// <summary>
        /// CSVファイルからデータを読み込む
        /// </summary>
        ///	<example>
        /// CSVReader reader = new CSVReader();
        ///	reader.read("csv.txt");
        ///	reader.DebugOutput();
        /// </example>
        /// <param name="filename"></param>
        /// <returns></returns>
        public YanesdkResult Read(string filename)
        {
            csvdata.Clear();

            byte[] data = FileSys.Read(filename);
            if (data == null)
            {
                return(YanesdkResult.FileReadError);
            }

            BOMFound = (data.Length >= 2 &&
                        data[0] == 0xff &&
                        data[1] == 0xfe);

            // このdataを解析していく。
            StringBuilderEncoding line = new StringBuilderEncoding();

            if (BOMFound)
            {
                for (int i = 2; i < data.Length;)
                {
                    byte b1 = data[i++];
                    if (!(i < data.Length))
                    {
                        break;
                    }
                    byte b2 = data[i++];
                    if (b2 == 0 && (b1 == 0x0a || b1 == 0x0d))
                    {
                        // 一行読めたのでlineを解析
                        Parse(line, BOMFound);
                        line.Clear();
                    }
                    else
                    {
                        line.Add(b1);
                        line.Add(b2);
                    }
                }
            }
            else
            {
                foreach (byte c in data)
                {
                    if (c == 0x0a || c == 0x0d)
                    {
                        // 一行読めたのでlineを解析
                        Parse(line, BOMFound);
                        line.Clear();
                    }
                    else
                    {
                        line.Add(c);
                    }
                }
            }
            // 最後に改行なしのlineがある可能性アリ
            if (line.Count != 0)
            {
                Parse(line, BOMFound);
            }

            return(YanesdkResult.NoError);
        }