From 0fb5853b7a828dab613b262bf78f34e2b80e5703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 10 Sep 2022 21:36:05 +0200 Subject: [PATCH] Fallback to normal difficulty when none is set. --- OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs | 12 ++++++++++++ mods/cnc/scripts/campaign.lua | 2 +- mods/d2k/scripts/campaign.lua | 2 +- mods/ra/scripts/campaign.lua | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs index 0b94d2fae0..0871a94c50 100644 --- a/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/MapGlobal.cs @@ -120,6 +120,18 @@ namespace OpenRA.Mods.Common.Scripting return option.Value; } + [Desc("Returns the value of a `ScriptLobbyDropdown` selected in the game lobby or fallback to a default value.")] + public LuaValue LobbyOptionOrDefault(string id, string fallback) + { + var option = Context.World.WorldActor.TraitsImplementing() + .FirstOrDefault(sld => sld.Info.ID == id); + + if (option == null) + return fallback; + + return option.Value; + } + [Desc("Returns a table of all the actors that were specified in the map file.")] public Actor[] NamedActors => sma.Actors.Values.ToArray(); diff --git a/mods/cnc/scripts/campaign.lua b/mods/cnc/scripts/campaign.lua index f70ae4deb8..760b078af4 100644 --- a/mods/cnc/scripts/campaign.lua +++ b/mods/cnc/scripts/campaign.lua @@ -7,7 +7,7 @@ information, see COPYING. ]] -Difficulty = Map.LobbyOption("difficulty") +Difficulty = Map.LobbyOptionOrDefault("difficulty", "normal") InitObjectives = function(player) Trigger.OnObjectiveCompleted(player, function(p, id) diff --git a/mods/d2k/scripts/campaign.lua b/mods/d2k/scripts/campaign.lua index e62442abe3..e190873c7f 100644 --- a/mods/d2k/scripts/campaign.lua +++ b/mods/d2k/scripts/campaign.lua @@ -7,7 +7,7 @@ information, see COPYING. ]] -Difficulty = Map.LobbyOption("difficulty") +Difficulty = Map.LobbyOptionOrDefault("difficulty", "normal") InitObjectives = function(player) Trigger.OnObjectiveCompleted(player, function(p, id) diff --git a/mods/ra/scripts/campaign.lua b/mods/ra/scripts/campaign.lua index 54678698ae..a5a7f1785f 100644 --- a/mods/ra/scripts/campaign.lua +++ b/mods/ra/scripts/campaign.lua @@ -7,7 +7,7 @@ information, see COPYING. ]] -Difficulty = Map.LobbyOption("difficulty") +Difficulty = Map.LobbyOptionOrDefault("difficulty", "normal") InitObjectives = function(player) Trigger.OnObjectiveCompleted(player, function(p, id)