Factorio-Access / FactorioAccess

An accessibility mod for the video game Factorio, making the game accessible to the blind and visually impaired.
Other
14 stars 8 forks source link

Add support for reading the consumption stats, and clean up the code while there #170

Closed ahicks92 closed 2 weeks ago

ahicks92 commented 3 weeks ago

We introduce fa_utils.spacecat, which takes any number of stringifiable things and converts them into a space-separated list. This is more efficient and easier to read than .. (if Lua knows ahead of time it may avoid intermediate string building), and can get rid of the hard to follow result variables. Then we use this to easily tweak wording in selection_item_production_stats_info, to be more brief and to add the consumption (output in mod language) stats.

Note a couple things. First the output code and input code are the same by one boolean, thus a quick local closure. After that and the wording tweak it then becomes evident that we need internal_name only in two spots, so we get to kill that variable. In context we have enough to not use super long variable names, so we get to also simplify some of those.

I cannot for the life of me figure out how to reach the second of the two recipe fluid branches. I hand tested all the other cases. Because we only check hand, inventory, and crafting menu, there's no way to get my hand on a fluid recipe which could trigger reading the second index because the first product must be either an item or a fluid and we check for both--except I think that's supposed to be else if as well too. Unless recipes can output something else, maybe?

ahicks92 commented 2 weeks ago

To repost from Discord, the oddness about recipes is that we only have the empty barrel recipes in vanilla, the part you care about is the fluid, and the case for mods is unclear. I have generalized it slightly: we take the first fluid over the first item, otherwise the first item. This now works if there's 3 items then a fluid, or whatever. In vanilla that's the same; in mods that's the same decision. In the long run I suspect that we can't do the right thing without a UI; I doubt that it's always the right decision, e.g.. recipes which produce an item and a fluid byproduct which gets in the way. I have yet to play Seablock but if I cannot find one there, I will be astonished Ultimately to put it another way, it's the same problem as iron ore: for things not in the crafting menu you can't target it reliably unless it is in hand, and fluids cannot be in hand.

LevFendi commented 2 weeks ago

Thank you for this addition. The fluid selection problem will indeed be fixed in the future when this feature has a full menu, which is issue #136. I will be merging this feature as it is. Meanwhile, the extensive usage of the space concat function will depend on the outcome of issue #52. The discussions about that can continue on that page.