1 module editorEvents; 2 3 import PixelPerfectEngine.concrete.eventChainSystem; 4 import PixelPerfectEngine.graphics.layers; 5 6 public class WriteToMapVoidFill : UndoableEvent{ 7 ITileLayer target; 8 Coordinate area; 9 MappingElement me; 10 ubyte[] mask; 11 public this(ITileLayer target, Coordinate area, MappingElement me){ 12 this.target = target; 13 this.area = area; 14 this.me = me; 15 } 16 public void redo(){ 17 for(int y = area.top ; y < area.bottom ; y++){ 18 for(int x = area.left ; x < area.right ; x++){ 19 if(target.readMapping(x,y).tileID != 0xFFFF){ 20 mask[area.width * y + x] = 0xFF; 21 target.writeMapping(x,y,me); 22 } 23 } 24 } 25 } 26 public void undo(){ 27 for(int y = area.top ; y < area.bottom ; y++){ 28 for(int x = area.left ; x < area.right ; x++){ 29 if(mask[area.width * y + x] == 0xFF){ 30 target.writeMapping(x,y,MappingElement(0xFFFF)); 31 } 32 } 33 } 34 } 35 } 36 37 public class WriteToMapOverwrite : UndoableEvent{ 38 ITileLayer target; 39 Coordinate area; 40 MappingElement me; 41 MappingElement[] original; 42 public this(ITileLayer target, Coordinate area, MappingElement me){ 43 this.target = target; 44 this.area = area; 45 this.me = me; 46 original.length = area.area; 47 } 48 public void redo(){ 49 size_t pos; 50 for(int y = area.top ; y < area.bottom ; y++){ 51 for(int x = area.left ; x < area.right ; x++){ 52 original[pos] = target.readMapping(x,y); 53 target.writeMapping(x,y,me); 54 pos++; 55 } 56 } 57 } 58 public void undo(){ 59 size_t pos; 60 for(int y = area.top ; y < area.bottom ; y++){ 61 for(int x = area.left ; x < area.right ; x++){ 62 target.writeMapping(x,y,original[pos]); 63 pos++; 64 } 65 } 66 } 67 } 68 69 public class WriteToMapSingle : UndoableEvent{ 70 ITileLayer target; 71 int x; 72 int y; 73 MappingElement me; 74 MappingElement original; 75 public this(ITileLayer target, int x, int y, MappingElement me){ 76 this.target = target; 77 this.x = x; 78 this.y = y; 79 this.me = me; 80 } 81 public void redo(){ 82 original = target.readMapping(x,y); 83 target.writeMapping(x,y,me); 84 } 85 public void undo(){ 86 target.writeMapping(x,y,original); 87 } 88 }