rollSkipLimit

This commit is contained in:
arc-alex
2023-11-22 19:05:08 +01:00
parent 8cabb347e9
commit e6b4f537af
3 changed files with 66 additions and 2 deletions
+1
View File
@@ -9,4 +9,5 @@ export const config = {
filename: 'override.css', filename: 'override.css',
}, },
restoreFile: 'ontime.restore', restoreFile: 'ontime.restore',
rollSkipLimit: 3 * 32,
}; };
@@ -2,6 +2,7 @@ import { OntimeEvent } from 'ontime-types';
import { dayInMs } from 'ontime-utils'; import { dayInMs } from 'ontime-utils';
import { getRollTimers, normaliseEndTime, sortArrayByProperty, updateRoll } from '../rollUtils.js'; import { getRollTimers, normaliseEndTime, sortArrayByProperty, updateRoll } from '../rollUtils.js';
import { config } from '../../config/config.js';
// test sortArrayByProperty() // test sortArrayByProperty()
describe('sort simple arrays of objects', () => { describe('sort simple arrays of objects', () => {
@@ -585,6 +586,66 @@ describe('typical scenarios', () => {
expect(updateRoll(timers)).toStrictEqual(expected); expect(updateRoll(timers)).toStrictEqual(expected);
}); });
it('dose not skip isFinished under limit', () => {
const timers = {
selectedEventId: '1',
current: 13,
_finishAt: 15,
_startAt: 9,
clock: 14,
secondaryTimer: null,
secondaryTarget: null,
};
const expected = {
updatedTimer: timers._finishAt - timers.clock,
updatedSecondaryTimer: null,
doRollLoad: false,
isFinished: false,
};
expect(updateRoll(timers)).toStrictEqual(expected);
// test that it can jump time
timers._finishAt = 14;
timers.clock += config.rollSkipLimit - 1;
expected.updatedTimer = timers._finishAt - timers.clock;
expected.doRollLoad = true;
expected.isFinished = true;
expect(updateRoll(timers)).toStrictEqual(expected);
});
it('dose skips isFinished over limit', () => {
const timers = {
selectedEventId: '1',
current: 13,
_finishAt: 15,
_startAt: 9,
clock: 14,
secondaryTimer: null,
secondaryTarget: null,
};
const expected = {
updatedTimer: timers._finishAt - timers.clock,
updatedSecondaryTimer: null,
doRollLoad: false,
isFinished: false,
};
expect(updateRoll(timers)).toStrictEqual(expected);
// test that it can jump time
timers._finishAt = 14;
timers.clock += config.rollSkipLimit + 1;
expected.updatedTimer = timers._finishAt - timers.clock;
expected.doRollLoad = true;
expected.isFinished = false;
expect(updateRoll(timers)).toStrictEqual(expected);
});
it('it updates secondary timer', () => { it('it updates secondary timer', () => {
const timers = { const timers = {
selectedEventId: null, selectedEventId: null,
+4 -2
View File
@@ -1,5 +1,6 @@
import { OntimeEvent } from 'ontime-types'; import { OntimeEvent } from 'ontime-types';
import { dayInMs } from 'ontime-utils'; import { dayInMs } from 'ontime-utils';
import { config } from '../config/config.js';
/** /**
* handle events that span over midnight * handle events that span over midnight
@@ -167,6 +168,7 @@ type CurrentTimers = {
export const updateRoll = (currentTimers: CurrentTimers) => { export const updateRoll = (currentTimers: CurrentTimers) => {
const { selectedEventId, current, _finishAt, _startAt, clock, secondaryTimer, secondaryTarget } = currentTimers; const { selectedEventId, current, _finishAt, _startAt, clock, secondaryTimer, secondaryTarget } = currentTimers;
console.log(currentTimers);
// timers // timers
let updatedTimer = current; let updatedTimer = current;
let updatedSecondaryTimer = secondaryTimer; let updatedSecondaryTimer = secondaryTimer;
@@ -183,12 +185,12 @@ export const updateRoll = (currentTimers: CurrentTimers) => {
updatedTimer -= dayInMs; updatedTimer -= dayInMs;
} }
if (updatedTimer < 0) { if (updatedTimer < 0) {
isPrimaryFinished = true; if (Math.abs(updatedTimer) < config.rollSkipLimit) isPrimaryFinished = true; //Dont trigger Finished if we are over the skip limit
// we need a new event // we need a new event
doRollLoad = true; doRollLoad = true;
} else if (clock < _startAt) { } else if (clock < _startAt) {
// we have rolled back befor this evet start so we need a new one
doRollLoad = true; doRollLoad = true;
} }
} else if (secondaryTimer >= 0) { } else if (secondaryTimer >= 0) {