XDUPlayer/Js/Common.js
2018-03-28 07:14:26 -07:00

53 lines
989 B
JavaScript

'use strict';
var rootUrl = `${window.location.protocol}//${window.location.host}/`
class commonFunctions {
static getFileText(file) {
return new Promise((resolve, reject) => {
fetch(file)
.then((success) => {
success.text()
.then((text) => {
resolve(text);
});
}, (failure) => {
reject(failure);
});
});
}
static getFileJson(file) {
return new Promise((resolve, reject) => {
fetch(file)
.then((success) => {
success.json()
.then((json) => {
resolve(json);
});
}, (failure) => {
reject(failure);
});
});
}
static readLine(line, headers) {
if(line.startsWith('//')) {
return {comment: line};
} else if(!line) {
return undefined;
} else {
var split = line.split('\t');
var newEntry = {};
for(let i = 0; i < split.length; ++i) {
var x = split[i];
newEntry[headers[i]] = x;
}
return newEntry;
}
}
static lerp(start, end, t) {
return (1 - t) * start + t * end;
}
}