Refined Storage

Refined Storage

115M Downloads

Improve auto crafting request input field

lucasser opened this issue ยท 5 comments

commented

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.

commented

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.

commented

Sounds like a good idea!
Can be tracked as part of #199

commented

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

commented

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.

commented

I finished writing this, so whenever you are ready, tell me to submit the PR.