private void OnDialogApply(object sender, EventArgs eventArgs)
        {
            List <StaticTile> tileFrames = new List <StaticTile>();

            foreach (ListViewItem listViewItem in m_animationListView.Items)
            {
                tileFrames.Add((StaticTile)listViewItem.Tag);
            }
            AnimatedTile animatedTile = new AnimatedTile(
                m_layer, tileFrames.ToArray(), (long)m_frameIntervalTextbox.Value);

            // copy anim tile-level properties
            Tile oldTile = m_layer.Tiles[m_tileLocation];

            if (oldTile != null)
            {
                animatedTile.Properties.CopyFrom(oldTile.Properties);
            }

            Command command = new TileAnimationCommand(m_layer, m_tileLocation, animatedTile);

            CommandHistory.Instance.Do(command);

            MarkAsApplied();
        }
 void Update()
 {
     if (allTilesGenerated != true)
     {
         var tile = GetNextTile();
         WaterTileMap.SetTile(new Vector3Int(xValue, yValue, 0), null);
         GroundTileMap.SetTile(new Vector3Int(xValue, yValue, 0), tile);
         LastPlacedTile = tile;
         if (LastPlacedTile == VerticalTile || LastPlacedTile == LeftToDownTile || LastPlacedTile == RightToDownTile)
         {
             yValue -= 1;
             if (yValue == bottomEdgeValue)
             {
                 WaterTileMap.SetTile(new Vector3Int(xValue, yValue, 0), null);
                 FinishTileMap.SetTile(new Vector3Int(xValue, yValue, 0), FinishTile);
                 allTilesGenerated = true;
             }
         }
         if (LastPlacedTile == HorizontalRightToLeft || LastPlacedTile == DownToLeftTile)
         {
             xValue -= 1;
         }
         if (LastPlacedTile == HorizontalLeftToRight || LastPlacedTile == DownToRightTile)
         {
             xValue += 1;
         }
     }
 }
        private void OnDialogLoad(object sender, EventArgs eventArgs)
        {
            Tile tile = m_layer.Tiles[m_tileLocation];

            if (tile != null)
            {
                if (tile is StaticTile)
                {
                    // convert to 1-frame animation
                    m_frameIntervalTextbox.Value = 250;
                    AddTileFrame(tile.Clone(this.m_layer) as StaticTile);
                }
                else if (tile is AnimatedTile)
                {
                    AnimatedTile animatedTile = tile as AnimatedTile;
                    m_frameIntervalTextbox.Value = animatedTile.FrameInterval;
                    foreach (StaticTile tileFrame in animatedTile.TileFrames)
                    {
                        AddTileFrame(tileFrame.Clone(this.m_layer) as StaticTile);
                    }
                }
            }
            else
            {
                m_frameIntervalTextbox.Value = 250;
            }

            m_tilePicker.Map = m_map;
            m_tilePicker.UpdatePicker();

            MarkAsApplied();
        }
예제 #4
0
        private AnimatedTile LoadAnimatedTile(XmlHelper xmlHelper, Layer layer, TileSheet tileSheet)
        {
            int frameInterval = xmlHelper.GetIntAttribute("Interval");

            xmlHelper.AdvanceStartElement("Frames");

            Map map = layer.Map;
            List <StaticTile> tileFrames = new List <StaticTile>();

            while (xmlHelper.AdvanceNode() != XmlNodeType.EndElement)
            {
                if (xmlHelper.XmlReader.Name == "Static")
                {
                    tileFrames.Add(LoadStaticTile(xmlHelper, layer, tileSheet));
                }
                else if (xmlHelper.XmlReader.Name == "TileSheet")
                {
                    string tileSheetRef = xmlHelper.GetAttribute("Ref");
                    tileSheet = map.GetTileSheet(tileSheetRef);
                }
            }

            AnimatedTile animatedTile
                = new AnimatedTile(layer, tileFrames.ToArray(), frameInterval);

            // end of this element or optional props
            if (xmlHelper.AdvanceNode() != XmlNodeType.EndElement)
            {
                LoadProperties(xmlHelper, animatedTile);
            }

            return(animatedTile);
        }
예제 #5
0
        private void StoreAnimatedTile(AnimatedTile animatedTile, XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("Animated");
            xmlWriter.WriteAttributeString("Interval", animatedTile.FrameInterval.ToString());

            xmlWriter.WriteStartElement("Frames");
            TileSheet tileSheet = null;

            foreach (StaticTile tileFrame in animatedTile.TileFrames)
            {
                if (tileSheet != tileFrame.TileSheet)
                {
                    xmlWriter.WriteStartElement("TileSheet");
                    xmlWriter.WriteAttributeString("Ref", tileFrame.TileSheet.Id);
                    xmlWriter.WriteEndElement();

                    tileSheet = tileFrame.TileSheet;
                }
                StoreStaticTile(tileFrame, xmlWriter);
            }
            xmlWriter.WriteEndElement(); // Frames

            if (animatedTile.Properties.Count > 0)
            {
                StoreProperties(animatedTile, xmlWriter);
            }

            xmlWriter.WriteEndElement();
        }
예제 #6
0
        private AnimatedTile LoadAnimatedTile(Stream stream, Layer layer)
        {
            long frameInterval           = LoadInt32(stream);
            int  tileFrameCount          = LoadInt32(stream);
            List <StaticTile> tileFrames = new List <StaticTile>(tileFrameCount);

            Map       map       = layer.Map;
            TileSheet tileSheet = null;

            while (tileFrameCount > 0)
            {
                char ch = (char)stream.ReadByte();
                if (ch == 'T')
                {
                    string tileSheetId = LoadString(stream);
                    tileSheet = map.GetTileSheet(tileSheetId);
                }
                else if (ch == 'S')
                {
                    tileFrames.Add(LoadStaticTile(stream, layer, tileSheet));
                    --tileFrameCount;
                }
                else
                {
                    throw new Exception("Expected character byte 'T' or 'S'");
                }
            }

            AnimatedTile animatedTile = new AnimatedTile(layer, tileFrames.ToArray(), frameInterval);

            LoadProperties(stream, animatedTile);

            return(animatedTile);
        }
예제 #7
0
    /// <summary>
    /// Creates an animated tile in world position
    /// </summary>
    /// <param name="worldPosition"> Where to create tile </param>
    /// <param name="animatedTile"></param>
    /// <param name="animationTime"></param>
    public void CreateAnimatedTile(Vector3 worldPosition, AnimatedTile animatedTile, float animationTime)
    {
        Vector3Int cellPos            = metaTileMap.WorldToCell(worldPosition);
        var        oldEffectLayerTile = metaTileMap.GetTile(cellPos, LayerType.Effects);

        StartCoroutine(EnableAnimationCoroutine(cellPos, animatedTile, animationTime, oldEffectLayerTile));
    }
예제 #8
0
    // Called on the first frame update
    private void Start()
    {
        try
        {
            GameObject genContObj    = GameObject.FindWithTag("PersistantController");
            TileSet    activeTileSet = genContObj.GetComponent <PersistantController>().GetActiveTileSet();
            _litCampfire = activeTileSet.GetLitCampfire();
        }
        catch
        {
            Debug.LogError("Error setting lit campfire");
        }

        _tilemapRef = GameObject.FindWithTag("Tilemap").GetComponent <Tilemap>();

        // Get the audio manager
        try
        {
            _audManRef = GameObject.FindWithTag("AudioManager").GetComponent <AudioManager>();
        }
        catch
        {
            Debug.Log("Could not get AudioManager");
        }
    }
예제 #9
0
        // If you're getting "error CS0246: The type of namespace name 'AnimatedTile' could not be found", then you need the prerequisite AnimatedTile class from
        // https://github.com/Unity-Technologies/2d-techdemos/blob/master/Assets/Tilemap/Tiles/Animated%20Tile/Scripts/AnimatedTile.cs
        // and put it somewhere in your project.
        static ImportedTile CreateAnimatedTileAsset(Sprite tileSprite, Sprite[] animatedSprites, float animationSpeed, string tileAssetPath, Tile.ColliderType colliderType)
        {
            AnimatedTile tile = AssetDatabase.LoadAssetAtPath <AnimatedTile>(tileAssetPath);

            if (tile == null)
            {
                tile = AnimatedTile.CreateInstance <AnimatedTile>();
                tile.m_AnimatedSprites    = animatedSprites;
                tile.m_AnimationStartTime = 0.0f;
                tile.m_MinSpeed           = animationSpeed;
                tile.m_MaxSpeed           = animationSpeed;
                tile.sprite       = tileSprite;
                tile.colliderType = colliderType;

                AssetDatabase.CreateAsset(tile, tileAssetPath);
            }
            else if ((tile.m_AnimatedSprites == null) == (animatedSprites == null) ||
                     tile.m_AnimatedSprites == null ||
                     animatedSprites == null ||
                     !tile.m_AnimatedSprites.SequenceEqual <Sprite>(animatedSprites) ||
                     tile.m_MinSpeed != animationSpeed ||
                     tile.m_MaxSpeed != animationSpeed ||
                     tile.sprite != tileSprite ||
                     tile.colliderType != colliderType)
            {
                tile.m_AnimatedSprites = animatedSprites;
                tile.m_MinSpeed        = animationSpeed;
                tile.m_MaxSpeed        = animationSpeed;
                tile.sprite            = tileSprite;
                tile.colliderType      = colliderType;
                EditorUtility.SetDirty(tile);
            }

            return(new ImportedTile(tile, tileAssetPath));
        }
예제 #10
0
        public void ResetAnim()
        {
            if (dlayers == null)
            {
                return;
            }

            int numRedone = 0;

            foreach (Tile t in dlayers[0].Values)
            {
                if (!(t is AnimatedTile))
                {
                    continue;
                }
                AnimatedTile tt = (AnimatedTile)t;
                tt.Reset();
                numRedone++;
            }

            if (numRedone >= 2) //redraw if we've redone 2 or more
            {
                this.Refresh();
            }
        }
 public TileAnimationCommand(Layer layer, Location tileLocation, AnimatedTile animatedTile)
 {
     m_layer        = layer;
     m_tileLocation = tileLocation;
     m_animatedTile = animatedTile;
     m_oldTile      = null;
     m_description  = "Set animated tile at " + tileLocation;
 }
예제 #12
0
        internal Tile LoadTile(Layer layer, TMXMap tmxMap, UInt32 gid)
        {
            if (gid == 0)
            {
                return(null);
            }
            TileSheet selectedTileSheet = null;

            int  tileIndex            = -1;
            uint g                    = gid;
            bool flipped_horizontally = false;
            bool flipped_vertically   = false;
            bool flipped_diagonally   = false;

            if (g >= FLIPPED_HORIZONTALLY_FLAG)
            {
                flipped_horizontally = true;
                g -= FLIPPED_HORIZONTALLY_FLAG;
            }

            if (g >= FLIPPED_VERTICALLY_FLAG)
            {
                flipped_vertically = true;
                g -= FLIPPED_VERTICALLY_FLAG;
            }

            if (g >= FLIPPED_DIAGONALLY_FLAG)
            {
                flipped_diagonally = true;
            }

            gid &= ~(FLIPPED_HORIZONTALLY_FLAG |
                     FLIPPED_VERTICALLY_FLAG |
                     FLIPPED_DIAGONALLY_FLAG);

            foreach (TileSheet tileSheet in layer.Map.TileSheets)
            {
                UInt32 property1 = (UInt32)tileSheet.Properties["@FirstGid"];
                UInt32 property2 = (UInt32)tileSheet.Properties["@LastGid"];
                if (gid >= property1 && gid <= property2)
                {
                    selectedTileSheet = tileSheet;
                    tileIndex         = (int)(gid - property1);
                    break;
                }
            }
            if (selectedTileSheet == null)
            {
                throw new Exception(string.Format("Invalid tile gid: {0}", gid));
            }

            Tile result = null;

            if (tmxMap.Tilesets.Where(ts => ts.Name == selectedTileSheet.Id).FirstOrDefault() is TMXTileset tileset && tileset.Tiles.Where(t => t.Id == tileIndex).FirstOrDefault() is TMXTileSetTile tile && tile.Animations != null && tile.Animations.Count() > 0)
            {
                StaticTile[] array = tile.Animations.Select(frame => new StaticTile(layer, selectedTileSheet, BlendMode.Alpha, (int)frame.TileId)).ToArray();
                result = new AnimatedTile(layer, array, tile.Animations[0].Duration);
            }
예제 #13
0
        public bool AttemptPlugLeak(int tileX, int tileY, Farmer who, bool forceRepair = false)
        {
            AnimatedTile firstTile = this.map.GetLayer("Buildings").Tiles[tileX, tileY] as AnimatedTile;

            //ModEntry.monitor.Log($"({tileX}, {tileY}) | {isActionableTile(tileX, tileY, who)}", LogLevel.Trace);

            if (firstTile is null)
            {
                return(false);
            }

            if (!forceRepair && !(isActionableTile(tileX, tileY, who) && IsWithinRangeOfLeak(tileX, tileY, who)))
            {
                return(false);
            }

            if (!firstTile.Properties.ContainsKey("CustomAction") || !firstTile.Properties.ContainsKey("IsLeaking"))
            {
                return(false);
            }

            if (firstTile.Properties["CustomAction"] == "HullHole" && bool.Parse(firstTile.Properties["IsLeaking"]) is true)
            {
                // Stop the leaking
                firstTile.Properties["IsLeaking"] = false;

                // Update the tiles
                bool isFirstTile = true;
                for (int y = tileY; y < 5; y++)
                {
                    if (isFirstTile)
                    {
                        // Board up the hole
                        this.setMapTile(tileX, y, GetRandomBoardTile(), "Buildings", null, TRAWLER_TILESHEET_INDEX);

                        // Add the custom properties for tracking
                        this.map.GetLayer("Buildings").Tiles[tileX, tileY].Properties.CopyFrom(firstTile.Properties);

                        this.playSound("crafting");

                        isFirstTile = false;
                        continue;
                    }

                    string targetLayer = y == 4 ? "Back" : "Buildings";

                    AnimatedTile animatedTile = this.map.GetLayer(targetLayer).Tiles[tileX, y] as AnimatedTile;
                    int          tileIndex    = animatedTile.TileFrames[0].TileIndex - 1;

                    this.setMapTile(tileX, y, tileIndex, targetLayer, null, TRAWLER_TILESHEET_INDEX);
                }
            }

            return(true);
        }
예제 #14
0
    private IEnumerator EnableAnimationCoroutine(
        Vector3Int cellPos,
        AnimatedTile animatedTile,
        float animationTime,
        LayerTile oldEffectLayerTile)
    {
        tileChangeManager.UpdateTile(cellPos, TileType.Effects, animatedTile.name);

        yield return(WaitFor.Seconds(animationTime));

        ApplyOldOverlay(cellPos, oldEffectLayerTile);
    }
예제 #15
0
        public MapMSD ParseFile(string path)
        {
            var msd    = new MapMSD();
            var reader = new BigEndianBinaryReader(File.OpenRead(path));

            msd.AntimatedTiles  = AnimatedTile.FromReader(reader);
            msd.GraphicsFilesID = reader.ReadByte();
            msd.NumberOfZones   = reader.ReadInt16();
            msd.Zones           = Zone.FromReader(reader, msd);

            return(msd);
        }
    void Start()
    {
        xValue          = -1;
        yValue          = PlayerPrefs.GetInt("LabyrinttiLevel");
        leftEdgeValue   = PlayerPrefs.GetInt("LabyrinttiLevel") * -1 - 1;
        rightEdgeValue  = PlayerPrefs.GetInt("LabyrinttiLevel") - 2;
        bottomEdgeValue = PlayerPrefs.GetInt("LabyrinttiLevel") * -1 - 1;
        float cameraSize = this.GetComponent <Camera>().orthographicSize;

        this.GetComponent <Camera>().orthographicSize = cameraSize + PlayerPrefs.GetInt("LabyrinttiLevel") - 2;
        LastPlacedTile    = EmptyTile;
        allTilesGenerated = false;
    }
예제 #17
0
        private AnimatedTile LoadAnimatedTile(XmlHelper xmlHelper, Layer layer, TileSheet tileSheet)
        {
            int frameInterval = xmlHelper.GetIntAttribute("Interval");

            xmlHelper.AdvanceStartElement("Frames");

            Map map = layer.Map;
            List <StaticTile> tileFrames = new List <StaticTile>();

            while (xmlHelper.AdvanceNode() != XmlNodeType.EndElement)
            {
                if (xmlHelper.XmlReader.Name == "Static")
                {
                    tileFrames.Add(LoadStaticTile(xmlHelper, layer, tileSheet));
                }
                else if (xmlHelper.XmlReader.Name == "TileSheet")
                {
                    string tileSheetRef = xmlHelper.GetAttribute("Ref");
                    tileSheet = map.GetTileSheet(tileSheetRef);
                }
            }

            AnimatedTile animatedTile
                = new AnimatedTile(layer, tileFrames.ToArray(), frameInterval);


            // advance to end Animated tag or Properties
            xmlHelper.AdvanceNode();

            XmlNodeType xmlNodeType = xmlHelper.XmlReader.NodeType;
            string      nodeName    = xmlHelper.XmlReader.Name;

            if (xmlNodeType == XmlNodeType.Element && nodeName == "Properties")
            {
                LoadProperties(xmlHelper, animatedTile, false);

                xmlHelper.AdvanceNode();
                xmlNodeType = xmlHelper.XmlReader.NodeType;
                nodeName    = xmlHelper.XmlReader.Name;
            }

            if (xmlNodeType == XmlNodeType.EndElement && nodeName == "Animated")
            {
                return(animatedTile);
            }
            else
            {
                throw new Exception("Closing \"Animated\" element expected");
            }
        }
예제 #18
0
    private IEnumerator StartOverlayTileAnimation(Vector3Int pos, AnimatedTile tile, Quaternion rotation)
    {
        yield return(new WaitForSeconds(.8f));

        var extraLocation = pos;

        extraLocation.z = extraLocation.z + 1;
        plantTilemap.SetTransformMatrix(
            extraLocation,
            Matrix4x4.Rotate(rotation)
            );

        StartTileAnimation(extraLocation, tile, rotation, 0);
    }
예제 #19
0
    void SetMatrix()
    {
        //tileMap.animationFrameRate = 0;

        // SET THE MATRIX
        mapBounds = tileMap.cellBounds;
        mapMatrix = new TileInfo[mapBounds.size.x, mapBounds.size.y];
        TileBase[] allTiles = tileMap.GetTilesBlock(mapBounds);


        // Recupere les tiles et creer la matrice
        for (int x = 0; x < mapBounds.size.x; x++)
        {
            for (int y = 0; y < mapBounds.size.y; y++)

                TileBase tile = tileMap.GetTile<TileBase>(new Vector3Int(x,y,0));
                //TileBase tile = allTiles[x + y * mapBounds.size.x];
                if (tile != null)
                {
                    AnimatedTile animTile = tileMap.GetTile<AnimatedTile>(new Vector3Int(x, y, 0));
                    TileType tileType;
                    if (animTile != null && animTile.name.StartsWith("Path"))
                    {
                        tileType = TileType.Path;
                    }
                    else if (tileUnusableName.Contains(tile.name))
                    {
                        tileType = TileType.Unusable;
                    }
                    else
                    {
                        tileType = TileType.Ground;
                    }
                    mapMatrix[x, y] = new TileInfo(animTile, tileType, true);
                    if (animTile != null)
                    {
                        if (!(animTileAlreadySee.ContainsKey(animTile.name)))
                        {
                            animTilesVector3.Add(new Vector3Int(x, y, 0));
                            animTileAlreadySee.Add(animTile.name, true);
                        }
                        animTile.m_SpriteIndex = 0;
                    }
                }
                else
                {
                    mapMatrix[x, y] = new TileInfo(null, TileType.Unusable, true);
                }
            }
        }
예제 #20
0
        void OnEnable()
        {
            _animatedTile = target as AnimatedTile;

            _randomizeStartProperty = serializedObject.FindProperty(nameof(AnimatedTile.RandomizeStart));
            _animationSpeedProperty = serializedObject.FindProperty(nameof(AnimatedTile.AnimationSpeed));
            _animationStartProperty = serializedObject.FindProperty(nameof(AnimatedTile.AnimationStartTime));

            _tiles.Setup(serializedObject.FindProperty(nameof(_animatedTile.Tiles)))
            .MakeAddable(_addTileButton)
            .MakeRemovable(_removeTileButton)
            .MakeHeaderButton(_createTilesIcon, CreateTiles, Color.white)
            .MakeCustomHeight(GetHeight)
            .MakeReorderable();
        }
    private void SetTileAtPointAndHeight(int x, int y, float noiseHeight, int terrainLevelCount)
    {
        // Tile assets allow you to use a height of 2z
        // Therefore, we “stretch” the noise scale more than 2 times
        float tileHeight      = noiseHeight * terrainLevelCount * 2;
        int   tileHeightIndex = Mathf.FloorToInt(tileHeight);

        int z = tileHeightIndex * m_HeightSettings.heightMultiplier;

        if (m_HeightSettings.flatten)
        {
            z = 0;
        }

        int terrainIndex = GetTilemapLevelAtHeight(noiseHeight);

        TerrainSettings.Terrain terrain = m_TerrainSettings.GetTerrain(terrainIndex);
        Tile         tile         = terrain.tile;
        AnimatedTile animatedTile = terrain.animatedTile;

        if (m_HeightSettings.jagged)
        {
            //if jagged Percent is 1, everything is shifted down 1, giving the illusion that nothing is shifted
            bool shouldApplyJagged = UnityEngine.Random.value >= 1 - m_HeightSettings.jaggedPercent;
            if (shouldApplyJagged)
            {
                z = Mathf.Max(0, z - terrain.heightDelta);
            }
        }


        FillTileMapGaps(x, y, z, tile);

        Vector3Int tilePosition =
            new Vector3Int(x - m_HeightSettings.dimensionLength / 2, y - m_HeightSettings.dimensionLength / 2, z);

        if (animatedTile != null)
        {
            groundMap.SetTile(tilePosition, animatedTile);
        }
        else
        {
            groundMap.SetTile(tilePosition, tile);
        }
    }
예제 #22
0
        private void AddLinks(List <string> links)
        {
            if (links == null)
            {
                return;
            }

            if (links.Count > 0)
            {
                _sprites.Clear();
                _tiles.Clear();
                foreach (string link in links)
                {
                    var tile = new AnimatedTile(link);
                    _tiles.Add(tile, link);
                    _sprites.Add(tile);
                }
            }
        }
예제 #23
0
        private void StoreAnimatedTile(Stream stream, AnimatedTile animatedTile)
        {
            StoreInt32(stream, (int)animatedTile.FrameInterval);
            StoreInt32(stream, animatedTile.TileFrames.Count());

            TileSheet prevTileSheet = null;

            foreach (StaticTile tileFrame in animatedTile.TileFrames)
            {
                TileSheet tileSheet = tileFrame.TileSheet;
                if (tileSheet != prevTileSheet)
                {
                    stream.WriteByte((byte)'T');
                    StoreString(stream, tileSheet.Id);
                    prevTileSheet = tileSheet;
                }
                stream.WriteByte((byte)'S');
                StoreStaticTile(stream, tileFrame);
            }

            StoreProperties(stream, animatedTile);
        }
예제 #24
0
        public bool AttemptFixNet(int tileX, int tileY, Farmer who, bool forceRepair = false)
        {
            AnimatedTile firstTile = this.map.GetLayer("AlwaysFront").Tiles[tileX, tileY] as AnimatedTile;

            //ModEntry.monitor.Log($"({tileX}, {tileY}) | {isActionableTile(tileX, tileY, who)}", LogLevel.Debug);

            if (firstTile is null)
            {
                return(false);
            }

            if (!forceRepair && !(isActionableTile(tileX, tileY, who) && IsWithinRangeOfNet(who)))
            {
                return(false);
            }

            if (!firstTile.Properties.ContainsKey("CustomAction") || !firstTile.Properties.ContainsKey("IsRipped"))
            {
                return(false);
            }

            if (firstTile.Properties["CustomAction"] == "RippedNet" && bool.Parse(firstTile.Properties["IsRipped"]) is true)
            {
                // Stop the rip
                firstTile.Properties["IsRipped"] = false;

                // Patch up the net
                this.setMapTile(tileX, tileY, 435, "AlwaysFront", null, TRAWLER_TILESHEET_INDEX);
                this.setMapTile(tileX, tileY - 1, 436, "AlwaysFront", null, TRAWLER_TILESHEET_INDEX);

                // Add the custom properties for tracking
                this.map.GetLayer("AlwaysFront").Tiles[tileX, tileY].Properties.CopyFrom(firstTile.Properties);

                this.playSound("harvest");
            }


            return(false);
        }
예제 #25
0
        public Tile ToGameTile(Map map)
        {
            if (Deleted)
            {
                return(null);
            }

            Tile      tile;
            Layer     layer     = map.GetLayer(LayerId);
            TileSheet tileSheet = map.GetTileSheet(TileSheetId);

            if (Animated)
            {
                tile = new AnimatedTile(layer, TileFramesToStaticTiles(map), FrameInterval);
            }
            else
            {
                tile = new StaticTile(layer, tileSheet, BlendMode, TileIndex);
            }
            PasteProperties(tile);
            return(tile);
        }
예제 #26
0
        private void MergeTiles(Layer layer, Diff.TileData[] tilesData)
        {
            TileSheet GetTileSheetForTile(Diff.TileData tiledata)
            {
                return(layer.Map.TileSheets.First(ts => ts.Id == tiledata.OwningTileSheetId));
            }

            foreach (Diff.TileData tileData in tilesData)
            {
                if (tileData.EditType == EditType.Delete)
                {
                    layer.Tiles[tileData.X, tileData.Y] = null;
                    continue;
                }

                Tile newTile = null;
                if (tileData is Diff.AnimatedTileData animatedTileData)
                {
                    StaticTile[] frames = animatedTileData.Frames
                                          .Select(fd => new StaticTile(layer, GetTileSheetForTile(fd), fd.BlendMode, fd.TileIndex))
                                          .ToArray();
                    newTile = new AnimatedTile(layer, frames, animatedTileData.FrameInterval);
                }

                newTile = newTile ?? new StaticTile(layer, GetTileSheetForTile(tileData), tileData.BlendMode, tileData.TileIndex);
                // TODO: Should we merge these in case another mod has edited them?
                if (tileData.Properties != null)
                {
                    newTile.Properties.CopyFrom(tileData.Properties);
                }
                if (tileData.TileIndexProperties != null)
                {
                    newTile.TileIndexProperties.CopyFrom(tileData.TileIndexProperties);
                }

                layer.Tiles[tileData.X, tileData.Y] = newTile;
            }
        }
예제 #27
0
        // Clones a tile but uses the provided tilesheet and layer.
        private Tile CopyTile(Tile source, TileSheet tileSheet, Layer layer, IPropertyCollection additionalProperties = null)
        {
            var blendMode = source.BlendMode;
            var tileIndex = source.TileIndex;

            Tile newTile = null;

            if (source is AnimatedTile)
            {
                AnimatedTile animatedTile = source as AnimatedTile;
                // Copy the frames
                StaticTile[] frames = new StaticTile[animatedTile.TileFrames.Length];
                for (int i = 0; i < animatedTile.TileFrames.Length; ++i)
                {
                    StaticTile copyFrame = animatedTile.TileFrames[i];
                    frames[i] = new StaticTile(layer, tileSheet, copyFrame.BlendMode, copyFrame.TileIndex);
                }

                newTile = new AnimatedTile(layer, frames, animatedTile.FrameInterval);
            }
            else
            {
                newTile = new StaticTile(layer, tileSheet, blendMode, tileIndex);
            }

            if (additionalProperties?.Count > 0)
            {
                newTile.Properties.CopyFrom(additionalProperties);
            }

            // Do this after adding the additional properties so it overwrites any conflicting ones.
            MergeTileProperties(source, newTile);

            // Copy the tile properties. This contains the data set on tiles on the actual tilesheet (ie. passable).
            newTile.TileIndexProperties.CopyFrom(source.TileIndexProperties);

            return(newTile);
        }
예제 #28
0
        public bool AttemptPlugLeak(int tileX, int tileY, Farmer who, bool forceRepair = false)
        {
            AnimatedTile firstTile = this.map.GetLayer("Buildings").Tiles[tileX, tileY] as AnimatedTile;

            //ModEntry.monitor.Log($"({tileX}, {tileY}) | {isActionableTile(tileX, tileY, who)}", LogLevel.Debug);

            if (firstTile is null)
            {
                return(false);
            }

            if (!forceRepair && !(isActionableTile(tileX, tileY, who) && IsWithinRangeOfLeak(tileX, tileY, who)))
            {
                return(false);
            }

            if (!firstTile.Properties.ContainsKey("CustomAction") || !firstTile.Properties.ContainsKey("IsLeaking"))
            {
                return(false);
            }

            if (firstTile.Properties["CustomAction"] == "RustyPipe" && bool.Parse(firstTile.Properties["IsLeaking"]) is true)
            {
                // Stop the leak
                firstTile.Properties["IsLeaking"] = false;

                // Patch up the net
                this.setMapTile(tileX, tileY, 81, "Buildings", null, CABIN_TILESHEET_INDEX);
                this.setMapTileIndex(tileX, tileY - 1, -1, "Buildings");

                // Add the custom properties for tracking
                this.map.GetLayer("Buildings").Tiles[tileX, tileY].Properties.CopyFrom(firstTile.Properties);

                this.playSound("hammer");
            }

            return(true);
        }
    // Use this for initialization
    void Start()
    {
        TiledMap = new Map(TileMap, true, MapsPath, this.gameObject, defaultMaterial, 0);

        TileLayer tileLayer = TiledMap.GetTileLayer("Background");

        for (int i = 0; i < CoinsToAnimate.Length; i++)
        {
            AnimatedTile animTile = tileLayer.Tiles[(int)CoinsToAnimate[i].x, (int)CoinsToAnimate[i].y].TileObject.AddComponent <AnimatedTile>();
            animTile.TiledMap       = TiledMap;
            animTile.TileFramesGIDs = new int[] { 41, 42, 43, 44, 45, 46, 47, 48 };
            animTile.AnimationFPS   = 5;
            animTile.AnimationMode  = TileAnimationMode.PING_PONG;
        }
        for (int i = 0; i < FacesToAnimate.Length; i++)
        {
            AnimatedTile animTile = tileLayer.Tiles[(int)FacesToAnimate[i].x, (int)FacesToAnimate[i].y].TileObject.AddComponent <AnimatedTile>();
            animTile.TiledMap       = TiledMap;
            animTile.TileFramesGIDs = new int[] { 2, 3, 19, 20, 22, 34 };
            animTile.AnimationFPS   = 5;
            animTile.AnimationMode  = TileAnimationMode.LOOP;
        }
    }
예제 #30
0
        /// <summary>
        /// Places a tile at the specified position, WHILE taking into account it's TileType
        /// Mainly used for player block placement, if you are looking to place a block through the code
        /// Either use `Tiles[x,y,z] =` or, set sendMessage to false
        /// </summary>
        /// <param name="x">The X position on the grid</param>
        /// <param name="y">The Y position on the grid</param>
        /// <param name="layer">The layer, either background or foreground</param>
        /// <param name="block">The block to place</param>
        /// <param name="sendMessage">Should the block be sent to the server or not</param>
        public void PlaceTile(int x, int y, Layer layer, BlockType block, bool sendMessage)
        {
            int z = layer == Layer.Foreground ? 1 : 0;

            if (CanPlaceBlock(x, y, z, block))
            {
                //If the block has changed, and we should send a message, send one
                if (sendMessage && Tiles[x, y, z].Block.ID != block.ID)
                {
                    Game.NetManager.Send(new BlockMessage(block, x, y, z));
                }
                //Set the block
                switch (block.Type)
                {
                case TileType.Default:
                    Tiles[x, y, z] = new Tile(block);
                    break;

                case TileType.Animated:
                    Tiles[x, y, z] = new AnimatedTile(block);
                    break;
                }
            }
        }
예제 #31
0
파일: Map.cs 프로젝트: Cyral/Bricklayer
 /// <summary>
 /// Places a tile at the specified position, WHILE taking into account it's TileType
 /// Mainly used for player block placement, if you are looking to place a block through the code
 /// Either use `Tiles[x,y,z] =` or, set sendMessage to false
 /// </summary>
 /// <param name="x">The X position on the grid</param>
 /// <param name="y">The Y position on the grid</param>
 /// <param name="layer">The layer, either background or foreground</param>
 /// <param name="block">The block to place</param>
 /// <param name="sendMessage">Should the block be sent to the server or not</param>
 public void PlaceTile(int x, int y, Layer layer, BlockType block, bool sendMessage)
 {
     int z = layer == Layer.Foreground ? 1 : 0;
     if (CanPlaceBlock(x, y, z, block))
     {
         //If the block has changed, and we should send a message, send one
         if (sendMessage && Tiles[x, y, z].Block.ID != block.ID)
         {
             Game.NetManager.Send(new BlockMessage(block, x, y, z));
         }
         //Set the block
         switch (block.Type)
         {
             case TileType.Default:
                 Tiles[x, y, z] = new Tile(block);
                 break;
             case TileType.Animated:
                 Tiles[x, y, z] = new AnimatedTile(block);
                 break;
         }
     }
 }
예제 #32
0
        /// <summary>
        /// Moves the maze by the given speed in the given directional axis (true = left + right, false = up + down) but only if the given animatied tile will not be in a wall.
        /// </summary>
        public void AttemptMove(GameTime gameTime, int speed, bool dir, AnimatedTile tile)
        {
            // Attempt to move
                Move(gameTime, speed, dir);

            // Check if the given tile is in a wall and if he is undo move
                if (IsInWall(tile))
                    Move(gameTime, -speed, dir);
        }
예제 #33
0
 /// <summary>
 /// Gets the comrade intersecting with the given tile (returns null if none)
 /// </summary>
 public Comrade IntersectingComrade(AnimatedTile tile)
 {
     Comrade[] comrade = comrades.Where(c => new Rectangle(tile.Position.ToPoint(), new Point(GameVariables.CharacterSize)).Intersects(new Rectangle(c.Position.ToPoint(), new Point(GameVariables.CharacterSize)))).ToArray();
     return comrade.Length > 0 ? comrade[0] : null;
 }
예제 #34
0
 /// <summary>
 /// Gets the minotuar intersecting with the given tile (returns null if none)
 /// </summary>
 public Minotaur IntersectingMinotuar(AnimatedTile tile)
 {
     Minotaur[] minotaur = minotaurs.Where(m => new Rectangle(tile.Position.ToPoint(), new Point(GameVariables.CharacterSize)).Intersects(new Rectangle(m.Position.ToPoint(), new Point(GameVariables.CharacterSize)))).ToArray();
     return minotaur.Length > 0 ? minotaur[0] : null;
 }
예제 #35
0
 /// <summary>
 /// Gets if the given tile is intersecting with the exit
 /// </summary>
 public bool IsInExit(AnimatedTile tile)
 {
     return new Rectangle(tile.Position.ToPoint(), new Point(GameVariables.TileSize)).Intersects(new Rectangle((exit+position).ToPoint(), new Point(GameVariables.TileSize)));
 }
예제 #36
0
 /// <summary>
 /// Gets if the given tile is intersecting with a wall.
 /// </summary>
 public bool IsInWall(AnimatedTile tile)
 {
     Vector2 relativePosition = new Vector2(tile.Position.X - position.X, tile.Position.Y - position.Y);
     return !tiles[(int)(relativePosition.X+GameVariables.CharacterSize/2) / GameVariables.TileSize][(int)(relativePosition.Y + GameVariables.CharacterSize / 2) / GameVariables.TileSize];
 }