1
+ /**
2
+ * Created by Daniel on 20.07.15.
3
+ */
4
+
5
+ CmdMoveObject = function ( object , newParent , newBefore ) {
6
+
7
+ Cmd . call ( this ) ;
8
+
9
+ this . type = 'CmdMoveObject' ;
10
+
11
+ this . object = object ;
12
+ this . objectUuid = object !== undefined ? object . uuid : undefined ;
13
+
14
+ this . oldParent = object !== undefined ? object . parent : undefined ;
15
+ this . oldParentUuid = this . oldParent !== undefined ? this . oldParent . uuid : undefined ;
16
+ this . oldIndex = this . oldParent !== undefined ? this . oldParent . children . indexOf ( this . object ) : undefined ;
17
+
18
+ this . newParent = newParent ;
19
+ this . newParentUuid = newParent !== undefined ? newParent . uuid : undefined ;
20
+
21
+ if ( newBefore !== undefined ) {
22
+
23
+ this . newIndex = newParent !== undefined ? newParent . children . indexOf ( newBefore ) : undefined ;
24
+
25
+ } else {
26
+
27
+ this . newIndex = newParent !== undefined ? newParent . children . length : undefined ;
28
+
29
+ }
30
+
31
+ if ( this . oldParent === this . newParent && this . newIndex > this . oldIndex ) {
32
+
33
+ this . newIndex -- ;
34
+
35
+ }
36
+
37
+ this . newBefore = newBefore ;
38
+
39
+ } ;
40
+
41
+ CmdMoveObject . prototype = {
42
+
43
+ execute : function ( ) {
44
+
45
+ this . oldParent . remove ( this . object ) ;
46
+
47
+ var children = this . newParent . children ;
48
+ children . splice ( this . newIndex , 0 , this . object ) ;
49
+ this . object . parent = this . newParent ;
50
+
51
+ this . editor . signals . sceneGraphChanged . dispatch ( ) ;
52
+
53
+ } ,
54
+
55
+ undo : function ( ) {
56
+
57
+ this . newParent . remove ( this . object ) ;
58
+
59
+ var children = this . oldParent . children ;
60
+ children . splice ( this . oldIndex , 0 , this . object ) ;
61
+ this . object . parent = this . oldParent ;
62
+
63
+ this . editor . signals . sceneGraphChanged . dispatch ( ) ;
64
+
65
+ } ,
66
+
67
+ toJSON : function ( ) {
68
+
69
+ var output = Cmd . prototype . toJSON . call ( this ) ;
70
+
71
+ output . objectUuid = this . objectUuid ;
72
+ output . newParentUuid = this . newParentUuid ;
73
+ output . oldParentUuid = this . oldParentUuid ;
74
+ output . newIndex = this . newIndex ;
75
+ output . oldIndex = this . oldIndex ;
76
+
77
+ return output ;
78
+
79
+ } ,
80
+
81
+ fromJSON : function ( json ) {
82
+
83
+ Cmd . prototype . fromJSON . call ( this , json ) ;
84
+
85
+ this . object = this . editor . objectByUuid ( json . objectUuid ) ;
86
+ this . objectUuid = json . objectUuid ;
87
+
88
+ this . oldParent = this . editor . objectByUuid ( json . oldParentUuid ) ;
89
+ this . oldParentUuid = json . oldParentUuid ;
90
+
91
+ this . newParent = this . editor . objectByUuid ( json . newParentUuid ) ;
92
+ this . newParentUuid = json . newParentUuid ;
93
+
94
+ this . newIndex = json . newIndex ;
95
+ this . oldIndex = json . oldIndex ;
96
+
97
+ }
98
+
99
+ } ;
0 commit comments