mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 14:00:14 +00:00
constant returnable helper method
This commit is contained in:
1 parent
3594beb406
commit
fb505fe28b
2 files changed
+25
-16
No files matched your search
+24
@@ -1,5 +1,10 @@
|
|||||||
package com.dfsek.terra.addons.terrascript.api.lang;
|
package com.dfsek.terra.addons.terrascript.api.lang;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.terrascript.api.ImplementationArguments;
|
||||||
|
import com.dfsek.terra.addons.terrascript.api.Position;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface Returnable<T> extends Item<T> {
|
public interface Returnable<T> extends Item<T> {
|
||||||
ReturnType returnType();
|
ReturnType returnType();
|
||||||
|
|
||||||
@@ -16,4 +21,23 @@ public interface Returnable<T> extends Item<T> {
|
|||||||
return comparable;
|
return comparable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static <T> Returnable<T> constant(T value, ReturnType type, Position position) {
|
||||||
|
return new Returnable<T>() {
|
||||||
|
@Override
|
||||||
|
public ReturnType returnType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
-16
@@ -24,22 +24,7 @@ public class BlockFunctionBuilder implements FunctionBuilder<BlockFunction> {
|
|||||||
@Override
|
@Override
|
||||||
public BlockFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
|
public BlockFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
|
||||||
if(argumentList.size() < 4) throw new ParseException("Expected data", position);
|
if(argumentList.size() < 4) throw new ParseException("Expected data", position);
|
||||||
Returnable<Boolean> booleanReturnable = new Returnable<Boolean>() {
|
Returnable<Boolean> booleanReturnable = Returnable.constant(true, Returnable.ReturnType.BOOLEAN, position);
|
||||||
@Override
|
|
||||||
public ReturnType returnType() {
|
|
||||||
return ReturnType.BOOLEAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Position getPosition() {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if(argumentList.size() == 5) booleanReturnable = (Returnable<Boolean>) argumentList.get(4);
|
if(argumentList.size() == 5) booleanReturnable = (Returnable<Boolean>) argumentList.get(4);
|
||||||
if(argumentList.get(3).returnType() == Returnable.ReturnType.STRING && argumentList.get(3) instanceof ConstantExpression) {
|
if(argumentList.get(3).returnType() == Returnable.ReturnType.STRING && argumentList.get(3) instanceof ConstantExpression) {
|
||||||
return new BlockFunction.Constant((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(2), (ConstantExpression<String>) argumentList.get(3), booleanReturnable, main, position);
|
return new BlockFunction.Constant((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(2), (ConstantExpression<String>) argumentList.get(3), booleanReturnable, main, position);
|
||||||
|
|||||||
Reference in new issue
Block a user