@@ -90,34 +90,36 @@ class PageFour extends React.Component {
90
90
const previousStageIndex = this . state . blockIndex ;
91
91
const previousStage = allStages [ previousStageIndex ] ;
92
92
const newStage = allStages [ index ] ;
93
+ const times = 20
94
+ // this.setState({
95
+ // drawBlocks: [...newStage]
96
+ // });
97
+ //
98
+ // requestAnimationFrame(() => {
99
+ //
100
+ // })
93
101
94
- // Differ 2 sets of blocks
95
- // - find out, different blocks;
96
- // - blockId | blockIndex
97
- // - blockId => src, x1, y1, dest, x2, y2
98
- // - blockId => xn, yn: x1 + (x2-x1)/10 * n, ...
99
- // - blockId => xn, yn
100
- // - [{blockId1: [xn, yn], blockId2: [xn, yn]},
101
- // {},
102
- // {}
103
- // ]
104
- // => movedBlocks
105
102
const movedBlocks = { } ;
106
103
previousStage . map ( ( eachBlock , i ) => {
104
+ if ( eachBlock . name !== newStage [ i ] . name ) return
107
105
if ( eachBlock . x !== newStage [ i ] . x || eachBlock . y !== newStage [ i ] . y ) {
108
106
// 10
109
107
// { blockId => [{x:x1,y:y1}, {x: x2, y: y2}, , x3, .... x10] }
110
108
const changingPos = [ ] ;
111
- for ( let j = 0 ; j < 50 ; j ++ ) {
109
+ for ( let j = 0 ; j < times ; j ++ ) {
112
110
const specificPos = { }
113
- specificPos . x = eachBlock . x + ( newStage [ i ] . x - eachBlock . x ) / 50 * ( j + 1 )
114
- specificPos . y = eachBlock . y + ( newStage [ i ] . y - eachBlock . y ) / 50 * ( j + 1 )
111
+ // specificPos.x = eachBlock.x + (newStage[i].x - eachBlock.x)/50 * (j + 1)
112
+ // specificPos.y = eachBlock.y + (newStage[i].y - eachBlock.y)/50 * (j + 1)
113
+ specificPos . minX = eachBlock . minX + ( newStage [ i ] . minX - eachBlock . minX ) / times * ( j + 1 ) ;
114
+ specificPos . maxX = eachBlock . maxX + ( newStage [ i ] . maxX - eachBlock . maxX ) / times * ( j + 1 ) ;
115
+ specificPos . minY = eachBlock . minY + ( newStage [ i ] . minY - eachBlock . minY ) / times * ( j + 1 ) ;
116
+ specificPos . maxY = eachBlock . maxY + ( newStage [ i ] . maxY - eachBlock . maxY ) / times * ( j + 1 ) ;
115
117
changingPos . push ( specificPos )
116
118
}
117
119
movedBlocks [ eachBlock . name ] = changingPos
118
120
}
119
121
} )
120
- //console.log(movedBlocks)
122
+
121
123
// draw 100 times, during 2 seconds, slash: 20ms
122
124
let i = 0 ;
123
125
if ( this . handler ) {
@@ -130,25 +132,33 @@ class PageFour extends React.Component {
130
132
const move = movedBlocks [ block . name ] ;
131
133
// I need to move
132
134
// Replace old x, y, with computed x, y (which will change per 20ms)
135
+ // return block;
136
+
133
137
return {
134
138
...block ,
135
- x : move [ i ] . x ,
136
- y : move [ i ] . y
137
- }
139
+ minX : move [ i ] . minX ,
140
+ maxX : move [ i ] . maxX ,
141
+ maxY : move [ i ] . maxY ,
142
+ minY : move [ i ] . minY
143
+ } ;
138
144
} else {
139
145
// Keep at original position
140
146
return block ;
141
147
}
142
148
} )
149
+
143
150
this . setState ( {
144
151
drawBlocks : [ ...newDrawBlocks ]
145
152
} ) ;
146
153
i ++ ;
147
- //console.info(i, newDrawBlocks);
154
+ // console.info(i, newDrawBlocks);
148
155
149
- if ( i >= 50 ) {
156
+ if ( i >= times ) {
150
157
clearInterval ( handler ) ;
151
158
this . handler = false ;
159
+ this . setState ( {
160
+ drawBlocks : [ ...newStage ]
161
+ } ) ;
152
162
}
153
163
} , 60 / this . state . playSpeed ) ;
154
164
this . handler = handler ;
@@ -170,6 +180,7 @@ class PageFour extends React.Component {
170
180
playButtonColor : 'primary' ,
171
181
pauseButtonColor : 'default'
172
182
} ) ;
183
+ this . diff ( index )
173
184
}
174
185
175
186
handleStepClick ( value ) {
@@ -189,6 +200,7 @@ class PageFour extends React.Component {
189
200
playButtonColor : 'primary' ,
190
201
pauseButtonColor : 'default'
191
202
} ) ;
203
+ this . diff ( index )
192
204
//console.info('DOM:', this.stepItem[index]);
193
205
this . stepItem [ index ] . current . scrollIntoView ( ) ;
194
206
}
@@ -207,6 +219,7 @@ class PageFour extends React.Component {
207
219
stepInfoIndex : previousIndex ,
208
220
selectedSubGoals : map
209
221
} ) ;
222
+ this . diff ( previousIndex )
210
223
//console.info('DOM:', this.stepItem[index]);
211
224
this . stepItem [ previousIndex ] . current . scrollIntoView ( ) ;
212
225
}
@@ -226,6 +239,7 @@ class PageFour extends React.Component {
226
239
stepInfoIndex : nextIndex ,
227
240
selectedSubGoals : map
228
241
} ) ;
242
+ this . diff ( nextIndex )
229
243
// console.info('DOM:', this.stepItem[index]);
230
244
this . stepItem [ nextIndex ] . current . scrollIntoView ( ) ;
231
245
}
@@ -236,7 +250,6 @@ class PageFour extends React.Component {
236
250
if ( nextIndex === steps . length ) {
237
251
alert ( "It's already the final state!" )
238
252
} else {
239
- this . diff ( nextIndex )
240
253
const map = this . highlight ( nextIndex )
241
254
this . setState ( {
242
255
blockIndex : nextIndex ,
@@ -245,6 +258,7 @@ class PageFour extends React.Component {
245
258
playButtonColor : 'default' ,
246
259
pauseButtonColor : 'primary' }
247
260
)
261
+ this . diff ( nextIndex )
248
262
this . stepItem [ nextIndex ] . current . scrollIntoView ( ) ;
249
263
250
264
nextIndex ++ ;
@@ -253,8 +267,8 @@ class PageFour extends React.Component {
253
267
}
254
268
if ( steps . length > nextIndex ) {
255
269
const run = ( ) => {
256
- this . diff ( nextIndex )
257
270
const map = this . highlight ( nextIndex )
271
+ this . diff ( nextIndex )
258
272
this . setState ( {
259
273
blockIndex : nextIndex ,
260
274
stepInfoIndex : nextIndex ,
@@ -275,12 +289,12 @@ class PageFour extends React.Component {
275
289
} else {
276
290
// setInterval effect
277
291
// detect change of playSpeed
278
- const handlerPlay = setTimeout ( run , 1000 / this . state . playSpeed ) ;
292
+ const handlerPlay = setTimeout ( run , 3000 / this . state . playSpeed ) ;
279
293
this . handlerPlay = handlerPlay ;
280
294
}
281
295
} ;
282
296
283
- const handlerPlay = setTimeout ( run , 1000 / this . state . playSpeed ) ;
297
+ const handlerPlay = setTimeout ( run , 3000 / this . state . playSpeed ) ;
284
298
this . handlerPlay = handlerPlay ;
285
299
}
286
300
}
@@ -365,9 +379,10 @@ class PageFour extends React.Component {
365
379
366
380
render ( ) {
367
381
// Get all sprites
368
- var sprites = vfg . visualStages [ this . state . stepInfoIndex ] . visualSprites ;
382
+ // var sprites = vfg.visualStages[this.state.stepInfoIndex].visualSprites;
383
+ var sprites = this . state . drawBlocks ;
369
384
// Sort sprites by their depth
370
- sprites . sort ( ( itemA , itemB ) => itemA . depth - itemB . depth )
385
+ sprites . sort ( ( itemA , itemB ) => itemA . depth - itemB . depth )
371
386
372
387
return (
373
388
< div className = { styles . container } >
@@ -404,7 +419,10 @@ class PageFour extends React.Component {
404
419
// Get the texture name
405
420
var textureName = sprite . prefabimage
406
421
// Get the color of the sprite
407
- var color = utils . rgb2hex ( [ sprite . color . r , sprite . color . g , sprite . color . b ] )
422
+ var color = null
423
+ if ( sprite . color ) {
424
+ color = utils . rgb2hex ( [ sprite . color . r , sprite . color . g , sprite . color . b ] )
425
+ }
408
426
// Initialize the rotation of the sprite
409
427
var rotation = 0
410
428
// Initialize the x-axis coordinate position of the sprite
0 commit comments