Class ExpressionEditor
java.lang.Object
org.cyclops.integrateddynamics.core.logicprogrammer.ExpressionEditor
The editing state of an expression in the logic programmer,
together with the edit actions that are applied identically on client and server.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intThe maximum number of nodes in an expression that is set as a whole. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.minecraft.nbt.CompoundTagstatic net.minecraft.nbt.CompoundTagactionClear(int[] path, int slot) static net.minecraft.nbt.CompoundTagactionConst(ValueDeseralizationContext context, int[] path, int slot, IValue value) static net.minecraft.nbt.CompoundTagactionNavigate(int[] path) static net.minecraft.nbt.CompoundTagactionOperator(int[] path, int slot, IOperator operator) static net.minecraft.nbt.CompoundTagactionParam(int[] path, int slot, int index) static net.minecraft.nbt.CompoundTagactionParamType(int index, IValueType<?> type) static net.minecraft.nbt.CompoundTagactionRemoveParam(int index) static net.minecraft.nbt.CompoundTagactionRenameParam(int index, String name) static net.minecraft.nbt.CompoundTagactionSet(ValueDeseralizationContext context, Expression expression, String text) An action that replaces the whole expression, which can have another root operator.intstatic StringaddParameterToText(String text, ExpressionParser.Context context) Add a parameter to the text of an expression, such as text that is still being typed.apply(ValueDeseralizationContext context, net.minecraft.nbt.CompoundTag action) Apply the given action.protected ExpressionEditor.ActionResultapplyUnsafe(ValueDeseralizationContext context, net.minecraft.nbt.CompoundTag action) check()getChild(int slot) int[]IValueType<?> getExpectedType(int slot) Map<Integer, IValueType<?>> static StringgetNewParameterName(List<String> names) getOperatorsAlongPath(int[] path) static List<IValueType<?>> static ExpressionParser.ContextgetParserContext(ValueDeseralizationContext values, IntFunction<IValueType<?>> refTypes, Function<String, it.unimi.dsi.fastutil.ints.IntList> labelIds) IValueType<?> getRefType(int variableId) Map<Integer, IValueType<?>> intgetText()booleanhasRefType(int variableId) voidFor references of unknown type, take the type of the operator input they are in when that type is not a category.static booleanisEditable(Expression expression) static booleanisEditable(IOperator operator) static booleanisParameterType(IValueType<?> type) static booleanisPickedAsValue(IValueType<?> expectedType, IOperator operator, boolean forceValue) static booleanisTextEditable(IValueType<?> type) booleannavigate(int[] path) static Expressionparse(String text, ExpressionParser.Context context) Parse the text of an expression that can be edited in the logic programmer.static IValueparseValue(IValueType<?> expectedType, String text) Parse the given text to a value for the given expected type.static ExpressionreadSetAction(ValueDeseralizationContext context, net.minecraft.nbt.CompoundTag action) static StringreadSetActionText(net.minecraft.nbt.CompoundTag action) voidremoveParameter(int index) voidrenameParameter(int index, String name) static StringsanitizeParameterName(String name) voidsetChild(int slot, ExpressionNode node) Set a child of the current node.voidsetExpression(Expression expression) voidsetExpression(Expression expression, String text) voidsetParameterType(int index, IValueType<?> type) voidsetRefType(int variableId, IValueType<?> type)
-
Field Details
-
ACTION_CONST
- See Also:
-
ACTION_OPERATOR
- See Also:
-
ACTION_PARAM
- See Also:
-
ACTION_CLEAR
- See Also:
-
ACTION_NAVIGATE
- See Also:
-
ACTION_ADD_PARAM
- See Also:
-
ACTION_REMOVE_PARAM
- See Also:
-
ACTION_RENAME_PARAM
- See Also:
-
ACTION_PARAM_TYPE
- See Also:
-
ACTION_SET
- See Also:
-
MAX_NODES
public static final int MAX_NODESThe maximum number of nodes in an expression that is set as a whole.- See Also:
-
-
Constructor Details
-
ExpressionEditor
-
-
Method Details
-
getExpression
-
getText
- Returns:
- The text the expression was typed as, or null if it is printed. It is only shown while it still reads as the expression.
-
getKnownRefTypes
- Returns:
- All known types of referenced variables, also of variables that are no longer referenced.
-
setExpression
-
setExpression
- Parameters:
expression- The expression.text- The text it was typed as, or null if it is printed.
-
getEditPath
public int[] getEditPath() -
getCurrentNode
- Returns:
- The operator node that is currently being edited.
-
getCurrentOperator
-
getChild
-
getSlotCount
public int getSlotCount() -
getExpectedType
- Parameters:
slot- A slot of the current node.- Returns:
- The input type of the current operator at the given slot.
-
setRefType
-
hasRefType
public boolean hasRefType(int variableId) -
getRefType
-
getRefTypes
- Returns:
- The known types of the variables referenced in the expression.
-
inferMissingRefTypes
public void inferMissingRefTypes()For references of unknown type, take the type of the operator input they are in when that type is not a category. This holds for cards that were written without errors. -
check
- Returns:
- The type checking result of the current expression, cached until the next change.
-
getOperatorsAlongPath
-
setChild
Set a child of the current node.- Parameters:
slot- The slot.node- The new child.
-
addParameter
public int addParameter() -
getNewParameterName
-
addParameterToText
Add a parameter to the text of an expression, such as text that is still being typed.- Parameters:
text- The text.context- What the parser needs to know about the world.- Returns:
- The text with a new parameter after its parameters, or in front of it if it has none.
-
removeParameter
public void removeParameter(int index) -
renameParameter
-
setParameterType
-
isPickedAsValue
public static boolean isPickedAsValue(IValueType<?> expectedType, IOperator operator, boolean forceValue) - Parameters:
expectedType- The type of the slot the operator is picked for.operator- The picked operator.forceValue- If the player asked to insert the operator as a value.- Returns:
- If the operator is inserted as an operator value instead of as a nested call.
-
isParameterType
- Parameters:
type- A value type.- Returns:
- If parameters can have this type: Any, Number, or any registered type that is not a category, also of add-ons.
-
getParameterTypes
- Returns:
- The types parameters can have, in cycling order: Any and Number, then the types in the order of the logic programmer, then those without an element in it by name.
-
isEditable
- Parameters:
operator- An operator.- Returns:
- If the operator can be edited in the logic programmer, which needs a slot for each input.
-
isEditable
- Parameters:
expression- An expression.- Returns:
- If the expression can be edited in the logic programmer.
-
getParserContext
public static ExpressionParser.Context getParserContext(ValueDeseralizationContext values, IntFunction<IValueType<?>> refTypes, Function<String, it.unimi.dsi.fastutil.ints.IntList> labelIds) - Parameters:
values- For deserializing values that are written with their type.refTypes- Resolves the type of a variable id, may return null when unknown.labelIds- Resolves the ids of the variables with a label.- Returns:
- The context for parsing expressions that can be edited in the logic programmer.
-
parse
public static Expression parse(String text, ExpressionParser.Context context) throws ExpressionParseException Parse the text of an expression that can be edited in the logic programmer.- Parameters:
text- The text.context- The context, seegetParserContext(ValueDeseralizationContext, IntFunction, Function).- Returns:
- The expression.
- Throws:
ExpressionParseException- If the text is not a valid expression, or one that is too large to edit.
-
sanitizeParameterName
-
actionConst
public static net.minecraft.nbt.CompoundTag actionConst(ValueDeseralizationContext context, int[] path, int slot, IValue value) -
actionOperator
public static net.minecraft.nbt.CompoundTag actionOperator(int[] path, int slot, IOperator operator) -
actionParam
public static net.minecraft.nbt.CompoundTag actionParam(int[] path, int slot, int index) -
actionClear
public static net.minecraft.nbt.CompoundTag actionClear(int[] path, int slot) -
actionAddParam
public static net.minecraft.nbt.CompoundTag actionAddParam() -
actionRemoveParam
public static net.minecraft.nbt.CompoundTag actionRemoveParam(int index) -
actionRenameParam
-
actionSet
public static net.minecraft.nbt.CompoundTag actionSet(ValueDeseralizationContext context, Expression expression, @Nullable String text) An action that replaces the whole expression, which can have another root operator.- Parameters:
context- The serialization context.expression- The new expression.text- The text it was typed as, to show it as typed, or null to print it.- Returns:
- The action.
-
readSetActionText
- Parameters:
action- A set action.- Returns:
- The text its expression was typed as, or null if there is none or it is too long. It is not checked against the expression, as it is only shown while it reads as the expression.
-
readSetAction
@Nullable public static Expression readSetAction(ValueDeseralizationContext context, net.minecraft.nbt.CompoundTag action) - Parameters:
context- The deserialization context.action- A set action.- Returns:
- Its expression, or null if the action is malformed or the expression can not be edited.
-
actionParamType
-
apply
public ExpressionEditor.ActionResult apply(ValueDeseralizationContext context, net.minecraft.nbt.CompoundTag action) Apply the given action. Actions that edit a slot are only accepted for the node that is currently being edited.- Parameters:
context- The deserialization context.action- The action.- Returns:
- The result.
-
applyUnsafe
protected ExpressionEditor.ActionResult applyUnsafe(ValueDeseralizationContext context, net.minecraft.nbt.CompoundTag action) -
parseValue
Parse the given text to a value for the given expected type. Numbers and booleans are read as in the text of an expression, such as5L, and otherwise the text is read as the element of the type in the logic programmer reads it.- Parameters:
expectedType- The expected type, possibly a category.text- The text.- Returns:
- The parsed value, or null if it could not be parsed.
-
isTextEditable
- Parameters:
type- A value type.- Returns:
- If constants of this type can be entered as text: those whose element in the logic programmer is text or a checkbox, and the categories of numbers, booleans or strings.
-