Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            TileData other = (TileData)obj;

            return(other.id == id && other.wall == wall && other.active == active && other.liq == liq && other.ltype == ltype && other.slope == slope && other.frameX == frameX && other.frameY == frameY);
        }
Ejemplo n.º 2
0
        public static Tile[,] DecompressTileData(TagCompound tag, int w, int h)
        {
            List <int>          tileIDs       = (List <int>)tag.GetList <int>("tileIDs");
            IList <TagCompound> tileData      = tag.GetList <TagCompound>("tileData");
            List <int>          counterIDs    = (List <int>)tag.GetList <int>("counterIDs");
            List <int>          counterCounts = (List <int>)tag.GetList <int>("counterCounts");
            List <Vector2>      locations     = (List <Vector2>)tag.GetList <Vector2>("extraLocations");
            List <int>          extraData     = (List <int>)tag.GetList <int>("extraData");

            Tile[,] tile = new Tile[w, h];
            int counter = 0;
            int x       = 0;
            int y       = 0;
            Dictionary <int, Tile> dictionary = new Dictionary <int, Tile>();
            List <(int, int)>      tileList   = new List <(int, int)>(); //First ushort is the dictionary id, second int is the quantity

            for (int i = 0; i < tileData.Count; i++)
            {
                //ModContent.GetInstance<StarSailorMod>().Logger.Info("tileID : " + data.tileIDs[i] + " | tileData : " + data.tileData[i]);
                TileData td = new TileData(tileData[i]);
                Tile     t  = new Tile(Main.tile[0, 0]);



                t.type   = td.id;
                t.wall   = td.wall;
                t.liquid = td.liq;
                t.liquidType(td.ltype);
                t.active(td.active);
                t.slope(td.slope);

                t.frameX = td.frameX;
                t.frameY = td.frameY;
                dictionary.Add(tileIDs[i], t);
            }

            for (int i = 0; i < counterIDs.Count; i++)
            {
                tileList.Add((counterIDs[i], counterCounts[i]));
            }

            int k = 0;

            foreach ((int, int)tc in tileList)
            {
                k += tc.Item2;
            }
            ModContent.GetInstance <StarSailorMod>().Logger.Info("Dimension decompressing | tileIDs : " + tileIDs.Count + " | tileData : " + tileData.Count + " | counterIDs " + counterIDs.Count + " | counterCounts " + counterCounts.Count);
            foreach ((int, int)tc in tileList)
            {
                int  count = tc.Item2;
                Tile t     = dictionary[tc.Item1];
                for (int i = 0; i < count; i++)
                {
                    tile[x, y] = new Tile(t);

                    if (++x >= w)
                    {
                        x = 0;
                        y++;
                    }
                }
            }
            for (int i = 0; i < extraData.Count; i++)
            {
                Tile t = tile[(int)locations[i].X, (int)locations[i].Y];
                if (t == null)
                {
                    t = new Tile();
                    tile[(int)locations[i].X, (int)locations[i].Y] = t;
                }
                int  data = extraData[i];
                bool act  = (data & 1) == 1;
                bool w1   = (data & 2) == 2;
                bool w2   = (data & 4) == 4;
                bool w3   = (data & 8) == 8;
                bool w4   = (data & 16) == 16;
                t.actuator(act);
                t.wire(w1);
                t.wire2(w2);
                t.wire3(w3);
                t.wire4(w4);
            }
            #region old way

            /*
             * for (int j = 0; j < tile.GetLength(1); j++)
             * {
             *
             *  for (int i = 0; i < tile.GetLength(0); i++)
             *  {
             *
             *
             *      if (tileList.Count == 0) return tile;
             *      tile[i, j] = new Tile(Main.tile[0, 0]);
             *      int id = tileList[0].Item1;
             *      if (id == -1) tile[i, j] = null;
             *      else
             *      {
             *
             *          TileData td = dictionary[id];
             *          tile[i, j].type = (ushort)td.id;
             *          tile[i, j].wall = (ushort)td.wall;
             *          tile[i, j].active(td.active);
             *          tile[i, j].liquid = td.liq;
             *          tile[i, j].slope(td.slope);
             *      }
             *      if (++counter >= tileList[0].Item2)
             *      {
             *          tileList.RemoveAt(0);
             *          counter = 0;
             *      }
             *  }
             * }
             */
            #endregion
            return(tile);
        }
Ejemplo n.º 3
0
        public static TagCompound GetCompressedTileData(Tile[,] tile) //Not compressed very well but ehhhh
        {
            TileData currentTile = TileData.NULLDATA;

            (int, int)currentCounter = (-1, 0);
            Dictionary <TileData, int> dictionary = new Dictionary <TileData, int>();
            List <(int, int)>          tileList   = new List <(int, int)>(); //First ushort is the dictionary id, second int is the quantity

            //ModContent.GetInstance<StarSailorMod>().Logger.Info(dimension + " peep ");

            for (int j = 0; j < tile.GetLength(1); j++)
            {
                for (int i = 0; i < tile.GetLength(0); i++)
                {
                    Tile t = tile[i, j];
                    if (t == null)
                    {
                        currentTile = TileData.NULLDATA;
                        if (dictionary.ContainsValue(-1))
                        {
                            if (currentCounter.Item1 == -1)
                            {
                                currentCounter.Item2 += 1;
                            }
                            else
                            {
                                if (currentCounter.Item2 >= 1)
                                {
                                    tileList.Add(currentCounter);
                                }
                                currentCounter = (-1, 1);
                            }
                        }
                        else
                        {
                            dictionary.Add(TileData.NULLDATA, -1);
                            if (currentCounter.Item2 >= 1)
                            {
                                tileList.Add(currentCounter);
                            }
                            currentCounter = (-1, 1);
                        }
                    }
                    else
                    {
                        TileData td = new TileData(t.type, t.wall, t.active(), t.liquid, t.liquidType(), t.slope(), t.frameX, t.frameY);
                        if (td == currentTile)
                        {
                            currentCounter.Item2 += 1;
                        }
                        else if (currentCounter.Item2 >= 1)
                        {
                            tileList.Add(currentCounter);
                            currentTile = td;
                            int val;
                            if (dictionary.TryGetValue(td, out val))
                            {
                                currentCounter = (val, 1);
                            }
                            else
                            {
                                int newID;
                                if (td != TileData.NULLDATA)
                                {
                                    newID = dictionary.Count;
                                }
                                else
                                {
                                    newID = -1;
                                }

                                dictionary.Add(td, newID);
                                currentCounter = (newID, 1);
                            }
                        }
                    }
                }
            }
            if (currentCounter.Item2 >= 1)
            {
                tileList.Add(currentCounter);
            }

            List <Vector2> pos  = new List <Vector2>();
            List <int>     data = new List <int>();

            for (int i = 0; i < tile.GetLength(0); i++)
            {
                for (int j = 0; j < tile.GetLength(1); j++)
                {
                    Tile t = tile[i, j];
                    if (t != null)
                    {
                        int num = 0;
                        num += t.actuator() ? 1 : 0;
                        num += t.wire() ? 2 : 0;
                        num += t.wire2() ? 4 : 0;
                        num += t.wire3() ? 8 : 0;
                        num += t.wire4() ? 16 : 0;
                        if (num != 0)
                        {
                            pos.Add(new Vector2(i, j));
                            data.Add(num);
                        }
                    }
                }
            }
            List <int>         counterIDs    = new List <int>();
            List <int>         counterCounts = new List <int>();
            List <int>         tileIDs       = new List <int>();
            List <TagCompound> tileData      = new List <TagCompound>();

            foreach ((int, int)k in tileList)
            {
                counterIDs.Add(k.Item1);
                counterCounts.Add(k.Item2);
            }
            foreach (KeyValuePair <TileData, int> k in dictionary)
            {
                tileIDs.Add(k.Value);
                tileData.Add(k.Key.ToTagCompound());
            }
            return(new TagCompound
            {
                ["tileIDs"] = tileIDs,
                ["tileData"] = tileData,
                ["counterIDs"] = counterIDs,
                ["counterCounts"] = counterCounts,
                ["extraLocations"] = pos,
                ["extraData"] = data,
            });
            //return new BasicTileData(dictionary, tileList);
        }