Improve auto crafting request input field
lucasser opened this issue ยท 5 comments
Describe your enhancement
Allow for math expressions (x+y), craft up to an amount in storage (=x), and use units (xK).
To do this, I added a folder to the query-parser called evaluator. It takes an input string, runs it through the lexer, interprets all unit multipliers (such as 1k->1000) and parser with ArithmeticMappings. Then the result is run through a loop which evaluates the equation.
If at any point there is a problem, it is returned as a thrown exception. The value of the exception corresponds to a translation entry, which will be the error shown to the user as a tooltip.
All this logic is controlled by the ExpressionAmountOperator which can be passed as the valueOperator to the abstract screen class. That operator also catches the exceptiona and returns the translation.
I was thinking that I can just use an existing expression evaluation library. It would be simpler than writing my own, and the result would be a lot more powerful.
Sounds like a good idea!
Can be tracked as part of #199
I think i should be able to write my own formatter which will first evaluate the expression, and then send the value to a decimal formatter
Keep in mind that we already have a query parser with a lexer and parser. It should be straightforward to add math expression evaluation to that.