Kopie van https://gitlab.com/studieverenigingvia/ict/centurion met een paar aanpassingen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
979 B
52 lines
979 B
const timeline = require('../data/timeline.js');
|
|
|
|
/**
|
|
*
|
|
* @param i
|
|
* @returns {*}
|
|
*/
|
|
function getIndex(i) {
|
|
if (i >= timeline.length) {
|
|
return;
|
|
}
|
|
|
|
return timeline[i];
|
|
}
|
|
|
|
/**
|
|
* @param {number} i - the index.
|
|
* @returns {{count: number, timestamp: number}|undefined}
|
|
*/
|
|
function getNextShot(i) {
|
|
for (; i < timeline.length; i++) {
|
|
const time = getIndex(i);
|
|
|
|
for (let event of time.events) {
|
|
if (event.type === 'shot') {
|
|
return {
|
|
timestamp: time.timestamp,
|
|
count: event.shotCount
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
function indexForTime(seconds) {
|
|
let lastIndex = 0;
|
|
for(let i = 0; i < timeline.length; i++) {
|
|
const time = timeline[i];
|
|
|
|
if (time.timestamp >= seconds) {
|
|
return lastIndex;
|
|
}
|
|
|
|
lastIndex = i;
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getIndex, getNextShot, indexForTime
|
|
}; |