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

Crafting GUI: Filter recipes by what can fit into the result (longest_side, volume, mass) #78384

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

Brambor
Copy link
Contributor

@Brambor Brambor commented Dec 6, 2024

Summary

Interface "Crafting GUI: Filter recipes by what can fit into the result (longest_side, volume, mass)"

Purpose of change

Describe the solution

image

  1. add filters L:, V:, M: to crafting GUI
  2. Parse user input by an existing parser for units. It is the same parser that is used for loading itypes from JSON.
  3. If an error is thrown on invalid input, the user is notified with a helpful message:
    • image
  4. Create a fake item, set its longest_side/volume/mass to specified in the filter.
  5. For each recipe try fitting the fake item into the recipe item.can_contain(fake_item).
  6. fix in item.cpp: units::mass_max * 1.0 resulted in -units::mass_max. Fixed by avoiding multiplying by 1.0.

Describe alternatives you've considered

... I wrote a detailed thing there, where the hell is it?

Testing

  • Use all the filters in crafting GUI, try all the suggested "Valid examples". Note: 2m is not valid 2meter is. Maybe not to be confused with minutes?
  • Try negative numbers. Like M: -250g.
    • Works for mass and longest_side - all recipes are shown.
    • Doesn't work for volume - none are shown. This is ok.

Additional context

@github-actions github-actions bot added Info / User Interface Game - player communication, menus, etc. Crafting / Construction / Recipes Includes: Uncrafting / Disassembling [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Dec 6, 2024
@db48x
Copy link
Contributor

db48x commented Dec 7, 2024

I like the idea. Can you add a comment documenting what the assert is checking for?

Also, why remove wildcards from an unrelated query type?

@Brambor
Copy link
Contributor Author

Brambor commented Dec 7, 2024

Can you add a comment documenting what the assert is checking for?

I went with a different approach and am finalizing it now. The assert will not be there.

Also, why remove wildcards from an unrelated query type?

I added that query type a while back and didn't know better. Now I know and I want to make it in line with the other filters.

It can be a separate PR, I aggregated it since it is close by.

@db48x
Copy link
Contributor

db48x commented Dec 7, 2024

Probably better to have a separate pull request for that then.

@github-actions github-actions bot added the [JSON] Changes (can be) made in JSON label Dec 8, 2024
@Brambor Brambor changed the title Filter items and recipes by what can fit into them Filter items and recipes by what can fit into them (longest_side, volume, mass) Dec 8, 2024
@Brambor
Copy link
Contributor Author

Brambor commented Dec 8, 2024

I updated to the new approach. I still need to do the inventory filter, which will have to be a bit different since I cannot throw that helpful error on every keystroke (the inventory filter is live).

@Brambor Brambor changed the title Filter items and recipes by what can fit into them (longest_side, volume, mass) Crafting GUI: Filter recipes by what can fit into the result (longest_side, volume, mass) Dec 8, 2024
@Brambor
Copy link
Contributor Author

Brambor commented Dec 8, 2024

I decided this is good to go. I want to look into AIM a bit more separately. There seems to be room for performance improvement in regards to filtering cache (caching the filter function).

@Brambor Brambor marked this pull request as ready for review December 8, 2024 23:05
@Brambor
Copy link
Contributor Author

Brambor commented Dec 8, 2024

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Dec 9, 2024
data/json/items/fake.json Outdated Show resolved Hide resolved
data/json/items/fake.json Outdated Show resolved Hide resolved
src/recipe_dictionary.cpp Show resolved Hide resolved
@Brambor Brambor force-pushed the filter-fits branch 2 times, most recently from 2173c38 to f650dd3 Compare December 9, 2024 10:02
Copy link
Contributor

github-actions bot commented Dec 9, 2024

Spell checker encountered unrecognized words in the in-game text added in this pull request. See below for details.

Click to expand
  • 450 ml

This alert is automatically generated. You can simply disregard if this is inaccurate, or (optionally) you can also add the new words to tools/spell_checker/dictionary.txt so they will not trigger an alert next time.

Hints for adding a new word to the dictionary
  • If the word is normally in all lowercase, such as the noun word or the verb does, add it in its lower-case form; if the word is a proper noun, such as the surname George, add it in its initial-caps form; if the word is an acronym or has special letter case, such as the acronym CDDA or the unit mW, add it by preserving the case of all the letters. A word in the dictionary will also match its initial-caps form (if the word is in all lowercase) and all-uppercase form, so a word should be added to the dictionary in its normal letter case even if used in a different letter case in a sentence.
  • For a word to be added to the dictionary, it should either be a real, properly-spelled modern American English word, a foreign loan word (including romanized foreign names), or a foreign or made-up word that is used consistently and commonly enough in the game. Intentional misspelling (including eye dialect) of a word should not be added unless it has become a common terminology in the game, because while someone may have a legitimate use for it, another person may spell it that way accidentally.

@github-actions github-actions bot removed BasicBuildPassed This PR builds correctly, label assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Dec 9, 2024
@github-actions github-actions bot added the json-styled JSON lint passed, label assigned by github actions label Dec 9, 2024
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Dec 10, 2024
@Brambor
Copy link
Contributor Author

Brambor commented Dec 10, 2024

Huh, didn't know a special name was requested:
image

It should have said so in the last error, when it asked me to make it a global variable!

image

Edit: And the next error. It should have told me where to put the string so that it is sorted!

@Night-Pryanik Night-Pryanik merged commit 5a97f71 into CleverRaven:master Dec 11, 2024
21 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Info / User Interface Game - player communication, menus, etc. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants