Remove code duplication and rename set/get method on editor/DrawOperation.java (#496)
- remove code duplication in undo and redo method - rename set/get method to setTile/getTile
This commit is contained in:
@@ -24,21 +24,23 @@ public class DrawOperation{
|
|||||||
|
|
||||||
public void undo(MapEditor editor){
|
public void undo(MapEditor editor){
|
||||||
for(int i = array.size - 1; i >= 0; i--){
|
for(int i = array.size - 1; i >= 0; i--){
|
||||||
long l = array.get(i);
|
updateTile(editor, i);
|
||||||
array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), get(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l))));
|
|
||||||
set(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.value(l));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void redo(MapEditor editor){
|
public void redo(MapEditor editor){
|
||||||
for(int i = 0; i < array.size; i++){
|
for(int i = 0; i < array.size; i++){
|
||||||
long l = array.get(i);
|
updateTile(editor, i);
|
||||||
array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), get(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l))));
|
|
||||||
set(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.value(l));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
short get(Tile tile, byte type){
|
private void updateTile(MapEditor editor, 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
short getTile(Tile tile, byte type){
|
||||||
if(type == OpType.floor.ordinal()){
|
if(type == OpType.floor.ordinal()){
|
||||||
return tile.floorID();
|
return tile.floorID();
|
||||||
}else if(type == OpType.block.ordinal()){
|
}else if(type == OpType.block.ordinal()){
|
||||||
@@ -53,7 +55,7 @@ public class DrawOperation{
|
|||||||
throw new IllegalArgumentException("Invalid type.");
|
throw new IllegalArgumentException("Invalid type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(MapEditor editor, Tile tile, byte type, short to){
|
void setTile(MapEditor editor, Tile tile, byte type, short to){
|
||||||
editor.load(() -> {
|
editor.load(() -> {
|
||||||
if(type == OpType.floor.ordinal()){
|
if(type == OpType.floor.ordinal()){
|
||||||
tile.setFloor((Floor)content.block(to));
|
tile.setFloor((Floor)content.block(to));
|
||||||
|
|||||||
Reference in New Issue
Block a user