SteamWar/BauSystem2.0
Archiviert
12
0

Implement Region.undo

Implement Region.redo
Implement Region undoSession implement
Dieser Commit ist enthalten in:
yoyosource 2021-04-20 13:39:30 +02:00
Ursprung 09fd349e5d
Commit 5baa457d3f

Datei anzeigen

@ -172,13 +172,6 @@ public class Region {
}
}
private void initSessions() {
if (undoSessions == null) {
undoSessions = new SizedStack<>(20);
redoSessions = new SizedStack<>(20);
}
}
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
if (!hasType(regionType)) {
return false;
@ -361,40 +354,44 @@ public class Region {
PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemType().fightType() || schematic.getSchemType().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel);
EditSession editSession = null;
switch (regionType) {
case BUILD:
System.out.println(schematic + " " + prototype.getBuild().getSchematicFile() + " " + regionType + " " + regionExtensionType + " " + minPointBuild);
if (schematic != null) {
paste(schematic.load(), minPointBuild, pasteOptions);
editSession = paste(schematic.load(), minPointBuild, pasteOptions);
} else {
paste(prototype.getBuild().getSchematicFile(), minPointBuild, pasteOptions);
editSession = paste(prototype.getBuild().getSchematicFile(), minPointBuild, pasteOptions);
}
break;
case TESTBLOCK:
System.out.println(schematic + " " + prototype.getBuild().getSchematicFile() + " " + regionType + " " + regionExtensionType + " " + minPointTestblock);
if (schematic != null) {
paste(schematic.load(), minPointTestblock, pasteOptions);
editSession = paste(schematic.load(), minPointTestblock, pasteOptions);
} else {
paste(prototype.getTestblock().getSchematicFile(), minPointTestblock, pasteOptions);
editSession = paste(prototype.getTestblock().getSchematicFile(), minPointTestblock, pasteOptions);
}
break;
default:
case NORMAL:
System.out.println(schematic + " " + prototype.getBuild().getSchematicFile() + " " + regionType + " " + regionExtensionType + " " + minPoint);
if (schematic != null) {
paste(schematic.load(), minPoint, pasteOptions);
editSession = paste(schematic.load(), minPoint, pasteOptions);
} else {
paste(prototype.getSchematicFile(), minPoint, pasteOptions);
editSession = paste(prototype.getSchematicFile(), minPoint, pasteOptions);
}
break;
}
initSessions();
undoSessions.push(editSession);
}
private static EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
private EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.paste(file, pastePoint, pasteOptions), 15));
}
private static EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
private EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.paste(clipboard, pastePoint, pasteOptions), 15));
}
@ -402,4 +399,47 @@ public class Region {
return this == GlobalRegion.getInstance();
}
private void initSessions() {
if (undoSessions == null) {
undoSessions = new SizedStack<>(20);
redoSessions = new SizedStack<>(20);
}
}
public boolean undo() {
initSessions();
EditSession session = null;
try {
session = undoSessions.pop();
if (session == null) {
return false;
}
session.undo(session);
redoSessions.push(session);
return true;
} finally {
if (session != null) {
session.flushSession();
}
}
}
public boolean redo() {
initSessions();
EditSession session = null;
try {
session = redoSessions.pop();
if (session == null) {
return false;
}
session.redo(session);
undoSessions.push(session);
return true;
} finally {
if (session != null) {
session.flushSession();
}
}
}
}