예제 #1
0
        private void Init(MapDescriptorFile MapFile)
        {
            this.MapFile = MapFile;

            BlockWidth  = (int)MapFile.BlockWidth;
            BlockHeight = (int)MapFile.BlockHeight;
        }
예제 #2
0
        public MapDataLoader(string FileName)
        {
            FileDirectory = Path.GetDirectoryName(FileName);
            FileBaseName  = Path.GetFileNameWithoutExtension(FileName);

            MapDescriptorFile MapFile;

            using (Stream FileStream = File.Open(FileName, FileMode.Open))
            {
                NetworkReader r = new NetworkReader(FileStream);
                MapFile = new MapDescriptorFile();
                MapFile.Read(r);
            }
            Init(MapFile);
        }
예제 #3
0
        public static void CreateMap(int Width, int Height, TileData[] Tiles, Action <double, string> UpdateLoading, ushort[,] DefaultTiles = null)
        {
            UpdateLoading(0.1, $"Creating Map Descriptor...");

            DispatchQueue.DispatchIO(() =>
            {
                if (!Directory.Exists(MapTempPath))
                {
                    Directory.CreateDirectory(MapTempPath);
                }

                MapDescriptorFile MapFile = new MapDescriptorFile()
                {
                    BlockWidth  = (uint)Math.Ceiling((double)Width / MapDescriptorFile.Block_Size),
                    BlockHeight = (uint)Math.Ceiling((double)Height / MapDescriptorFile.Block_Size)
                };

                int BlocksDone = 0;
                int Blocks     = (int)MapFile.BlockHeight * (int)MapFile.BlockWidth;

                MapFile.Blocks = new string[MapFile.BlockWidth, MapFile.BlockHeight];
                for (int y = 0; y < MapFile.BlockHeight; y++)
                {
                    for (int x = 0; x < MapFile.BlockWidth; x++)
                    {
                        UpdateLoading(0.1 + 0.5 * (((double)BlocksDone + 1) / Blocks), $"Creating Block {BlocksDone + 1} / {Blocks}...");
                        int StartX      = x * MapDescriptorFile.Block_Size;
                        int StartY      = y * MapDescriptorFile.Block_Size;
                        BlockFile Block = new BlockFile()
                        {
                            Width  = (ushort)((Width - StartX < MapDescriptorFile.Block_Size) ? Width - StartX : MapDescriptorFile.Block_Size),
                            Height = (ushort)((Height - StartY < MapDescriptorFile.Block_Size) ? Height - StartY : MapDescriptorFile.Block_Size)
                        };
                        Block.Tiles = new ushort[Block.Width, Block.Height];
                        for (int yy = 0; yy < Block.Height; yy++)
                        {
                            for (int xx = 0; xx < Block.Width; xx++)
                            {
                                if (DefaultTiles == null)
                                {
                                    Block.Tiles[xx, yy] = Tiles[0].Type;
                                }
                                else
                                {
                                    Block.Tiles[xx, yy] = DefaultTiles[StartX + xx, StartY + yy];
                                }
                            }
                        }
                        string FileName      = MapDataTempName.Replace("%", $"_{y * MapFile.BlockWidth + x}");
                        MapFile.Blocks[x, y] = FileName;
                        using (MemoryStream Stream = new MemoryStream())
                        {
                            NetworkWriter w = new NetworkWriter(Stream);
                            Block.Write(w);
                            File.WriteAllBytes(Path.Combine(MapTempPath, FileName), Stream.ToArray());
                        }

                        BlocksDone++;
                    }
                }

                UpdateLoading(0.7, $"Saving Map Descriptor...");

                using (MemoryStream Stream = new MemoryStream())
                {
                    NetworkWriter w = new NetworkWriter(Stream);
                    MapFile.Write(w);
                    File.WriteAllBytes(Path.Combine(MapTempPath, MapTempName), Stream.ToArray());
                }

                UpdateLoading(0.8, $"Rasterizing First Block...");

                DispatchQueue.DispatchMain(() =>
                {
                    JuixelGame.Shared.ChangeScene(new MapScene(new MapDataLoader(Path.Combine(MapTempPath, MapTempName)),
                                                               Tiles, JuixelGame.Shared.CurrentScene.Size));
                });
            });
        }