1 package net.systemeD.halcyon.connection.actions {
3 import net.systemeD.halcyon.connection.*;
5 public class RemoveNodeByIndexAction extends UndoableEntityAction {
8 private var nodeList:Array;
9 private var index:uint;
10 private var removed:Array;
11 private var fireEvent:Boolean;
13 public function RemoveNodeByIndexAction(way:Way, nodeList:Array, index:uint, fireEvent:Boolean=true) {
14 super(way, "Remove node " + nodeList[index].id + " from position " + index);
16 this.nodeList = nodeList;
18 this.fireEvent = fireEvent;
21 public override function doAction():uint {
22 var preceding:Node=(index>1) ? nodeList[index-1] : null;
23 var node:Node=nodeList[index];
26 while (nodeList[index]==node || nodeList[index]==preceding) {
27 var removedNode:Node=nodeList.splice(index, 1)[0];
28 removed.push(removedNode);
29 if (nodeList.indexOf(removedNode)==-1) { removedNode.removeParent(way); }
31 entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, removedNode, way, index));
34 way.deleted = nodeList.length == 0;
39 public override function undoAction():uint {
40 for (var i:uint=removed.length-1; i>=0; i--) {
41 nodeList.splice(index, 0, removed[i]);
42 removed[i].addParent(way);
44 entity.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_ADDED, removed[i], way, index));
47 way.deleted = nodeList.length == 0;