예제 #1
0
        public static Blockset LoadOrGet(int id)
        {
            string name = _ids[id];

            if (name is null)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }
            Blockset b;

            if (!_loadedBlocksets.ContainsKey(id))
            {
                b = new Blockset(name);
                _loadedBlocksets.Add(id, new WeakReference <Blockset>(b));
                return(b);
            }
            WeakReference <Blockset> w = _loadedBlocksets[id];

            if (w.TryGetTarget(out b))
            {
                return(b);
            }
            b = new Blockset(name);
            w.SetTarget(b);
            return(b);
        }
예제 #2
0
                public Block(Layout parent, EndianBinaryReader r)
                {
                    Parent = parent;

                    Elevations    = r.ReadByte();
                    Passage       = r.ReadEnum <LayoutBlockPassage>();
                    BlocksetBlock = Blockset.LoadOrGet(r.ReadInt32()).Blocks[r.ReadInt32()];
                }
예제 #3
0
            public readonly Tile[][][][] Tiles; // Y,X,Elevation,Sublayers

            public Block(Blockset parent, EndianBinaryReader r)
            {
                Behavior = r.ReadEnum <BlocksetBlockBehavior>();
                Tile[][] Read()
                {
                    var eLayers = new Tile[Overworld.NumElevations][];

                    for (byte e = 0; e < Overworld.NumElevations; e++)
                    {
                        byte   count = r.ReadByte();
                        Tile[] subLayers;
                        if (count == 0)
                        {
                            subLayers = Array.Empty <Tile>();
                        }
                        else
                        {
                            subLayers = new Tile[count];
                            for (int i = 0; i < count; i++)
                            {
                                subLayers[i] = new Tile(r);
                            }
                        }
                        eLayers[e] = subLayers;
                    }
                    return(eLayers);
                }

                Tiles = new Tile[Overworld.Block_NumTilesY][][][];
                for (int y = 0; y < Overworld.Block_NumTilesY; y++)
                {
                    var arrY = new Tile[Overworld.Block_NumTilesX][][];
                    for (int x = 0; x < Overworld.Block_NumTilesX; x++)
                    {
                        arrY[x] = Read();
                    }
                    Tiles[y] = arrY;
                }
                Parent = parent;
            }