assets/scripts.js: Rename generateJs to preconditionToJS

This commit is contained in:
Vladimir Panteleev 2019-07-28 00:47:38 +00:00
parent 350a2caead
commit 588036f80e

View file

@ -21,21 +21,21 @@ function getCurrentMs() {
return Math.round(document.getElementById("video").currentTime * 1000.0); return Math.round(document.getElementById("video").currentTime * 1000.0);
} }
function generateJs(cond) { function preconditionToJS(cond) {
if (cond[0] == 'persistentState') { if (cond[0] == 'persistentState') {
return '!!persistentState["' + cond[1] + '"]'; return '!!persistentState["' + cond[1] + '"]';
} else if (cond[0] == 'not') { } else if (cond[0] == 'not') {
return '!(' + generateJs(cond[1]) + ')'; return '!(' + preconditionToJS(cond[1]) + ')';
} else if (cond[0] == 'and') { } else if (cond[0] == 'and') {
let conds = []; let conds = [];
for (let i = 1; i < cond.length; i++) { for (let i = 1; i < cond.length; i++) {
conds.push('(' + generateJs(cond[i]) + ')'); conds.push('(' + preconditionToJS(cond[i]) + ')');
} }
return '(' + conds.join(' && ') + ')'; return '(' + conds.join(' && ') + ')';
} else if (cond[0] == 'or') { } else if (cond[0] == 'or') {
let conds = []; let conds = [];
for (let i = 1; i < cond.length; i++) { for (let i = 1; i < cond.length; i++) {
conds.push('(' + generateJs(cond[i]) + ')'); conds.push('(' + preconditionToJS(cond[i]) + ')');
} }
return '(' + conds.join(' || ') + ')'; return '(' + conds.join(' || ') + ')';
} else { } else {
@ -48,7 +48,7 @@ function checkPrecondition(segmentId) {
let precondition = bv.preconditions[segmentId]; let precondition = bv.preconditions[segmentId];
if (precondition) { if (precondition) {
let cond = generateJs(precondition); let cond = preconditionToJS(precondition);
let match = eval(cond); let match = eval(cond);
console.log(cond, '==', match); console.log(cond, '==', match);