mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
[Major WIP] Fix /redo.
This commit is contained in:
parent
f0ea6ba7b1
commit
209e67c072
@ -37,43 +37,19 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
public override IEnumerable<DrawOpBlock> Perform(Vec3S32[] marks, Player p, Level lvl, Brush brush) {
|
public override IEnumerable<DrawOpBlock> Perform(Vec3S32[] marks, Player p, Level lvl, Brush brush) {
|
||||||
UndoCache cache = p.UndoBuffer;
|
UndoCache cache = p.UndoBuffer;
|
||||||
using (IDisposable locker = cache.ClearLock.AccquireReadLock()) {
|
using (IDisposable locker = cache.ClearLock.AccquireReadLock()) {
|
||||||
RedoBlocks(p);
|
if (RedoBlocks(p)) yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
UndoFormat.DoRedo(p, p.name.ToLower(), Start, End, ref found);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RedoBlocks(Player p) {
|
bool RedoBlocks(Player p) {
|
||||||
UndoCache cache = p.UndoBuffer;
|
UndoFormatArgs args = new UndoFormatArgs(p, Start);
|
||||||
UndoCacheNode node = p.UndoBuffer.Tail;
|
UndoFormat format = new UndoFormatOnline(p.UndoBuffer);
|
||||||
if (node == null) return;
|
UndoFormat.DoRedo(null, End, format, args);
|
||||||
|
return args.Stop;
|
||||||
while (node != null) {
|
|
||||||
Level lvl = LevelInfo.FindExact(node.MapName);
|
|
||||||
if (lvl == null || (p.level != null && !p.level.name.CaselessEq(lvl.name))) {
|
|
||||||
node = node.Prev; continue;
|
|
||||||
}
|
|
||||||
List<UndoCacheItem> items = node.Items;
|
|
||||||
BufferedBlockSender buffer = new BufferedBlockSender(lvl);
|
|
||||||
|
|
||||||
for (int i = items.Count - 1; i >= 0; i--) {
|
|
||||||
UndoCacheItem item = items[i];
|
|
||||||
ushort x, y, z;
|
|
||||||
node.Unpack(item.Index, out x, out y, out z);
|
|
||||||
|
|
||||||
DateTime time = node.BaseTime.AddTicks(item.TimeDelta * TimeSpan.TicksPerSecond);
|
|
||||||
if (time > End) continue;
|
|
||||||
if (time < Start) { buffer.CheckIfSend(true); return; }
|
|
||||||
|
|
||||||
byte tile, extTile;
|
|
||||||
item.GetBlock(out tile, out extTile);
|
|
||||||
if (lvl.DoBlockchange(p, x, y, z, tile, extTile, true)) {
|
|
||||||
buffer.Add(lvl.PosToInt(x, y, z), tile, extTile);
|
|
||||||
buffer.CheckIfSend(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buffer.CheckIfSend(true);
|
|
||||||
node = node.Prev;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,37 @@ namespace MCGalaxy.Undo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void DoRedo(Player p, string target,
|
||||||
|
DateTime start, DateTime end, ref bool found) {
|
||||||
|
List<string> files = GetUndoFiles(target);
|
||||||
|
UndoFormatArgs args = new UndoFormatArgs(p, start);
|
||||||
|
|
||||||
|
foreach (string file in files) {
|
||||||
|
found = true;
|
||||||
|
using (Stream s = File.OpenRead(file)) {
|
||||||
|
DoRedo(s, end, GetFormat(file), args);
|
||||||
|
if (args.Stop) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DoRedo(Stream s, DateTime end,
|
||||||
|
UndoFormat format, UndoFormatArgs args) {
|
||||||
|
Level lvl = args.Player.level;
|
||||||
|
BufferedBlockSender buffer = new BufferedBlockSender(lvl);
|
||||||
|
Player p = args.Player;
|
||||||
|
|
||||||
|
foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
|
||||||
|
if (P.Time > end) continue;
|
||||||
|
if (!lvl.DoBlockchange(p, P.X, P.Y, P.Z, P.Block, P.ExtBlock, true)) continue;
|
||||||
|
|
||||||
|
buffer.Add(lvl.PosToInt(P.X, P.Y, P.Z), P.Block, P.ExtBlock);
|
||||||
|
buffer.CheckIfSend(false);
|
||||||
|
}
|
||||||
|
buffer.CheckIfSend(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void UpgradePlayerUndoFiles(string name) {
|
public static void UpgradePlayerUndoFiles(string name) {
|
||||||
UpgradeFiles(undoDir, name);
|
UpgradeFiles(undoDir, name);
|
||||||
UpgradeFiles(prevUndoDir, name);
|
UpgradeFiles(prevUndoDir, name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user