Exemple #1
0
        public static void Add(string level, uint uid, ushort x, ushort z, ushort y, byte newBlock)
        {
            LevelUndo tmp = history[level];

            if (tmp == null)
            {
                return;
            }
            tmp.Add(x, z, y, uid, newBlock);
        }
Exemple #2
0
 /// <summary>
 /// Loads the history data
 /// </summary>
 /// <param name="level">The name of the level</param>
 /// <returns>Whether or not the history could have been loaded.</returns>
 public static bool Load(string level)
 {
     if (File.Exists("levels/" + level + ".history"))
     {
         FileStream fs = new FileStream("levels/" + level + ".history", FileMode.Open, FileAccess.Read);
         //    GZipStream gs = new GZipStream(fs, CompressionMode.Decompress);
         BinaryReader br = new BinaryReader(fs);
         history[level] = LevelUndo.Read(br);
         fs.Close();
         return(true);
     }
     return(false);
 }
Exemple #3
0
        public static IEnumerable <Tuple <byte, long, long> > About(string level, ushort x, ushort z, ushort y)
        {
            LevelUndo tmp = history[level];

            if (tmp == null)
            {
                yield break;
            }
            foreach (var ret in tmp.About(x, z, y))
            {
                yield return(ret);
            }
            yield break;
        }
Exemple #4
0
        public static IEnumerable <Tuple <ushort, ushort, ushort, byte> > GetCurrentIfUID(string level, uint uid, long since)
        {
            LevelUndo tmp = history[level];

            if (tmp == null)
            {
                yield break;
            }
            else
            {
                foreach (var ret in tmp.GetCurrentIfUID(uid, since))
                {
                    yield return(ret);
                }
            }
        }
Exemple #5
0
        public static LevelUndo Read(BinaryReader br)
        {
            long   count = br.ReadInt32();
            ushort x     = br.ReadUInt16();
            ushort z     = br.ReadUInt16();
            ushort y     = br.ReadUInt16();

            byte[]    origLvl = br.ReadBytes((int)count);
            LevelUndo ret     = new LevelUndo(x, z, y, origLvl);

            count = br.ReadInt64();
            for (; count > 0; count--)
            {
                x = br.ReadUInt16();
                z = br.ReadUInt16();
                y = br.ReadUInt16();
                ExtraData <ushort, ExtraData <ushort, UndoList> > xLevel = ret.changes[x];
                ExtraData <ushort, UndoList> zLevel;
                if (xLevel == null)
                {
                    xLevel         = new ExtraData <ushort, ExtraData <ushort, UndoList> >();
                    zLevel         = new ExtraData <ushort, UndoList>();
                    zLevel[y]      = UndoList.Read(br);
                    xLevel[z]      = zLevel;
                    ret.changes[x] = xLevel;
                }
                else
                {
                    zLevel = xLevel[z];
                    if (zLevel == null)
                    {
                        zLevel    = new ExtraData <ushort, UndoList>();
                        zLevel[y] = UndoList.Read(br);
                        xLevel[z] = zLevel;
                    }
                    else
                    {
                        zLevel[y] = UndoList.Read(br);
                    }
                }
            }
            return(ret);
        }
Exemple #6
0
        public static void WriteOut(string level, bool clear)
        {
            LevelUndo tmp = history[level];

            if (tmp != null)
            {
                FileStream fs = new FileStream("levels/" + level + ".history", FileMode.Create, FileAccess.Write);
                //    GZipStream gs = new GZipStream(fs, CompressionMode.Compress);
                BinaryWriter bw = new BinaryWriter(fs);
                tmp.Write(bw);
                bw.Flush();
                //    gs.Flush();
                fs.Flush();
                fs.Close();
                if (clear)
                {
                    history[level] = null;
                }
            }
        }
Exemple #7
0
 public static void SetLevel(string level, ushort sizeX, ushort sizeZ, ushort sizeY, byte[] originalLevel)
 {
     history[level] = new LevelUndo(sizeX, sizeZ, sizeY, originalLevel);
 }
 public static LevelUndo Read(BinaryReader br) {
     long count = br.ReadInt32();
     ushort x = br.ReadUInt16();
     ushort z = br.ReadUInt16();
     ushort y = br.ReadUInt16();
     byte[] origLvl = br.ReadBytes((int)count);
     LevelUndo ret = new LevelUndo(x, z, y, origLvl);
     count = br.ReadInt64();
     for (; count > 0; count--) {
         x = br.ReadUInt16();
         z = br.ReadUInt16();
         y = br.ReadUInt16();
         ExtraData<ushort, ExtraData<ushort, UndoList>> xLevel = ret.changes[x];
         ExtraData<ushort, UndoList> zLevel;
         if (xLevel == null) {
             xLevel = new ExtraData<ushort, ExtraData<ushort, UndoList>>();
             zLevel = new ExtraData<ushort, UndoList>();
             zLevel[y] = UndoList.Read(br);
             xLevel[z] = zLevel;
             ret.changes[x] = xLevel;
         }
         else {
             zLevel = xLevel[z];
             if (zLevel == null) {
                 zLevel = new ExtraData<ushort, UndoList>();
                 zLevel[y] = UndoList.Read(br);
                 xLevel[z] = zLevel;
             }
             else {
                 zLevel[y] = UndoList.Read(br);
             }
         }
     }
     return ret;
 }
 public static void SetLevel(string level, ushort sizeX, ushort sizeZ, ushort sizeY, byte[] originalLevel) {
     history[level] = new LevelUndo(sizeX, sizeZ, sizeY, originalLevel);
 }