2e623aecfaaff9b472e696bbe9f15c9404cf0623
[potlatch2.git] / net / systemeD / halcyon / connection / actions / RemoveNodeByIndexAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class RemoveNodeByIndexAction extends UndoableEntityAction {
6     
7         private var way:Way;
8         private var nodeList:Array;
9         private var index:uint;
10         private var removed:Array;
11         private var fireEvent:Boolean;
12     
13         public function RemoveNodeByIndexAction(way:Way, nodeList:Array, index:uint, fireEvent:Boolean=true) {
14             super(way, "Remove node " + nodeList[index].id + " from position " + index);
15             this.way = way;
16             this.nodeList = nodeList;
17             this.index = index;
18             this.fireEvent = fireEvent;
19         }
20         
21         public override function doAction():uint {
22             removed = nodeList.splice(index, 1);
23             if (nodeList.indexOf(removed[0])==-1) { removed[0].removeParent(way); }
24             way.deleted = nodeList.length == 0;
25             markDirty();
26             if (fireEvent) {
27                entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, removed[0], way, index));
28             }
29             return SUCCESS;
30         }
31         
32         public override function undoAction():uint {
33             nodeList.splice(index, 0, removed[0]);
34             removed[0].addParent(way);
35             way.deleted = nodeList.length == 0;
36             markClean();
37             if (fireEvent) {
38                 entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_ADDED, removed[0], way, index));
39             }
40             return SUCCESS;
41         }
42     }
43 }