Exemple #1
0
    async void ReadTest()
    {
        pathText.text = Application.streamingAssetsPath;
        string path = Application.streamingAssetsPath + "/Project/Data/MapData/SampleMapA.mps";

        Debug.Log(path);
        var     mpsReader = new MpsFileReader();
        MapData mapData   = await mpsReader.ReadFileAsync(path);

        infoText.text = mapData.MapSizeWidth.ToString();
    }
Exemple #2
0
        private static void Common(MapData resultData, string readFileName)
        {
            var reader = new MpsFileReader($@"{MapFileTestItemGenerator.TestWorkRootDir}\{readFileName}");

            var     readResult   = false;
            MapData data         = null;
            var     errorMessage = "";

            try
            {
                data       = reader.ReadSync();
                readResult = true;
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }


            // 正しく読めること
            if (!readResult)
            {
                throw new InvalidOperationException(
                          $"Error Occured. Message : {errorMessage}");
            }

            Console.WriteLine("Write Test Clear.");

            // 意図したデータと一致すること
            var resultDataBytes     = resultData.ToBinary().ToArray();
            var readResultDataBytes = data.ToBinary().ToArray();

            if (resultDataBytes.Length != readResultDataBytes.Length)
            {
                throw new InvalidOperationException(
                          $"Data Length Not Match. " +
                          $"(answerLength: {resultDataBytes.Length}, readResultLength: {readResultDataBytes.Length})");
            }

            for (long i = 0; i < 0; i++)
            {
                if (resultDataBytes[i] != readResultDataBytes[i])
                {
                    throw new InvalidOperationException(
                              $"Data Byte Not Match. (index: {i}, answer: {resultDataBytes[i]}," +
                              $" readResult: {readResultDataBytes[i]})");
                }
            }
        }
Exemple #3
0
        async Task InitializeMapData(string dataPath)
        {
            DatabaseDataDescList mapSettingList = CoreData.Instance.systemDB.GetDataDescList(0);

            CoreData.Instance.mapEventCurrentPages = new int[mapSettingList.Count][];
            CoreData.Instance.mapDataArray         = new MapData[mapSettingList.Count];
            CoreData.Instance.mapVariables         = new int[mapSettingList.Count][][];
            for (int i = 0; i < mapSettingList.Count; i++)
            {
                string  mapPath   = dataPath + mapSettingList[i].ItemValueList[0].StringValue.ToString();
                var     mpsReader = new MpsFileReader();
                MapData mapData   = await mpsReader.ReadFileAsync(mapPath);

                CoreData.Instance.mapDataArray[i]         = mapData;
                CoreData.Instance.mapEventCurrentPages[i] = new int[mapData.MapEvents.Count];
                CoreData.Instance.mapVariables[i]         = new int[mapData.MapEvents.Count][];
                for (int j = 0; j < mapData.MapEvents.Count; j++)
                {
                    CoreData.Instance.mapVariables[i][j] = new int[10];
                }
            }
        }
Exemple #4
0
        public static void SampleMapBIOTest()
        {
            const string inputFileName  = "SampleMapB.mps";
            const string outputFileName = "OutputSampleMapB.mps";

            var     reader        = new MpsFileReader($@"{MapFileTestItemGenerator.TestWorkRootDir}\{inputFileName}");
            MapData data          = null;
            var     isSuccessRead = false;

            try
            {
                data          = reader.ReadAsync().GetAwaiter().GetResult();
                isSuccessRead = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
            }

            Assert.IsTrue(isSuccessRead);

            var writer = new MpsFileWriter(
                $@"{MapFileTestItemGenerator.TestWorkRootDir}\{outputFileName}");
            var isSuccessWrite = false;

            try
            {
                writer.WriteAsync(data).GetAwaiter().GetResult();
                isSuccessWrite = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
            }

            Assert.IsTrue(isSuccessWrite);

            Console.WriteLine($@"Written FilePath : {MapFileTestItemGenerator.TestWorkRootDir}\{outputFileName}");
        }
Exemple #5
0
        public static void DungeonIOTest()
        {
            const string inputFileName  = "Dungeon.mps";
            const string outputFileName = "OutputDungeon.mps";

            var     reader        = new MpsFileReader($@"{MapFileTestItemGenerator.TestWorkRootDir}\{inputFileName}");
            MapData data          = null;
            var     isSuccessRead = false;

            try
            {
                data          = reader.ReadSync();
                isSuccessRead = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
            }

            Assert.IsTrue(isSuccessRead);

            var writer = new MpsFileWriter(
                $@"{MapFileTestItemGenerator.TestWorkRootDir}\{outputFileName}");
            var isSuccessWrite = false;

            try
            {
                writer.WriteSync(data);
                isSuccessWrite = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
            }

            Assert.IsTrue(isSuccessWrite);
        }
Exemple #6
0
    async void RenderMap()
    {
        DatabaseMergedData systemDB = await ReadSystemDB();

        var mapDataList = systemDB.GetDataDescList(0);

        if (mapNo >= mapDataList.Count)
        {
            return;
        }

        string  mapPath   = dataPath + mapDataList[mapNo].ItemValueList[0].StringValue.ToString();
        var     mpsReader = new MpsFileReader();
        MapData mapData   = await mpsReader.ReadFileAsync(mapPath);

        string      tileSetPath = dataPath + "BasicData/TileSetData.dat";
        var         reader      = new TileSetDataFileReader();
        TileSetData setData     = await reader.ReadFileAsync(tileSetPath);

        TileSetSetting tileSetting = setData.TileSetSettingList[mapData.TileSetId];

        ReadBaseTileTexture(tileSetting.BaseTileSetFileName);

        ReadAutoTileTextures(tileSetting.AutoTileFileNameList.ToArray());

        Texture2D mapTexture
            = new Texture2D(mapData.MapSizeWidth * chipSize, mapData.MapSizeHeight * chipSize);

        for (int i = 0; i < mapData.MapSizeHeight; i++)
        {
            for (int j = 0; j < mapData.MapSizeWidth; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    int id = mapData.GetLayer(k).Chips[j][i];
                    if (mapData.GetLayer(k).Chips[j][i].IsAutoTile)
                    {
                        RenderAutoTile(mapTexture, j, i, id);
                    }
                    else
                    {
                        RenderNormalTile(mapTexture, j, i, id);
                    }
                }
            }
        }

        for (int i = 0; i < mapData.MapEvents.Count; i++)
        {
            int          x            = mapData.MapEvents[i].Position.X;
            int          y            = mapData.MapEvents[i].Position.Y;
            MapEventPage mapEventPage = mapData.MapEvents[i].MapEventPageList[0];
            if (mapEventPage.GraphicInfo.IsGraphicTileChip)
            {
                int tileId = mapEventPage.GraphicInfo.GraphicTileId;
                RenderNormalTile(mapTexture, x, y, tileId);
            }
            else if (!string.IsNullOrEmpty(mapEventPage.GraphicInfo.CharaChipFilePath))
            {
                string graphicPath = dataPath + mapEventPage.GraphicInfo.CharaChipFilePath;
                Debug.Log(graphicPath);
                CharaChipDirection charaChipDirection = mapEventPage.GraphicInfo.InitDirection;
                Texture2D          charaChipTexture   = new Texture2D(1, 1);
                byte[]             bytes = System.IO.File.ReadAllBytes(graphicPath);
                charaChipTexture.LoadImage(bytes);
                charaChipTexture.filterMode = FilterMode.Point;
                RenderCharaChip(mapTexture, x, y, charaChipTexture, charaChipDirection);
            }
        }

        mapTexture.Apply();
        mapTexture.filterMode = FilterMode.Point;

        Sprite sprite = Sprite.Create(mapTexture,
                                      new Rect(0.0f, 0.0f, mapTexture.width, mapTexture.height), new Vector2(0.5f, 0.5f), 1.0f);

        mapSprite.sprite = sprite;
    }