File tree Expand file tree Collapse file tree 6 files changed +64
-8
lines changed Expand file tree Collapse file tree 6 files changed +64
-8
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
2
* Created by knutandersstokke on 16.10.2016.
3
- *
3
+ * Modified by Øyvind Skeie Liland
4
4
*/
5
5
/** Manager for events stored in queue. Manager is also responsible for executing events automatically */
6
6
var EventManager = /** @class */ ( function ( ) {
@@ -11,6 +11,7 @@ var EventManager = /** @class */ (function () {
11
11
}
12
12
// Executing the next event in the queue, adding it to 'previous'
13
13
EventManager . prototype . next = function ( ) {
14
+ viewer . playButtonState ( ) ;
14
15
if ( this . nextEvents . length == 0 ) {
15
16
return ;
16
17
}
@@ -23,13 +24,10 @@ var EventManager = /** @class */ (function () {
23
24
} ;
24
25
// Executing the previous event
25
26
EventManager . prototype . previous = function ( ) {
26
- this . pause ( ) ;
27
27
if ( this . previousEvents . length == 0 )
28
28
return ;
29
29
var event = this . previousEvents . pop ( ) ;
30
30
//this.delayTime = 0; //TODO: Should there be a delay when stepping backwards?
31
- console . log ( event ) ;
32
- console . log ( this . previousEvents ) ;
33
31
event . previous ( ) ;
34
32
this . nextEvents . unshift ( event ) ;
35
33
} ;
Original file line number Diff line number Diff line change 1
1
/**
2
2
* Created by knutandersstokke on 16.10.2016.
3
- *
3
+ * Modified by Øyvind Skeie Liland
4
4
*/
5
5
6
6
declare var $ : any ;
@@ -14,6 +14,7 @@ class EventManager {
14
14
15
15
// Executing the next event in the queue, adding it to 'previous'
16
16
next ( ) {
17
+ viewer . playButtonState ( ) ;
17
18
if ( this . nextEvents . length == 0 ) {
18
19
return ;
19
20
}
@@ -27,13 +28,10 @@ class EventManager {
27
28
28
29
// Executing the previous event
29
30
previous ( ) {
30
- this . pause ( ) ;
31
31
if ( this . previousEvents . length == 0 )
32
32
return ;
33
33
var event : FrontendEvent = ( < FrontendEvent > this . previousEvents . pop ( ) ) ;
34
34
//this.delayTime = 0; //TODO: Should there be a delay when stepping backwards?
35
- console . log ( event ) ;
36
- console . log ( this . previousEvents ) ;
37
35
38
36
event . previous ( ) ;
39
37
this . nextEvents . unshift ( event ) ;
Original file line number Diff line number Diff line change @@ -297,26 +297,46 @@ var View = /** @class */ (function () {
297
297
this . paused = true ;
298
298
this . playing = true ;
299
299
$ ( "#play" ) . text ( "Pause" ) ;
300
+ lockBackForward ( true ) ;
300
301
}
301
302
else if ( algo === "HeapSort" && ! this . paused && ! this . playing ) {
302
303
control . getAlgorithm ( ) . sort ( ) ;
303
304
this . paused = true ;
304
305
this . playing = true ;
305
306
$ ( "#play" ) . text ( "Pause" ) ;
307
+ lockBackForward ( true ) ;
306
308
}
307
309
else {
308
310
if ( this . playing ) {
309
311
manager . pause ( ) ;
310
312
$ ( "#play" ) . text ( "Resume" ) ;
311
313
this . playing = false ;
314
+ lockBackForward ( false ) ;
312
315
}
313
316
else {
314
317
this . playing = true ;
315
318
manager . start ( ) ;
316
319
$ ( "#play" ) . text ( "Pause" ) ;
320
+ lockBackForward ( true ) ;
317
321
}
318
322
}
319
323
} ;
324
+ // Used in eventmanager for freemode and predefined
325
+ View . prototype . playButtonState = function ( ) {
326
+ var algo = control . getAlgorithm ( ) . getName ( ) ;
327
+ if ( ! ( algo === "MaxHeap" || algo === "MaxHeapFree" ) )
328
+ return ;
329
+ if ( manager . nextEvents . length > 0 ) {
330
+ this . playing = true ;
331
+ lockPlay ( false ) ;
332
+ lockBackForward ( true ) ;
333
+ $ ( "#play" ) . text ( "Pause" ) ;
334
+ }
335
+ else {
336
+ lockPlay ( true ) ;
337
+ lockBackForward ( false ) ;
338
+ }
339
+ } ;
320
340
View . prototype . insertNewElemThis = function ( child , value , parent ) {
321
341
var forward = function ( index , value , parent ) {
322
342
return function ( ) {
Original file line number Diff line number Diff line change @@ -352,24 +352,44 @@ class View implements IView {
352
352
this . paused = true ;
353
353
this . playing = true ;
354
354
$ ( "#play" ) . text ( "Pause" ) ;
355
+ lockBackForward ( true ) ;
355
356
} else if ( algo === "HeapSort" && ! this . paused && ! this . playing ) {
356
357
( < HeapSort > control . getAlgorithm ( ) ) . sort ( ) ;
357
358
this . paused = true ;
358
359
this . playing = true ;
359
360
$ ( "#play" ) . text ( "Pause" ) ;
361
+ lockBackForward ( true ) ;
360
362
} else {
361
363
if ( this . playing ) {
362
364
manager . pause ( ) ;
363
365
$ ( "#play" ) . text ( "Resume" ) ;
364
366
this . playing = false ;
367
+ lockBackForward ( false ) ;
365
368
} else {
366
369
this . playing = true ;
367
370
manager . start ( ) ;
368
371
$ ( "#play" ) . text ( "Pause" ) ;
372
+ lockBackForward ( true ) ;
369
373
}
370
374
}
371
375
}
372
376
377
+ // Used in eventmanager for freemode and predefined
378
+ playButtonState ( ) {
379
+ let algo = control . getAlgorithm ( ) . getName ( ) ;
380
+ if ( ! ( algo === "MaxHeap" || algo === "MaxHeapFree" ) )
381
+ return ;
382
+
383
+ if ( manager . nextEvents . length > 0 ) {
384
+ this . playing = true ;
385
+ lockPlay ( false ) ;
386
+ lockBackForward ( true ) ;
387
+ $ ( "#play" ) . text ( "Pause" ) ;
388
+ } else {
389
+ lockPlay ( true ) ;
390
+ lockBackForward ( false ) ;
391
+ }
392
+ }
373
393
374
394
insertNewElemThis ( child : number , value : number , parent : number ) {
375
395
let forward = function ( index , value , parent ) {
Original file line number Diff line number Diff line change @@ -336,6 +336,16 @@ function lockPlay(lock) {
336
336
$ ( "#play" ) . removeAttr ( "disabled" ) ;
337
337
}
338
338
}
339
+ function lockBackForward ( lock ) {
340
+ if ( lock ) {
341
+ $ ( "#backward" ) . attr ( { "disabled" : "true" } ) ;
342
+ $ ( "#forward" ) . attr ( { "disabled" : "true" } ) ;
343
+ }
344
+ else {
345
+ $ ( "#backward" ) . removeAttr ( "disabled" ) ;
346
+ $ ( "#forward" ) . removeAttr ( "disabled" ) ;
347
+ }
348
+ }
339
349
function stepBack ( ) {
340
350
if ( firstSelected != - 1 ) {
341
351
selectIndex ( firstSelected , false ) ;
Original file line number Diff line number Diff line change @@ -392,6 +392,16 @@ function lockPlay(lock: boolean) {
392
392
}
393
393
}
394
394
395
+ function lockBackForward ( lock : boolean ) {
396
+ if ( lock ) {
397
+ $ ( "#backward" ) . attr ( { "disabled" : "true" } ) ;
398
+ $ ( "#forward" ) . attr ( { "disabled" : "true" } ) ;
399
+ } else {
400
+ $ ( "#backward" ) . removeAttr ( "disabled" ) ;
401
+ $ ( "#forward" ) . removeAttr ( "disabled" ) ;
402
+ }
403
+ }
404
+
395
405
function stepBack ( ) {
396
406
if ( firstSelected != - 1 ) {
397
407
selectIndex ( firstSelected , false ) ;
You can’t perform that action at this time.
0 commit comments