DB: fix /redo

This commit is contained in:
UnknownShadow200 2017-01-02 11:32:49 +11:00
parent b0b1a1e41d
commit 18edc5e5a3
4 changed files with 8 additions and 37 deletions

View File

@ -128,7 +128,7 @@ namespace MCGalaxy.DB {
int count = Cache.Count, index = (y * dims.Z + z) * dims.X + x;
BlockDBEntry[] items = Cache.Items;
for (int i = count - 1; i >= 0; i--) {
for (int i = 0; i < count; i++) {
if (items[i].Index != index) continue;
output(items[i]);
}

View File

@ -129,7 +129,7 @@ namespace MCGalaxy.Drawing.Ops {
if (item.Brush != null) item.Brush.Configure(item.Op, p);
DoDrawOp(item, p);
timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds;
timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds + 1;
entry.End = Server.StartTime.AddTicks(timeDelta * TimeSpan.TicksPerSecond);
p.DrawOps.Add(entry);

View File

@ -40,31 +40,27 @@ namespace MCGalaxy.Drawing.Ops {
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
int[] ids = NameConverter.FindIds(Player.name);
Server.s.Log("FFFOUND: " + ids.Length);
if (ids.Length > 0) {
if (Level.BlockDB.FindChangesBy(ids, Start, End, out dims, RedoBlock)) return;
}
if (ids.Length == 0) return;
bool found = false;
UndoFormatArgs args = new UndoFormatArgs(Player, Start, End, output);
UndoFormat.DoRedo(Player.name.ToLower(), ref found, args);
this.output = output;
Level.BlockDB.FindChangesBy(ids, Start, End, out dims, RedoBlock);
this.output = null;
}
Action<DrawOpBlock> output;
Vec3U16 dims;
void RedoBlock(BlockDBEntry entry) {
byte block = entry.OldRaw, ext = 0;
if ((entry.Flags & BlockDBFlags.OldCustom) != 0) {
ext = block; block = Block.custom_block;
}
Server.s.Log("FFFFFFF " + block);
if (block == Block.Invalid) return; // Exported BlockDB SQL table entries don't have previous block
if ((entry.Flags & BlockDBFlags.UndoSelf) == 0) return; // not an undo
int x = entry.Index % dims.X;
int y = (entry.Index / dims.X) / dims.Z;
int z = (entry.Index / dims.X) % dims.Z;
Place((ushort)x, (ushort)y, (ushort)z, block, ext);
output(Place((ushort)x, (ushort)y, (ushort)z, block, ext));
}
}
}

View File

@ -111,31 +111,6 @@ namespace MCGalaxy.Undo {
}
public static void DoRedo(string target, ref bool found, UndoFormatArgs args) {
List<string> files = GetUndoFiles(target);
if (files.Count == 0) return;
found = true;
foreach (string file in files) {
using (Stream s = File.OpenRead(file)) {
DoRedo(s, GetFormat(file), args);
if (args.Stop) break;
}
}
}
public static void DoRedo(Stream s, UndoFormat format, UndoFormatArgs args) {
DrawOpBlock block;
foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
if (P.Time > args.End) continue;
block.X = P.X; block.Y = P.Y; block.Z = P.Z;
block.Block = P.Block; block.ExtBlock = P.ExtBlock;
args.Output(block);
}
}
public static void UpgradePlayerUndoFiles(string name) {
UpgradeFiles(undoDir, name);
UpgradeFiles(prevUndoDir, name);