Esempio n. 1
0
        private string LoadInTileSheetForTile(TileProfile tile)
        {
            Map    map            = Location.map;
            string newTileSheetId = GetCustomTileSheetIdFromTile(tile);

            if (map.GetTileSheet(tile.TileSheetId) != null)
            {
                return(tile.TileSheetId);
            }
            if (map.GetTileSheet(newTileSheetId) != null)
            {
                return(newTileSheetId);
            }

            TileSheet ts = new TileSheet(newTileSheetId, map, tile.TileSheetImageSource, tile.TileSheetSize, tile.TileSheetTileSize);

            map.AddTileSheet(ts);
            map.LoadTileSheets(Game1.mapDisplayDevice);
            {
                foreach (TileSheet tish in map.TileSheets)
                {
                    iTile.LogDebug(tish.Id);
                }
            }
            return(newTileSheetId);
        }
Esempio n. 2
0
        private static string GetCustomTileSheetIdFromTile(TileProfile tile)
        {
            string id = tile.TileSheetId;

            if (!id.StartsWith(extraTileSheetPrefix))
            {
                id = string.Concat(extraTileSheetPrefix, id);
            }
            return(id);
        }
Esempio n. 3
0
 public void ReplaceTileSafe(TileProfile tile, string layerId, Vector2 position, bool onAction = true)
 {
     if (!tile.Deleted)
     {
         tile.TileSheetId = LoadInTileSheetForTile(tile);
     }
     if (onAction)
     {
         tiles.Add(tile);
     }
     Location.map.GetLayer(layerId).Tiles[(int)position.X, (int)position.Y] = tile.ToGameTile(Location.map);
 }
Esempio n. 4
0
        public void HandleTileReplacement(TileProfile tp, bool broadcast = true)
        {
            TileProfile existingTile = GetTileProfile(tp.Position, tp.LayerId, out int index);

            if (existingTile != null)
            {
                tiles.RemoveAt(index);
            }
            ReplaceTileSafe(tp, tp.LayerId, tp.Position);

            if (broadcast && Context.IsMultiplayer && Context.HasRemotePlayers)
            {
                iTile._Helper.Multiplayer.SendMessage(new Packet(tp, Name), NetworkManager.pasteActionKey, NetworkManager.toModIDs);
            }
        }
Esempio n. 5
0
        private TileProfile GetTileProfile(Vector2 position, string layerId, out int index)
        {
            int i = 0;

            index = 0;
            TileProfile profile = tiles.FirstOrDefault(t =>
            {
                if (t.LayerId == layerId && t.Position.Equals(position))
                {
                    return(true);
                }
                i++;
                return(false);
            });

            index = i;
            return(profile);
        }
Esempio n. 6
0
        public TileProfile(Tile gameTile, Vector2 location, string layerId, bool deleted = false)
        {
            if (deleted)
            {
                Deleted = true;
                X       = location.X;
                Y       = location.Y;
                LayerId = layerId;
                return;
            }

            TileSheet ts = gameTile.TileSheet;

            Animated  = gameTile is AnimatedTile;
            BlendMode = gameTile.BlendMode;
            X         = location.X;
            Y         = location.Y;
            LayerId   = layerId;
            CopyProperties(gameTile);
            TileSheetImageSource = ts.ImageSource;
            TileSheetId          = ts.Id;
            TileSheetSize        = ts.SheetSize;
            TileSheetTileSize    = ts.TileSize;
            TileIndex            = gameTile.TileIndex;

            if (Animated)
            {
                FrameInterval = GetFrameIntervalForAnimatedTile(gameTile);
                StaticTile[] frames = GetTileFramesForAnimatedTile(gameTile);
                if (frames != null && frames.Length != 0)
                {
                    TileFrames = new TileProfile[frames.Length];
                    for (int i = 0; i < frames.Length; i++)
                    {
                        TileProfile profile = new TileProfile(frames[0], Position, LayerId);
                        TileFrames[i] = profile;
                    }
                }
            }
        }
Esempio n. 7
0
        public void RestoreTile(Vector2 position, string layerId, bool broadcast = true)
        {
            TileProfile existingTile = GetTileProfile(position, layerId, out int index);

            if (existingTile != null)
            {
                tiles.RemoveAt(index);
            }

            Tile initialTile = initialTiles[layerId][position];

            if (initialTile != null)
            {
                DoubleCheckTS(initialTile);
            }
            Location.map.GetLayer(layerId).Tiles[(int)position.X, (int)position.Y] = initialTile;

            if (broadcast && Context.IsMultiplayer && Context.HasRemotePlayers)
            {
                iTile._Helper.Multiplayer.SendMessage(new Packet(position, layerId, Name), NetworkManager.restoreActionKey, NetworkManager.toModIDs);
            }
        }
Esempio n. 8
0
        private void DoubleCheckTS(Tile tile)
        {
            TileSheet ts = tile.TileSheet;

            if (!Location.map.DependsOnTileSheet(ts))
            {
                if (Location.map.TileSheets.FirstOrDefault(t => t.Id == ts.Id && t.ImageSource == ts.ImageSource) == null)
                {
                    return;
                }

                if (tile is StaticTile)
                {
                    AssignTS(tile);
                }
                else if (tile is AnimatedTile)
                {
                    foreach (StaticTile sTile in TileProfile.GetTileFramesForAnimatedTile(tile))
                    {
                        AssignTS(sTile);
                    }
                }
            }
        }
Esempio n. 9
0
        public void HandleTileReplacement(Tile tile, string layerId, Vector2 position, bool broadcast = true)
        {
            TileProfile tp = new TileProfile(tile, position, layerId, tile == null);

            HandleTileReplacement(tp, broadcast);
        }
Esempio n. 10
0
 public void ApplyTile(TileProfile tile)
 {
     ReplaceTileSafe(tile, tile.LayerId, tile.Position, false);
 }