@@ -13,9 +13,10 @@ var View = /** @class */ (function () {
13
13
function View ( ) {
14
14
this . colors = [ "#7FFF00" , "not used" , "#FFB366" ] ;
15
15
this . k = 0 ;
16
- this . paused = false ;
16
+ this . started = false ;
17
17
this . playing = false ;
18
18
this . animSpeed = 500 ;
19
+ this . clickedPlay = true ;
19
20
}
20
21
View . prototype . displayThisArray = function ( array ) {
21
22
displayArray ( JSON . stringify ( array ) ) ;
@@ -145,9 +146,12 @@ var View = /** @class */ (function () {
145
146
} ;
146
147
View . prototype . stepForward = function ( twoDimRelationshipsJSON , backendArray ) {
147
148
//this.step("forward", twoDimRelationshipsJSON, backendArray);
149
+ this . clickedPlay = false ;
148
150
manager . next ( ) ;
149
- if ( manager . nextEvents . length <= 0 )
151
+ if ( manager . nextEvents . length <= 0 ) {
152
+ this . playing = true ;
150
153
manager . start ( ) ;
154
+ }
151
155
} ;
152
156
View . prototype . step = function ( dir , twoDimRelationshipsJSON , backendArray ) {
153
157
var relationships = JSON . parse ( twoDimRelationshipsJSON ) ;
@@ -158,7 +162,7 @@ var View = /** @class */ (function () {
158
162
stepper . stepBack ( relationships , backendArr ) ;
159
163
} ;
160
164
View . prototype . resetAll = function ( ) {
161
- this . paused = false ;
165
+ this . started = false ;
162
166
this . playing = false ;
163
167
$ ( "#play" ) . text ( "Play" ) ;
164
168
manager . pause ( ) ;
@@ -299,74 +303,82 @@ var View = /** @class */ (function () {
299
303
} ( i , val , Math . floor ( ( i - 1 ) / 2 ) ) ;
300
304
manager . addEvent ( new FrontendEvent ( forward , backward , manager . delayTime ) ) ;
301
305
} ;
306
+ View . prototype . insertNewElemThis = function ( child , value , parent ) {
307
+ var forward = function ( index , value , parent ) {
308
+ return function ( ) {
309
+ setValueAtIndex ( index , value ) ;
310
+ insertNewNode ( index , value ) ;
311
+ insertNewElemConnect ( index , parent ) ;
312
+ // If first node -> Position with a nice animation
313
+ if ( control . getAlgorithm ( ) . getArrayLength ( ) == 1 )
314
+ positioningNodes ( 1500 ) ;
315
+ } ;
316
+ } ( child , value , parent ) ;
317
+ var backward = function ( index , parent ) {
318
+ return function ( ) {
319
+ allNodes [ parent ] . removeChild ( allNodes [ index ] ) ;
320
+ //removeElem(index, true);
321
+ setValueAtIndex ( index , "" ) ;
322
+ removeNode ( index ) ;
323
+ } ;
324
+ } ( child , parent ) ;
325
+ manager . addEvent ( new FrontendEvent ( forward , backward , manager . delayTime ) ) ;
326
+ } ;
302
327
View . prototype . play = function ( ) {
328
+ this . clickedPlay = true ;
303
329
var algo = control . getAlgorithm ( ) . getName ( ) ;
304
- if ( algo === "BuildHeap" && ! this . paused && ! this . playing ) {
330
+ if ( algo === "BuildHeap" && ! this . started && ! this . playing ) {
305
331
control . getAlgorithm ( ) . build ( ) ;
306
- this . paused = true ;
307
- this . playing = true ;
308
- $ ( "#play" ) . text ( "Pause" ) ;
309
- lockBackForward ( true ) ;
332
+ this . started = true ;
333
+ this . setPause ( false ) ;
310
334
}
311
- else if ( algo === "HeapSort" && ! this . paused && ! this . playing ) {
335
+ else if ( algo === "HeapSort" && ! this . started && ! this . playing ) {
312
336
control . getAlgorithm ( ) . sort ( ) ;
313
- this . paused = true ;
314
- this . playing = true ;
315
- $ ( "#play" ) . text ( "Pause" ) ;
316
- lockBackForward ( true ) ;
337
+ this . started = true ;
338
+ this . setPause ( false ) ;
317
339
}
318
340
else {
319
341
if ( this . playing ) {
320
- manager . pause ( ) ;
321
- $ ( "#play" ) . text ( "Resume" ) ;
322
- this . playing = false ;
323
- lockBackForward ( false ) ;
342
+ this . setPause ( true ) ;
324
343
}
325
344
else {
326
- this . playing = true ;
327
- manager . start ( ) ;
328
- $ ( "#play" ) . text ( "Pause" ) ;
329
- lockBackForward ( true ) ;
345
+ this . setPause ( false ) ;
330
346
}
331
347
}
332
348
} ;
349
+ View . prototype . setPause = function ( bool ) {
350
+ if ( bool ) {
351
+ this . playing = false ;
352
+ manager . pause ( ) ;
353
+ $ ( "#play" ) . text ( "Resume" ) ;
354
+ lockBackForward ( false ) ;
355
+ }
356
+ else {
357
+ this . playing = true ;
358
+ manager . start ( ) ;
359
+ $ ( "#play" ) . text ( "Pause" ) ;
360
+ lockBackForward ( true ) ;
361
+ }
362
+ } ;
333
363
// Used in eventmanager for freemode and predefined
334
364
View . prototype . playButtonState = function ( ) {
335
365
var algo = control . getAlgorithm ( ) . getName ( ) ;
336
- if ( ! ( algo === "MaxHeap" || algo === "MaxHeapFree" || this . playing ) )
366
+ if ( ! ( algo === "MaxHeap" || algo === "MaxHeapFree" ) )
337
367
return ;
338
- if ( manager . nextEvents . length > 0 ) {
368
+ if ( manager . nextEvents . length > 0 && this . clickedPlay ) {
339
369
this . playing = true ;
340
370
lockPlay ( false ) ;
341
371
lockBackForward ( true ) ;
342
372
$ ( "#play" ) . text ( "Pause" ) ;
343
373
}
374
+ else if ( manager . nextEvents . length > 0 ) {
375
+ return ;
376
+ }
344
377
else {
345
378
lockPlay ( true ) ;
346
379
lockBackForward ( false ) ;
347
380
}
348
381
} ;
349
- View . prototype . insertNewElemThis = function ( child , value , parent ) {
350
- var forward = function ( index , value , parent ) {
351
- return function ( ) {
352
- setValueAtIndex ( index , value ) ;
353
- insertNewNode ( index , value ) ;
354
- insertNewElemConnect ( index , parent ) ;
355
- // If first node -> Position with a nice animation
356
- if ( control . getAlgorithm ( ) . getArrayLength ( ) == 1 )
357
- positioningNodes ( 1500 ) ;
358
- } ;
359
- } ( child , value , parent ) ;
360
- var backward = function ( index , parent ) {
361
- return function ( ) {
362
- allNodes [ parent ] . removeChild ( allNodes [ index ] ) ;
363
- //removeElem(index, true);
364
- setValueAtIndex ( index , "" ) ;
365
- removeNode ( index ) ;
366
- } ;
367
- } ( child , parent ) ;
368
- manager . addEvent ( new FrontendEvent ( forward , backward , manager . delayTime ) ) ;
369
- } ;
370
382
return View ;
371
383
} ( ) ) ;
372
384
var viewer = new View ( ) ;
0 commit comments