Ejemplo n.º 1
0
 public void RemoveTile(Vector3Int position, LayerType refLayer, bool removeAll)
 {
     if (!Layers.ContainsKey(refLayer))
     {
         return;
     }
     Layers[refLayer].RemoveTile(position, removeAll);
 }
Ejemplo n.º 2
0
 public void LoadTileData(byte[] packet)
 {
     Layers = JsonConvert.DeserializeObject <Dictionary <string, Tile[, ]> >(LZ4.UnPickleString(packet), mJsonSerializerSettings);
     foreach (var layer in Options.Instance.MapOpts.Layers.All)
     {
         if (!Layers.ContainsKey(layer))
         {
             Layers.Add(layer, new Tile[Options.MapWidth, Options.MapHeight]);
         }
     }
 }
Ejemplo n.º 3
0
 private List <Entity2D> GetLayer(string layerName)
 {
     if (Layers.ContainsKey(layerName))
     {
         return(Layers[layerName]);
     }
     else
     {
         var layer = new List <Entity2D>();
         Layers.Add(layerName, layer);
         return(layer);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Try and add a layer to the map. Returns false if fails.
 /// </summary>
 /// <param name="_key"></param>
 /// <param name="_layer"></param>
 /// <returns></returns>
 internal bool TryAddLayer(string _key, MapLayer _layer)
 {
     if (Layers == null)
     {
         Layers = new Dictionary <string, MapLayer>();
     }
     if (!Layers.ContainsKey(_key) && (_layer.TileIds.Length == Size))
     {
         _layer.Build(this);
         Layers.Add(_key, _layer);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
    public void SetPreviewTile(Vector3Int position, LayerTile tile, Matrix4x4 transformMatrix)
    {
        for (var i = 0; i < LayersValues.Length; i++)
        {
            Layer layer = LayersValues[i];
            if (layer.LayerType < tile.LayerType)
            {
                Layers[layer.LayerType].SetPreviewTile(position, LayerTile.EmptyTile, Matrix4x4.identity);
            }
        }

        if (!Layers.ContainsKey(tile.LayerType))
        {
            Logger.LogErrorFormat($"LAYER TYPE: {0} not found!", Category.TileMaps, tile.LayerType);
            return;
        }

        Layers[tile.LayerType].SetPreviewTile(position, tile, transformMatrix);
    }
Ejemplo n.º 6
0
        public bool Tick()
        {
            if (PlayerPos == Layers.Keys.Max())
            {
                return(false);
            }

            PlayerPos++;

            if (Layers.ContainsKey(PlayerPos) && Layers[PlayerPos].ScannerPos == 0)
            {
                Caught.Add(PlayerPos);
            }


            //(wait + pos) % (2 * (height - 1)) == 0

            TickLayers();

            return(true);
        }
Ejemplo n.º 7
0
        private GameTileBuffer[][] DrawMapLayer(string layerName, float xoffset = 0, float yoffset = 0)
        {
            var tileBuffers = new Dictionary <object, GameTileBuffer[]>();

            if (!Layers.ContainsKey(layerName))
            {
                return(null);
            }

            for (var x = 0; x < Options.MapWidth; x++)
            {
                for (var y = 0; y < Options.MapHeight; y++)
                {
                    var tile = Layers[layerName][x, y];
                    if (tile.TilesetTex == null)
                    {
                        continue;
                    }

                    var tilesetTex = (GameTexture)tile.TilesetTex;

                    if (tile.X < 0 || tile.Y < 0)
                    {
                        continue;
                    }

                    if (tile.X * Options.TileWidth >= tilesetTex.GetWidth() ||
                        tile.Y * Options.TileHeight >= tilesetTex.GetHeight())
                    {
                        continue;
                    }

                    var platformTex = tilesetTex.GetTexture();

                    GameTileBuffer[] buffers = null;
                    if (tileBuffers.ContainsKey(platformTex))
                    {
                        buffers = tileBuffers[platformTex];
                    }
                    else
                    {
                        buffers = new GameTileBuffer[3];
                        for (var i = 0; i < 3; i++)
                        {
                            buffers[i] = Graphics.Renderer.CreateTileBuffer();
                        }

                        tileBuffers.Add(platformTex, buffers);
                    }

                    switch (Autotiles.Layers[layerName][x, y].RenderState)
                    {
                    case MapAutotiles.RENDER_STATE_NORMAL:
                        for (var i = 0; i < 3; i++)
                        {
                            var buffer = buffers[i];
                            if (!buffer.AddTile(
                                    tilesetTex, x * Options.TileWidth + xoffset, y * Options.TileHeight + yoffset,
                                    Layers[layerName][x, y].X * Options.TileWidth,
                                    Layers[layerName][x, y].Y * Options.TileHeight, Options.TileWidth,
                                    Options.TileHeight
                                    ))
                            {
                                throw new Exception("Failed to add VBO!");
                            }
                        }

                        break;

                    case MapAutotiles.RENDER_STATE_AUTOTILE:
                        for (var i = 0; i < 3; i++)
                        {
                            DrawAutoTile(
                                layerName, x * Options.TileWidth + xoffset, y * Options.TileHeight + yoffset, 1, x, y,
                                i, tilesetTex, buffers[i]
                                );

                            DrawAutoTile(
                                layerName, x * Options.TileWidth + Options.TileWidth / 2 + xoffset,
                                y * Options.TileHeight + yoffset, 2, x, y, i, tilesetTex, buffers[i]
                                );

                            DrawAutoTile(
                                layerName, x * Options.TileWidth + xoffset,
                                y * Options.TileHeight + Options.TileHeight / 2 + yoffset, 3, x, y, i, tilesetTex,
                                buffers[i]
                                );

                            DrawAutoTile(
                                layerName, +x * Options.TileWidth + Options.TileWidth / 2 + xoffset,
                                y * Options.TileHeight + Options.TileHeight / 2 + yoffset, 4, x, y, i, tilesetTex,
                                buffers[i]
                                );
                        }

                        break;
                    }
                }
            }

            var outputBuffers = new GameTileBuffer[3][];

            for (var i = 0; i < 3; i++)
            {
                outputBuffers[i] = new GameTileBuffer[tileBuffers.Count];
            }

            var valueArrays = tileBuffers.Values.ToArray();

            for (var x = 0; x < valueArrays.Length; x++)
            {
                for (var i = 0; i < 3; i++)
                {
                    outputBuffers[i][x] = valueArrays[x][i];
                }
            }

            mTileBufferDict[layerName] = tileBuffers;

            return(outputBuffers);
        }
Ejemplo n.º 8
0
 public bool HasLayer(string name)
 {
     return(Layers.ContainsKey(name));
 }
Ejemplo n.º 9
0
        //---------------------------------------------------------------------------

        public Layer this[ELayerMode mode]
        {
            get { return(Layers.ContainsKey(mode) ? Layers[mode] : null); }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Swtich to the given index layer and use the given action after the layer is
        /// added to the parent. The parameter can be the index or it can be the tag of the layer.
        /// </summary>
        /// <param name="n">Send in NoLayer to hide all multiplexed layers. Otherwise, send in a tag or the logical index of the
        /// layer to show.</param>
        /// <returns>The layer that is going to be shown. This can return null if the SwitchTo layer is NoLayer</returns>
        public CCLayer SwitchTo(int n)
        {
            if (n != NoLayer)
            {
                if (EnabledLayer == n || EnabledLayer == (n + TagOffsetForUniqueness))
                {
                    if (EnabledLayer == NoLayer)
                    {
                        return(null);
                    }
                    return(Layers[EnabledLayer]);
                }
            }

            if (EnabledLayer != NoLayer)
            {
                CCLayer outLayer = null;
                if (Layers.ContainsKey(EnabledLayer))
                {
                    outLayer = Layers[EnabledLayer];
                    if (OutAction != null)
                    {
                        outLayer.RunAction(
                            new CCSequence(
                                (CCFiniteTimeAction)OutAction,
                                new CCCallFunc(() => RemoveChild(outLayer, true))
                                )
                            );
                    }
                    else
                    {
                        RemoveChild(outLayer, true);
                    }
                }
                // We have no enabled layer at this point
                EnabledLayer = NoLayer;
            }

            // When NoLayer, the multiplexer shows nothing.
            if (n == NoLayer)
            {
                ShowFirstLayerOnEnter = false;
                return(null);
            }

            if (!Layers.ContainsKey(n))
            {
                int f = n + TagOffsetForUniqueness;
                if (Layers.ContainsKey(f))
                {
                    n = f;
                }
                else
                {
                    // Invalid index - layer not found
                    return(null);
                }
            }

            // Set the active layer
            AddChild(Layers[n]);
            EnabledLayer = n;

            if (InAction != null)
            {
                Layers[n].RunAction(InAction);
            }

            return(Layers[EnabledLayer]);
        }