From 3dff3a99ca85e5e137257ec27e7c03ee2aa13e2c Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:04:46 -0800 Subject: [PATCH] Fix map-specific options in lobby not appearing (#6562) --- changelog/snippets/features.6557.md | 2 +- changelog/snippets/other.6495.md | 2 +- lua/ui/maputil.lua | 18 +++++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/changelog/snippets/features.6557.md b/changelog/snippets/features.6557.md index a62cf8c6d1..364b9a9878 100644 --- a/changelog/snippets/features.6557.md +++ b/changelog/snippets/features.6557.md @@ -1 +1 @@ -- (#6557) Siloes without engineering suites will not cancel missile construction when issued a hard-stop order (siloes will pause construction instead). +- (#6557) Siloes without engineering suites will not cancel missile construction when issued a hard-stop order (siloes will pause construction instead). diff --git a/changelog/snippets/other.6495.md b/changelog/snippets/other.6495.md index b961de38cc..57682060e0 100644 --- a/changelog/snippets/other.6495.md +++ b/changelog/snippets/other.6495.md @@ -1,3 +1,3 @@ -- (#6495) Refactor the map utilities module +- (#6495, #6562) Refactor the map utilities module Chunks up some larger functions into smaller functions to allow them to be re-used in other modules. diff --git a/lua/ui/maputil.lua b/lua/ui/maputil.lua index b7da6605fc..f2c9c92b94 100644 --- a/lua/ui/maputil.lua +++ b/lua/ui/maputil.lua @@ -132,19 +132,22 @@ ---@field PlayableAreaHeight number Syncs when the playable area changes ---@field PlayableRect { [1]: number, [2]: number, [3]: number, [4]: number } Coordinates `{x0, y0, x1, y1}` of the playable area Rectangle. Syncs when the playable area changes. +-- A scenario file path is typically like `/maps/scmp_001/scmp_001_scenario.lua` + --- Given the path to a scenario info file, returns a path with the `_scenario.lua` bit removed. ---@param pathToScenarioInfo any ---@return string -local function GetPathToFolder(pathToScenarioInfo) +local function GetPathToScenario(pathToScenarioInfo) return string.sub(pathToScenarioInfo, 1, string.len(pathToScenarioInfo) - string.len("scenario.lua")) end --- Given the path to a scenario info file, returns the path to the folder it resides in. ---@param pathToScenarioInfo any ---@return string -local function GetPathToScenario(pathToScenarioInfo) +local function GetPathToFolder(pathToScenarioInfo) local splits = StringSplit(pathToScenarioInfo, "/") - return string.sub(pathToScenarioInfo, 1, string.len(pathToScenarioInfo) - string.len(splits[table.getn(splits)])) + -- Remove the length of the last token (filename), and the slash character before it. + return string.sub(pathToScenarioInfo, 1, string.len(pathToScenarioInfo) - string.len(splits[table.getn(splits)]) - 1) end --- Given the path to a scenario info file, returns the path to the scenario options file. The reference to this file is not stored in the _scenario.lua file. @@ -260,14 +263,15 @@ function LoadScenario(pathToScenarioInfo) end -- optionally, add in the options - local ok, msg, scenarioOptions = pcall(LoadScenarioOptionsFile, GetPathToScenarioOptions(pathToScenarioInfo)) --[[@as UIScenarioOptionsFile | nil]] - if scenarioOptions then + local ok, scenarioOptions = pcall(LoadScenarioOptionsFile, GetPathToScenarioOptions(pathToScenarioInfo)) --[[@as UIScenarioOptionsFile | nil]] + if ok and scenarioOptions then scenarioInfo.options = scenarioOptions end -- optionally, add in briefing data flag - local ok, msg, scenarioStrings = pcall(LoadScenarioStringsFile, GetPathToScenarioStrings(pathToScenarioInfo)) --[[@as UIScenarioStringsFile | nil]] - if scenarioStrings then + local scenarioStrings + ok, scenarioStrings = pcall(LoadScenarioStringsFile, GetPathToScenarioStrings(pathToScenarioInfo)) --[[@as UIScenarioStringsFile | nil]] + if ok and scenarioStrings then if scenarioStrings.BriefingData then scenarioInfo.hasBriefing = true end