Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve auto crafting request input field #834

Closed
lucasser opened this issue Feb 18, 2025 · 5 comments
Closed

Improve auto crafting request input field #834

lucasser opened this issue Feb 18, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@lucasser
Copy link
Contributor

lucasser commented Feb 18, 2025

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.

@lucasser lucasser added the enhancement New feature or request label Feb 18, 2025
@raoulvdberge
Copy link
Contributor

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

@lucasser
Copy link
Contributor Author

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

@raoulvdberge
Copy link
Contributor

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.

@lucasser
Copy link
Contributor Author

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.

@lucasser
Copy link
Contributor Author

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

lucasser added a commit to lucasser/refinedstorage2 that referenced this issue Feb 23, 2025

Verified

This commit was signed with the committer’s verified signature.
mlschroe Michael Schroeder
…e-number-input-fields
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants