Skip to content

Commit

Permalink
Fix map-specific options in lobby not appearing (#6562)
Browse files Browse the repository at this point in the history
  • Loading branch information
lL1l1 authored Nov 29, 2024
1 parent 302ec55 commit 3dff3a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion changelog/snippets/features.6557.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion changelog/snippets/other.6495.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 11 additions & 7 deletions lua/ui/maputil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3dff3a9

Please sign in to comment.