mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 11:17:11 +07:00
decoupling editor/MapEditor from editor/OperationStack (#504)
This commit is contained in:
commit
30a254e9be
@ -12,8 +12,13 @@ import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class DrawOperation{
|
||||
private MapEditor editor;
|
||||
private LongArray array = new LongArray();
|
||||
|
||||
public DrawOperation(MapEditor editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
public boolean isEmpty(){
|
||||
return array.isEmpty();
|
||||
}
|
||||
@ -22,22 +27,22 @@ public class DrawOperation{
|
||||
array.add(op);
|
||||
}
|
||||
|
||||
public void undo(MapEditor editor){
|
||||
public void undo(){
|
||||
for(int i = array.size - 1; i >= 0; i--){
|
||||
updateTile(editor, i);
|
||||
updateTile(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void redo(MapEditor editor){
|
||||
public void redo(){
|
||||
for(int i = 0; i < array.size; i++){
|
||||
updateTile(editor, i);
|
||||
updateTile(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTile(MapEditor editor, int i) {
|
||||
private void updateTile(int i) {
|
||||
long l = array.get(i);
|
||||
array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), getTile(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l))));
|
||||
setTile(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.value(l));
|
||||
setTile(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.value(l));
|
||||
}
|
||||
|
||||
short getTile(Tile tile, byte type){
|
||||
@ -55,7 +60,7 @@ public class DrawOperation{
|
||||
throw new IllegalArgumentException("Invalid type.");
|
||||
}
|
||||
|
||||
void setTile(MapEditor editor, Tile tile, byte type, short to){
|
||||
void setTile(Tile tile, byte type, short to){
|
||||
editor.load(() -> {
|
||||
if(type == OpType.floor.ordinal()){
|
||||
tile.setFloor((Floor)content.block(to));
|
||||
|
@ -240,13 +240,13 @@ public class MapEditor{
|
||||
|
||||
public void undo(){
|
||||
if(stack.canUndo()){
|
||||
stack.undo(this);
|
||||
stack.undo();
|
||||
}
|
||||
}
|
||||
|
||||
public void redo(){
|
||||
if(stack.canRedo()){
|
||||
stack.redo(this);
|
||||
stack.redo();
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ public class MapEditor{
|
||||
public void addTileOp(long data){
|
||||
if(loading) return;
|
||||
|
||||
if(currentOp == null) currentOp = new DrawOperation();
|
||||
if(currentOp == null) currentOp = new DrawOperation(this);
|
||||
currentOp.addOperation(data);
|
||||
|
||||
renderer.updatePoint(TileOp.x(data), TileOp.y(data));
|
||||
|
@ -34,18 +34,18 @@ public class OperationStack{
|
||||
return !(index > -1 || stack.size + index < 0);
|
||||
}
|
||||
|
||||
public void undo(MapEditor editor){
|
||||
public void undo(){
|
||||
if(!canUndo()) return;
|
||||
|
||||
stack.get(stack.size - 1 + index).undo(editor);
|
||||
stack.get(stack.size - 1 + index).undo();
|
||||
index--;
|
||||
}
|
||||
|
||||
public void redo(MapEditor editor){
|
||||
public void redo(){
|
||||
if(!canRedo()) return;
|
||||
|
||||
index++;
|
||||
stack.get(stack.size - 1 + index).redo(editor);
|
||||
stack.get(stack.size - 1 + index).redo();
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user