示例#1
0
 public MapClass(String filename)
 {
     MapFile = new MAP(FileSystem.LoadFile(filename));
     Instance = this;
 }
示例#2
0
        public void Initialize(String filename = null)
        {
            if (filename != null) {
                MapFile = new MAP(FileSystem.LoadFile(filename));
            }

            ClearCells();

            String TheaterName = "";
            MapFile.GetString("Map", "Theater", out TheaterName, "");

            if (!MapTheater.Theaters.ContainsKey(TheaterName)) {
                throw new InvalidDataException(String.Format("Theater {0} is not recognized.", TheaterName));
            }

            MapFile.GetInteger("Map", "Level", out BaseLevel, 0);

            int[] sz = new int[4];
            if (MapFile.Get4Integers("Map", "Size", out sz, new int[4])) {
                MapSize = new Rectangle() { X = sz[0], Y = sz[1], Width = sz[2], Height = sz[3] };

                MapRect = MapSize;

                CreateMap();
            }

            if(MapFile.Get4Integers("Map", "LocalSize", out sz, sz)) {
                LocalSize = new Rectangle() { X = sz[0], Y = sz[1], Width = sz[2], Height = sz[3] };
            }

            TheaterData = MapTheater.Theaters[TheaterName];

            MapTheater.Init(TheaterData);

            foreach (var packedTile in MapFile.Tiles) {
                var x = packedTile.X;
                var y = packedTile.Y;
                var cell = GetCellAt(x, y);
                if (cell != null) {
                    cell.IsoTileTypeIndex = (int)packedTile.TileTypeIndex;
                    cell.IsoTileTypeSubIndex = (int)packedTile.TileSubtypeIndex;
                    cell.Level = BaseLevel + packedTile.Level;
                } else {
                    Debug.WriteLine("Failed to find cell at {0}x{1}", x, y);
                }
            }

            for(var y = 0; y < 512; ++y) {
                for (var x = 0; x < 512; ++x) {
                    var cell = GetCellAt(x, y);
                    if (cell != null) {
                        var idx = (MapFile.Overlays[y * 512 + x] & 0xFF);
                        if (idx != 0xFF) {
                            cell.OverlayTypeIndex = idx;
                        }
                        cell.OverlayState = MapFile.OverlayStates[y * 512 + x];
                    }
                }
            }
        }