mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
[Major WIP] Fix /undo again now.
This commit is contained in:
parent
cdc5619f9d
commit
f03d0687b0
@ -35,7 +35,7 @@ namespace MCGalaxy.Commands {
|
|||||||
long seconds;
|
long seconds;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
||||||
if (message == "") message = p.name + " 300";
|
if (message == "") message = p.name + " 1800";
|
||||||
string[] args = message.Split(' ');
|
string[] args = message.Split(' ');
|
||||||
string name = args[0];
|
string name = args[0];
|
||||||
|
|
||||||
@ -46,9 +46,9 @@ namespace MCGalaxy.Commands {
|
|||||||
} else if (long.TryParse(args[0], out seconds)) {
|
} else if (long.TryParse(args[0], out seconds)) {
|
||||||
args[0] = p.name;
|
args[0] = p.name;
|
||||||
} else {
|
} else {
|
||||||
seconds = 300;
|
seconds = 30 * 60;
|
||||||
}
|
}
|
||||||
if (seconds <= 0) seconds = 5400;
|
if (seconds <= 0) seconds = 30 * 60;
|
||||||
DateTime start = DateTime.UtcNow.AddTicks(-seconds * TimeSpan.TicksPerSecond);
|
DateTime start = DateTime.UtcNow.AddTicks(-seconds * TimeSpan.TicksPerSecond);
|
||||||
|
|
||||||
Player who = PlayerInfo.Find(name);
|
Player who = PlayerInfo.Find(name);
|
||||||
|
@ -90,7 +90,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
item.GetNewBlock(out Pos.newtype, out Pos.newExtType);
|
item.GetNewBlock(out Pos.newtype, out Pos.newExtType);
|
||||||
item.GetBlock(out Pos.type, out Pos.extType);
|
item.GetBlock(out Pos.type, out Pos.extType);
|
||||||
UndoFormat.UndoBlock(p, lvl, Pos, timeDelta, buffer);
|
UndoFormat.UndoBlock(p, lvl, Pos, buffer);
|
||||||
}
|
}
|
||||||
buffer.CheckIfSend(true);
|
buffer.CheckIfSend(true);
|
||||||
node = node.Prev;
|
node = node.Prev;
|
||||||
|
@ -77,8 +77,7 @@ namespace MCGalaxy.Undo {
|
|||||||
static void FilterEntries(Player p, string dir, string name, Vec3S32[] marks,
|
static void FilterEntries(Player p, string dir, string name, Vec3S32[] marks,
|
||||||
DateTime start, bool highlight, ref bool FoundUser) {
|
DateTime start, bool highlight, ref bool FoundUser) {
|
||||||
string path = Path.Combine(dir, name);
|
string path = Path.Combine(dir, name);
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path)) return;
|
||||||
return;
|
|
||||||
string[] files = Directory.GetFiles(path);
|
string[] files = Directory.GetFiles(path);
|
||||||
Array.Sort<string>(files, CompareFiles);
|
Array.Sort<string>(files, CompareFiles);
|
||||||
UndoEntriesArgs args = new UndoEntriesArgs(p, start);
|
UndoEntriesArgs args = new UndoEntriesArgs(p, start);
|
||||||
@ -99,7 +98,7 @@ namespace MCGalaxy.Undo {
|
|||||||
if (highlight) {
|
if (highlight) {
|
||||||
DoHighlight(s, format, args);
|
DoHighlight(s, format, args);
|
||||||
} else {
|
} else {
|
||||||
// TODO: fixy fix if (!format.UndoEntry(p, path, marks, ref temp, start)) break;
|
DoUndo(s, format, args);
|
||||||
}
|
}
|
||||||
if (args.Stop) break;
|
if (args.Stop) break;
|
||||||
}
|
}
|
||||||
@ -117,8 +116,43 @@ namespace MCGalaxy.Undo {
|
|||||||
return aNum.CompareTo(bNum);
|
return aNum.CompareTo(bNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DoHighlight(Stream s, UndoFormat format, UndoEntriesArgs args) {
|
||||||
|
BufferedBlockSender buffer = new BufferedBlockSender(args.Player);
|
||||||
|
Level lvl = args.Player.level;
|
||||||
|
|
||||||
|
foreach (Player.UndoPos P in format.GetEntries(s, args)) {
|
||||||
|
byte type = P.type, newType = P.newtype;
|
||||||
|
byte block = (newType == Block.air
|
||||||
|
|| Block.Convert(type) == Block.water || type == Block.waterstill
|
||||||
|
|| Block.Convert(type) == Block.lava || type == Block.lavastill)
|
||||||
|
? Block.red : Block.green;
|
||||||
|
|
||||||
|
buffer.Add(lvl.PosToInt(P.x, P.y, P.z), block, 0);
|
||||||
|
buffer.CheckIfSend(false);
|
||||||
|
}
|
||||||
|
buffer.CheckIfSend(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DoUndo(Stream s, UndoFormat format, UndoEntriesArgs args) {
|
||||||
|
Level lvl = args.Player == null ? null : args.Player.level;
|
||||||
|
BufferedBlockSender buffer = new BufferedBlockSender(lvl);
|
||||||
|
string lastMap = null;
|
||||||
|
|
||||||
|
foreach (Player.UndoPos P in format.GetEntries(s, args)) {
|
||||||
|
if (P.mapName != lastMap) {
|
||||||
|
lvl = LevelInfo.FindExact(P.mapName);
|
||||||
|
buffer.CheckIfSend(true);
|
||||||
|
buffer.level = lvl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lvl == null) continue;
|
||||||
|
UndoBlock(args.Player, lvl, P, buffer);
|
||||||
|
}
|
||||||
|
buffer.CheckIfSend(true);
|
||||||
|
}
|
||||||
|
|
||||||
protected internal static void UndoBlock(Player pl, Level lvl, Player.UndoPos P,
|
protected internal static void UndoBlock(Player pl, Level lvl, Player.UndoPos P,
|
||||||
int timeDelta, BufferedBlockSender buffer) {
|
BufferedBlockSender buffer) {
|
||||||
byte lvlTile = lvl.GetTile(P.x, P.y, P.z);
|
byte lvlTile = lvl.GetTile(P.x, P.y, P.z);
|
||||||
if (lvlTile == P.newtype || Block.Convert(lvlTile) == Block.water
|
if (lvlTile == P.newtype || Block.Convert(lvlTile) == Block.water
|
||||||
|| Block.Convert(lvlTile) == Block.lava || lvlTile == Block.grass) {
|
|| Block.Convert(lvlTile) == Block.lava || lvlTile == Block.grass) {
|
||||||
@ -126,7 +160,6 @@ namespace MCGalaxy.Undo {
|
|||||||
byte newExtType = P.newExtType;
|
byte newExtType = P.newExtType;
|
||||||
P.newtype = P.type; P.newExtType = P.extType;
|
P.newtype = P.type; P.newExtType = P.extType;
|
||||||
P.extType = newExtType; P.type = lvlTile;
|
P.extType = newExtType; P.type = lvlTile;
|
||||||
P.timeDelta = timeDelta;
|
|
||||||
|
|
||||||
if (pl != null) {
|
if (pl != null) {
|
||||||
if (lvl.DoBlockchange(pl, P.x, P.y, P.z, P.newtype, P.newExtType, true)) {
|
if (lvl.DoBlockchange(pl, P.x, P.y, P.z, P.newtype, P.newExtType, true)) {
|
||||||
@ -149,23 +182,6 @@ namespace MCGalaxy.Undo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DoHighlight(Stream s, UndoFormat format, UndoEntriesArgs args) {
|
|
||||||
BufferedBlockSender buffer = new BufferedBlockSender(args.Player);
|
|
||||||
Level lvl = args.Player.level;
|
|
||||||
|
|
||||||
foreach (Player.UndoPos P in format.GetEntries(s, args)) {
|
|
||||||
byte type = P.type, newType = P.newtype;
|
|
||||||
byte block = (newType == Block.air
|
|
||||||
|| Block.Convert(type) == Block.water || type == Block.waterstill
|
|
||||||
|| Block.Convert(type) == Block.lava || type == Block.lavastill)
|
|
||||||
? Block.red : Block.green;
|
|
||||||
|
|
||||||
buffer.Add(lvl.PosToInt(P.x, P.y, P.z), block, 0);
|
|
||||||
buffer.CheckIfSend(false);
|
|
||||||
}
|
|
||||||
buffer.CheckIfSend(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void CreateDefaultDirectories() {
|
public static void CreateDefaultDirectories() {
|
||||||
if (!Directory.Exists(undoDir))
|
if (!Directory.Exists(undoDir))
|
||||||
@ -193,8 +209,7 @@ namespace MCGalaxy.Undo {
|
|||||||
IEnumerable<Player.UndoPos> data = null;
|
IEnumerable<Player.UndoPos> data = null;
|
||||||
using (FileStream s = File.OpenRead(path)) {
|
using (FileStream s = File.OpenRead(path)) {
|
||||||
data = path.EndsWith(BinFormat.Ext)
|
data = path.EndsWith(BinFormat.Ext)
|
||||||
? BinFormat.GetEntries(s, args)
|
? BinFormat.GetEntries(s, args) : TxtFormat.GetEntries(s, args);
|
||||||
: TxtFormat.GetEntries(s, args);
|
|
||||||
|
|
||||||
foreach (Player.UndoPos pos in data)
|
foreach (Player.UndoPos pos in data)
|
||||||
buffer.Add(pos);
|
buffer.Add(pos);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user