mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 12:53:32 +00:00
create addTime function in simple timer (#1363)
* create addTime function in simple timer
This commit is contained in:
committed by
GitHub
parent
e6aa7404f7
commit
607bc40673
@@ -37,6 +37,14 @@ export class SimpleTimer {
|
|||||||
return this.state;
|
return this.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public addTime(millis: number): SimpleTimerState {
|
||||||
|
this.state.duration += millis;
|
||||||
|
// the value of current will be overridden when update is called,
|
||||||
|
// but if we are in pause or stop state it will not be changed so we do it here
|
||||||
|
this.state.current += millis;
|
||||||
|
return this.state;
|
||||||
|
}
|
||||||
|
|
||||||
public setDirection(direction: SimpleDirection, timeNow: number): SimpleTimerState {
|
public setDirection(direction: SimpleDirection, timeNow: number): SimpleTimerState {
|
||||||
// if we are playing, we need to reset the targets
|
// if we are playing, we need to reset the targets
|
||||||
if (this.state.playback === SimplePlayback.Start) {
|
if (this.state.playback === SimplePlayback.Start) {
|
||||||
|
|||||||
@@ -177,5 +177,60 @@ describe('SimpleTimer count-down', () => {
|
|||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('adding time affects final result', () => {
|
||||||
|
timer.reset();
|
||||||
|
|
||||||
|
timer.setTime(1000);
|
||||||
|
timer.start(0);
|
||||||
|
timer.update(100);
|
||||||
|
expect(timer.state).toMatchObject({ current: 900, duration: 1000 });
|
||||||
|
|
||||||
|
timer.addTime(1000);
|
||||||
|
timer.update(200);
|
||||||
|
expect(timer.state).toMatchObject({ current: 1800, duration: 2000 });
|
||||||
|
|
||||||
|
timer.update(300);
|
||||||
|
expect(timer.state).toMatchObject({ current: 1700, duration: 2000 });
|
||||||
|
|
||||||
|
timer.stop();
|
||||||
|
expect(timer.state).toMatchObject({ current: 1000, duration: 1000 });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('adding time affects paused timer', () => {
|
||||||
|
timer.reset();
|
||||||
|
|
||||||
|
timer.setTime(1000);
|
||||||
|
timer.start(0);
|
||||||
|
timer.update(100);
|
||||||
|
expect(timer.state).toMatchObject({ current: 900, duration: 1000 });
|
||||||
|
|
||||||
|
timer.pause(200);
|
||||||
|
expect(timer.state).toMatchObject({ current: 900, duration: 1000 });
|
||||||
|
|
||||||
|
timer.addTime(1000);
|
||||||
|
timer.update(200);
|
||||||
|
expect(timer.state).toMatchObject({ current: 1900, duration: 2000 });
|
||||||
|
|
||||||
|
timer.start(300);
|
||||||
|
expect(timer.state).toMatchObject({ current: 1800, duration: 2000 });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('adding time affects stopped timer, but returns to initial valuses when stopped again', () => {
|
||||||
|
timer.reset();
|
||||||
|
|
||||||
|
timer.setTime(1000);
|
||||||
|
expect(timer.state).toMatchObject({ current: 1000, duration: 1000 });
|
||||||
|
|
||||||
|
timer.addTime(1000);
|
||||||
|
expect(timer.state).toMatchObject({ current: 2000, duration: 2000 });
|
||||||
|
|
||||||
|
timer.start(0);
|
||||||
|
timer.update(100);
|
||||||
|
expect(timer.state).toMatchObject({ current: 1900, duration: 2000 });
|
||||||
|
|
||||||
|
timer.stop();
|
||||||
|
expect(timer.state).toMatchObject({ current: 1000, duration: 1000 });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { SimpleDirection, SimpleTimerState } from 'ontime-types';
|
import { SimpleDirection, SimplePlayback, SimpleTimerState } from 'ontime-types';
|
||||||
|
|
||||||
import { SimpleTimer } from '../../classes/simple-timer/SimpleTimer.js';
|
import { SimpleTimer } from '../../classes/simple-timer/SimpleTimer.js';
|
||||||
import { eventStore } from '../../stores/EventStore.js';
|
import { eventStore } from '../../stores/EventStore.js';
|
||||||
@@ -59,7 +59,11 @@ export class AuxTimerService {
|
|||||||
|
|
||||||
@broadcastReturn
|
@broadcastReturn
|
||||||
addTime(millis: number) {
|
addTime(millis: number) {
|
||||||
return this.timer.setTime(this.timer.state.current + millis);
|
if (this.timer.state.playback === SimplePlayback.Start) {
|
||||||
|
this.timer.addTime(millis);
|
||||||
|
return this.timer.update(this.getTime());
|
||||||
|
}
|
||||||
|
return this.timer.addTime(millis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@broadcastReturn
|
@broadcastReturn
|
||||||
|
|||||||
Reference in New Issue
Block a user