Fix usage of MapGeneratorMultiChoiceOption.Default

When this switched to an ImmutableArray, this expression has to be updated as the struct is not nullable. It supports an overloaded equals (==) but not a null-conditional (?.) operator. This expression was rewritten incorrectly and failed to use the first valid choice as a fallback in all cases. Update the code to do this.

Fixes regression from 649e7e8c28.
This commit is contained in:
RoosterDragon
2025-12-22 17:57:38 +00:00
committed by Gustas Kažukauskas
parent 4aec67c0c6
commit 3ea5b08848
3 changed files with 15 additions and 3 deletions

View File

@@ -127,7 +127,11 @@ namespace OpenRA.Mods.Common.MapGenerator
if (validChoices.Contains(value))
return Choices[value].Settings;
var fallback = Default != null ? Default.FirstOrDefault(validChoices.Contains) : validChoices.FirstOrDefault();
string fallback = null;
if (Default != null)
fallback = Default.FirstOrDefault(validChoices.Contains);
fallback ??= validChoices.FirstOrDefault();
return fallback != null ? Choices[fallback].Settings : [];
}

View File

@@ -184,7 +184,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
var validChoices = mo.ValidChoices(world.Map.Rules.TerrainInfo, playerCount);
if (!validChoices.Contains(mo.Value))
mo.Value = mo.Default != null ? mo.Default.FirstOrDefault(validChoices.Contains) : validChoices.FirstOrDefault();
{
if (mo.Default != null)
mo.Value = mo.Default.FirstOrDefault(validChoices.Contains);
mo.Value ??= validChoices.FirstOrDefault();
}
if (mo.Value != null && mo.Label != null && validChoices.Count > 0)
{

View File

@@ -348,7 +348,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
var validChoices = mo.ValidChoices(selectedTerrain, playerCount);
if (!validChoices.Contains(mo.Value))
mo.Value = mo.Default != null ? mo.Default.FirstOrDefault(validChoices.Contains) : validChoices.FirstOrDefault();
{
if (mo.Default != null)
mo.Value = mo.Default.FirstOrDefault(validChoices.Contains);
mo.Value ??= validChoices.FirstOrDefault();
}
if (mo.Label != null && validChoices.Count > 0)
{