mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-15 01:34:48 +00:00
* wip backport of custom uniforms * Functioning custom uniforms maybe? * Workon separating dynamic/non-dynamic uniforms and making variables available to custom uniforms (currently the JVM dies horribly) * wip * It no longer crashes horrifically * star imports
37 lines
1.0 KiB
Java
37 lines
1.0 KiB
Java
package kroppeb.stareval.function;
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|
import kroppeb.stareval.expression.Expression;
|
|
import kroppeb.stareval.expression.VariableExpression;
|
|
|
|
import java.util.Map;
|
|
|
|
public class BasicFunctionContext implements FunctionContext {
|
|
final private Map<String, Expression> variables = new Object2ObjectOpenHashMap<>();
|
|
|
|
public void setVariable(String name, Expression value) {
|
|
variables.put(name, value);
|
|
}
|
|
|
|
public void setIntVariable(String name, int value) {
|
|
setVariable(name, (VariableExpression) (c, r) -> r.intReturn = value);
|
|
}
|
|
|
|
public void setFloatVariable(String name, float value) {
|
|
setVariable(name, (VariableExpression) (c, r) -> r.floatReturn = value);
|
|
}
|
|
|
|
@Override
|
|
public Expression getVariable(String name) {
|
|
Expression expression = variables.get(name);
|
|
if (expression == null)
|
|
throw new RuntimeException("Variable hasn't been set: " + name);
|
|
return expression;
|
|
}
|
|
|
|
@Override
|
|
public boolean hasVariable(String name) {
|
|
return variables.containsKey(name);
|
|
}
|
|
}
|