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

Investigate the question mark when hovering over a recipe #43

Closed
shpaass opened this issue Feb 18, 2024 · 12 comments · Fixed by #329 · May be fixed by #63
Closed

Investigate the question mark when hovering over a recipe #43

shpaass opened this issue Feb 18, 2024 · 12 comments · Fixed by #329 · May be fixed by #63

Comments

@shpaass
Copy link
Owner

shpaass commented Feb 18, 2024

When choosing a production recipe, when hovering over some recipes, the first line sometimes is ? instead of A recipe to create something:
image
image

It would be useful to understand why exactly the question mark is shown because it is shown quite often, and it can bring confusion to the end user.

A mod-list to replicate the exact same situation would be quite large, but the bulk of the mods is Pyanodons Alternative Energy and all its mandatory dependencies.

@Dorus
Copy link
Collaborator

Dorus commented Feb 19, 2024

The ? stems from FactorioDataDeserializer line 568.

It arrives on line 565 with a luaTable containing a localised_descripption of 3 elements, an ?, and 2 other luaTable

afbeelding

Moving into the Localize(table) function, it decides to call Localize("?", table) that in turns calls FactorioLocalization.Localize("?") that returns null. Then on line 491 it calls table.ArrayElements(table), which returns just the "?". So basically it's just parsing what's in the data. I'm not sure how it should have parsed this different.

If i had to guess where this dataset comes from:
afbeelding

It seems pycoalprocessing_2.1.22\prototypes\functions\functions.lua:1302 adds a entity-description like this:

-- adds some text to a prototype's localised description
function overrides.add_to_description(type, prototype, localised_string)
	if prototype.localised_description and prototype.localised_description ~= '' then
		prototype.localised_description = {'', prototype.localised_description, '\n', localised_string}
	else
		if type == 'item' and prototype.place_result then
			for _, machine in pairs(data.raw) do
				machine = machine[prototype.place_result]
				if machine and machine.localised_description then
					prototype.localised_description = {
						'?',
						{'', machine.localised_description, '\n', localised_string},
						localised_string
					}
					return
				end
			end

			prototype.localised_description = {
				'?',
				{'', {'entity-description.' .. prototype.place_result}, '\n', localised_string},
				{'', {type .. '-description.' .. prototype.name}, '\n', localised_string},
				localised_string
			}
		else
			prototype.localised_description = {'?', {'', {type .. '-description.' .. prototype.name}, '\n', localised_string}, localised_string}
		end
	end
end

After going trough all this code, i'm still clueless what's going on here lol.

@shpaass shpaass removed the backlog label Feb 21, 2024
@SWeini
Copy link
Collaborator

SWeini commented Feb 21, 2024

that's a new feature introduced in 1.1.73, officially called "fallback group"

for more information see https://forums.factorio.com/viewtopic.php?f=3&t=104293 and https://forums.factorio.com/71553

@shpaass
Copy link
Owner Author

shpaass commented Feb 21, 2024

Thank you for the info!
Practically, do we want to hide this question mark, or do you have other ideas about how to handle it?

@craig-johnston
Copy link

I was playing around to see if I could fix this. This snippet helps some cases e.g. Bonemeal (the item) is ? in main but with the following fix displays the right info. But it then causes items where there is no localisation (e.g. the diesel recipe) to show the localisation key: "recipe-description.diesel"

        private void Localize(object obj)
        {
            if (obj is LuaTable table)
            {
                if (!table.Get(1, out string key))
                    return;

                if (key == "?")
                    Localize(table[2]);
                else 
                    Localize(key, table);
            }
            else localeBuilder.Append(obj);
        }

What's the actual desired behaviour if a localisation is missing?

  • Show ?
  • Show the key (e.g. "recipe-description.diesel")
  • Show nothing

@craig-johnston
Copy link

If we follow what Factorio seems to do, it'd simply fail the first localisation lookup and return empty string for that specific item.
In this specific case ("recipe-description.diesel") that would mean there's no description for the recipe and the next part of the localisation occurs (the "affected by productivity" string is put in the description).
image

@craig-johnston
Copy link

#63 might be useful as a starting point for fixing this properly.

@shpaass
Copy link
Owner Author

shpaass commented Feb 28, 2024

What's the actual desired behaviour if a localisation is missing?

I think it's either to show nothing or the key. There are arguments for both of the approaches, so it's up to you.

@Dorus
Copy link
Collaborator

Dorus commented Feb 28, 2024

Wouldn't you default to english then? If that's also missing i guess the above.

@shpaass
Copy link
Owner Author

shpaass commented Feb 28, 2024

Wouldn't you default to english then?

From what I see, YAFC already uses English everywhere, no matter what language your system or the game is using.

@Dorus
Copy link
Collaborator

Dorus commented Feb 28, 2024

afbeelding
Not for me, it has the same parts dutch as Factorio has ingame.

@veger
Copy link
Collaborator

veger commented Feb 28, 2024

The in-game items are localized (by the mods), but the whole application itself uses (hard-coded) English. Open some files and you see all kind of strings in the code to be rendered in the UI. (Unles SDL applies some magic to match them against localisation files to translate?)

@craig-johnston
Copy link

Here are the before and after for what's currently implemented in #63
It tries to match what's what Factorio does as closely as possible.

Before:
image
image
image

After:
image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants