private void Floor_OnChange(int whichRoom, int which, DecoratableLocation dec)
        {
            TileSheet    tilesheet = initTilesheet(ref dec.map);
            AnimatedTile anim      = null;

            if (Texture is AnimatedTexture && (Texture as AnimatedTexture).AnimatedTiles.Find(a => a.Index == which && a.Floor == isFloor) is AnimatedTile aList)
            {
                anim = aList;
            }

            setFloorsTilesheet(whichRoom, which, tilesheet, dec, anim);

            if (savFile.rooms.Find(sr => sr.Id == Game1.player.UniqueMultiplayerID && sr.Location == dec.Name && sr.Room == whichRoom) is SavedRoom sav)
            {
                sav.Floors   = name;
                sav.FloorsNr = parentSheetIndex;
            }
            else
            {
                savFile.rooms.Add(new SavedRoom(Game1.player.UniqueMultiplayerID, dec.Name, whichRoom, name, "na", 0, parentSheetIndex));
            }

            dec.floor.OnChange -= floorChange;
        }
        public static void setMapTilesheet(Map map, TileSheet tilesheet, int tileX, int tileY, string layer, int whichTileSheet = 0, int index = 0, AnimatedTile animations = null)
        {
            try
            {
                if (!tilesheet.Id.Contains("zCWF"))
                {
                    index = 0;
                }
                Tile tile    = map.GetLayer(layer).Tiles[tileX, tileY];
                Tile newTile = null;
                if (animations != null)
                {
                    List <StaticTile> statics = new List <StaticTile>();
                    for (int i = 0; i < animations.Frames; i++)
                    {
                        statics.Add(new StaticTile(map.GetLayer(layer), tilesheet, BlendMode.Alpha, (i * (animations.Floor ? 2 : 1)) + (tile.TileIndex - index)));
                    }
                    newTile = new xTile.Tiles.AnimatedTile(map.GetLayer(layer), statics.ToArray(), animations.Length);
                    foreach (var p in tile.Properties)
                    {
                        newTile.Properties.Add(p);
                    }

                    PyTK.PyUtils.setDelayedAction(200, () => map.GetLayer(layer).Tiles[tileX, tileY] = newTile);
                }
                else
                {
                    newTile = new StaticTile(map.GetLayer(layer), tilesheet, BlendMode.Alpha, tile.TileIndex - index);
                    foreach (var p in tile.Properties)
                    {
                        newTile.Properties.Add(p);
                    }

                    PyTK.PyUtils.setDelayedAction(200, () => map.GetLayer(layer).Tiles[tileX, tileY] = newTile);
                }
            }
            catch
            {
            }
        }
        public static void setFloorsTilesheet(int whichRoom, int which, TileSheet tilesheet, DecoratableLocation dec, AnimatedTile animations = null)
        {
            List <Rectangle> floors = dec.getFloors();
            int i = 336;

            if (whichRoom == -1)
            {
                foreach (Rectangle rectangle in floors)
                {
                    int x = rectangle.X;
                    while (x < rectangle.Right)
                    {
                        int y = rectangle.Y;
                        while (y < rectangle.Bottom)
                        {
                            if (rectangle.Contains(x, y))
                            {
                                setMapTilesheet(dec.map, tilesheet, x, y, "Back", 0, i, animations);
                            }
                            if (rectangle.Contains(x + 1, y))
                            {
                                setMapTilesheet(dec.map, tilesheet, x + 1, y, "Back", 0, i, animations);
                            }
                            if (rectangle.Contains(x, y + 1))
                            {
                                setMapTilesheet(dec.map, tilesheet, x, y + 1, "Back", 0, i, animations);
                            }
                            if (rectangle.Contains(x + 1, y + 1))
                            {
                                setMapTilesheet(dec.map, tilesheet, x + 1, y + 1, "Back", 0, i, animations);
                            }
                            y += 2;
                        }
                        x += 2;
                    }
                }
            }
            else
            {
                if (floors.Count <= whichRoom)
                {
                    return;
                }
                Rectangle rectangle = floors[whichRoom];
                int       x         = rectangle.X;
                while (x < rectangle.Right)
                {
                    int y = rectangle.Y;
                    while (y < rectangle.Bottom)
                    {
                        if (rectangle.Contains(x, y))
                        {
                            setMapTilesheet(dec.map, tilesheet, x, y, "Back", 0, i, animations);
                        }
                        if (rectangle.Contains(x + 1, y))
                        {
                            setMapTilesheet(dec.map, tilesheet, x + 1, y, "Back", 0, i, animations);
                        }
                        if (rectangle.Contains(x, y + 1))
                        {
                            setMapTilesheet(dec.map, tilesheet, x, y + 1, "Back", 0, i, animations);
                        }
                        if (rectangle.Contains(x + 1, y + 1))
                        {
                            setMapTilesheet(dec.map, tilesheet, x + 1, y + 1, "Back", 0, i, animations);
                        }
                        y += 2;
                    }
                    x += 2;
                }
            }

            PyTK.PyUtils.setDelayedAction(500, () => dec.updateMap());
        }
        public static void setWallsTilesheet(int whichRoom, int which, TileSheet tilesheet, DecoratableLocation dec, AnimatedTile animations = null)
        {
            List <Rectangle> walls = dec.getWalls();

            if (whichRoom == -1)
            {
                foreach (Rectangle rectangle in walls)
                {
                    for (int x = rectangle.X; x < rectangle.Right; ++x)
                    {
                        setMapTilesheet(dec.map, tilesheet, x, rectangle.Y, "Back", 0, 0, animations);
                        setMapTilesheet(dec.map, tilesheet, x, rectangle.Y + 1, "Back", 0, 0, animations);
                        if (rectangle.Height >= 3)
                        {
                            if (dec.map.GetLayer("Buildings").Tiles[x, rectangle.Y + 2].TileSheet.Equals(dec.map.TileSheets[2]) || dec.map.GetLayer("Buildings").Tiles[x, rectangle.Y + 2].TileSheet.Id.StartsWith("zCWF"))
                            {
                                setMapTilesheet(dec.map, tilesheet, x, rectangle.Y + 2, "Buildings", 0, 0, animations);
                            }
                            else
                            {
                                setMapTilesheet(dec.map, tilesheet, x, rectangle.Y + 2, "Back", 0, 0, animations);
                            }
                        }
                    }
                }
            }
            else
            {
                if (walls.Count <= whichRoom)
                {
                    return;
                }
                Rectangle rectangle = walls[whichRoom];
                for (int x = rectangle.X; x < rectangle.Right; ++x)
                {
                    setMapTilesheet(dec.map, tilesheet, x, rectangle.Y, "Back", 0, 0, animations);
                    setMapTilesheet(dec.map, tilesheet, x, rectangle.Y + 1, "Back", 0, 0, animations);
                    if (rectangle.Height >= 3)
                    {
                        if (dec.map.GetLayer("Buildings").Tiles[x, rectangle.Y + 2].TileSheet.Equals(dec.map.TileSheets[2]) || dec.map.GetLayer("Buildings").Tiles[x, rectangle.Y + 2].TileSheet.Id.StartsWith("zCWF"))
                        {
                            setMapTilesheet(dec.map, tilesheet, x, rectangle.Y + 2, "Buildings", 0, 0, animations);
                        }
                        else
                        {
                            setMapTilesheet(dec.map, tilesheet, x, rectangle.Y + 2, "Back", 0, 0, animations);
                        }
                    }
                }
            }


            PyTK.PyUtils.setDelayedAction(500, () => dec.updateMap());
        }