mirror of
https://github.com/Team4388/2022NoWayHome.git
synced 2026-06-09 00:38:05 -06:00
Fixed type reading
This commit is contained in:
@@ -42,25 +42,24 @@
|
||||
variables = JSON.parse(this.responseText);
|
||||
|
||||
for(let variable of variables) {
|
||||
switch(variable['type']) {
|
||||
case 'expression':
|
||||
variable['lname'] = latexName(variable['name']);
|
||||
calculator.setExpression({ id: variable['name'], latex: variable['lname'] + '=' + variable['value']});
|
||||
break;
|
||||
case 'table':
|
||||
let cols = [];
|
||||
for(let col of variable['value'].split('\s')) {
|
||||
col = col.split(',');
|
||||
let latexStr = latexName(col[0]);
|
||||
let valuesArr = col.slice(1, col.length);
|
||||
console.log();
|
||||
if(EXPRESSION_TYPES['expression'].includes(variable['type'])) {
|
||||
variable['lname'] = latexName(variable['name']);
|
||||
calculator.setExpression({ id: variable['name'], latex: variable['lname'] + '=' + variable['value']});
|
||||
} else if(EXPRESSION_TYPES['table'].includes(variable['type'])) {
|
||||
let cols = [];
|
||||
for(let col of variable['value'].split('\s')) {
|
||||
col = col.split(',');
|
||||
let latexStr = latexName(col[0]);
|
||||
let valuesArr = col.slice(1, col.length);
|
||||
|
||||
cols.push({ latex: latexStr, values: valuesArr });
|
||||
}
|
||||
cols.push({ latex: latexStr, values: valuesArr });
|
||||
}
|
||||
|
||||
calculator.setExpression({ type: 'table', id: variable['name'], columns: cols});
|
||||
break;
|
||||
default:
|
||||
console.log('Invalid type : ' + variable['type']);
|
||||
calculator.setExpression({ type: 'table', id: variable['name'], columns: cols});
|
||||
break;
|
||||
} else {
|
||||
console.log('Invalid type : ' + variable['type']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,20 +71,28 @@
|
||||
let expressions = calculator.getExpressions();
|
||||
|
||||
for(expression of expressions) {
|
||||
let lname = expression['latex'].split('=')[0];
|
||||
let lvalue = expression['latex'].split('=')[1];
|
||||
|
||||
if(lname && lname != '' && lvalue && lvalue != '') {
|
||||
let name = regularName(lname);
|
||||
let value = regularValue(lvalue);
|
||||
|
||||
vars.push({"name": name, "value": value});
|
||||
if(expression['type'] === 'expression') {
|
||||
readVariable(expression['latex']);
|
||||
} else {
|
||||
console.log('Invalid type : ' + expression['type']);
|
||||
}
|
||||
}
|
||||
|
||||
return vars;
|
||||
}
|
||||
|
||||
function readVariable(latex) {
|
||||
let lname = expression['latex'].split('=')[0];
|
||||
let lvalue = expression['latex'].split('=')[1];
|
||||
|
||||
if(lname && lname != '' && lvalue && lvalue != '') {
|
||||
let name = regularName(lname);
|
||||
let value = regularValue(lvalue);
|
||||
|
||||
vars.push({"name": name, "value": value});
|
||||
}
|
||||
}
|
||||
|
||||
function latexName(name) {
|
||||
return name.substring(0, 1) + '_{' + name.substring(1, name.length) + '}';
|
||||
}
|
||||
|
||||
@@ -213,10 +213,10 @@ public class DesmosServer extends Thread {
|
||||
tableStr += table[i] + ",";
|
||||
String values = Arrays.toString((double[]) table[i+1]).replace(" ", "");
|
||||
tableStr += values.substring(1, values.length() - 1);
|
||||
tableStr += " ";
|
||||
tableStr += ' ';
|
||||
}
|
||||
|
||||
tableStr = tableStr.substring(0, tableStr.length()-1); // remove tab at the end
|
||||
tableStr = tableStr.substring(0, tableStr.length()-1); // remove space at the end
|
||||
|
||||
desmosVariables.put(name, new String[] {"table", tableStr});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user