-
Notifications
You must be signed in to change notification settings - Fork 261
Improve wreckage extraction for map preview #7269
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||
| - Improved wreckae detection for lobby map preview. (#7269) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,30 +155,19 @@ ResourceMapPreview = ClassUI(Group) { | |
| -- Add the wreckage, if activated. (done first so the important things appear on top) | ||
| local wreckagemarkers = {} | ||
| if enableWreckage then | ||
| local armies = mapdata.Scenario.Armies | ||
|
|
||
| for _, army in armies do | ||
| -- This is so spectacularly brittle it's magnificent. | ||
| if army.Units and army.Units.Units and army.Units.Units.WRECKAGE and army.Units.Units.WRECKAGE.Units then | ||
| for k, v in army.Units.Units.WRECKAGE.Units do | ||
| -- Some maps have extra entities in the Units list, representing groups. | ||
| -- Very annoying, so let's check for the fields we care about. | ||
| if v.Position then | ||
| local marker = self.wreckageIconPool:Get() | ||
| table.insert(wreckagemarkers, marker) | ||
| if scenarioInfo.hidePreviewMarkers then | ||
| marker:Hide() | ||
| else | ||
| marker:Show() | ||
| end | ||
|
|
||
| -- Yes, these ones have a capital Position, but the others have a lowercase. | ||
| LayoutHelpers.AtLeftTopIn(marker, self.mapPreview, | ||
| xOffset + (v.Position[1] / mWidth) * (self.size - 2) * xFactor, | ||
| yOffset + (v.Position[3] / mHeight) * (self.size - 2) * yFactor) | ||
| end | ||
| end | ||
| for _, pos in MapUtil.GetWreckagePositions(mapdata.Scenario) do | ||
| local marker = self.wreckageIconPool:Get() | ||
| table.insert(wreckagemarkers, marker) | ||
| if scenarioInfo.hidePreviewMarkers then | ||
| marker:Hide() | ||
| else | ||
| marker:Show() | ||
| end | ||
|
|
||
| -- Yes, these ones have a capital Position, but the others have a lowercase. | ||
| LayoutHelpers.AtLeftTopIn(marker, self.mapPreview, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Use the fluent layouter for the wreckage marker. Replace As per coding guidelines, use the fluent layouter for UI layout and always call 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| xOffset + (pos[1] / mWidth) * (self.size - 2) * xFactor, | ||
| yOffset + (pos[3] / mHeight) * (self.size - 2) * yFactor) | ||
| end | ||
| end | ||
| self.wreckagemarkers = wreckagemarkers | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -586,4 +586,58 @@ function GetStartPositionsFromScenario(scenarioInfo, scenarioSave) | |
| return output | ||
| end | ||
|
|
||
| ---Returns all units' (leaf nodes) positions under the specified group. | ||
| ---@param tblNode? table | ||
| ---@param positions? Vector[] | ||
| ---@return Vector[] | ||
| local function extractUnitPositions(tblNode, positions) | ||
| positions = positions or {} | ||
| if not tblNode then return positions end | ||
|
|
||
| for strName, tblData in pairs(tblNode.Units) do | ||
| if tblData.type == 'GROUP' then | ||
| positions = extractUnitPositions(tblData, positions) | ||
| else | ||
| table.insert(positions, tblData.Position) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- scoped repository rules and learnings ---'
head -5 /tmp/coderabbit-repo-knowledge/faforever-fa-d6ccff43/*/*.md 2>/dev/null || true
printf '%s\n' '--- relevant diff ---'
git diff -- lua/ui/maputil.lua lua/ui/resmappreview.lua
printf '%s\n' '--- maputil structure and target context ---'
ast-grep outline lua/ui/maputil.lua
sed -n '550,630p' lua/ui/maputil.lua
printf '%s\n' '--- preview consumers ---'
rg -n -C 8 'GetWreckagePositions|SetScenario|pos\[1\]|pos\[3\]' lua/ui/resmappreview.lua lua/ui
printf '%s\n' '--- direct position producers/filters ---'
rg -n -C 5 'Position|extractUnitPositions|GROUP|Wreckage' lua/ui/maputil.luaRepository: FAForever/fa Length of output: 25685 Preserve the position validity filter. If a non- 🤖 Prompt for AI Agents |
||
| end | ||
| end | ||
|
|
||
| return positions | ||
| end | ||
|
|
||
| ---Extracts wreckage positions from all groups that contain `"wreck"` in their name. | ||
| ---@param tblNode? table | ||
| ---@param positions? Vector[] | ||
| ---@return Vector[] | ||
| local function extractPositionsFromWreckageGroups(tblNode, positions) | ||
| positions = positions or {} | ||
| if not tblNode then return positions end | ||
|
|
||
| for strName, tblData in pairs(tblNode.Units) do | ||
| if tblData.type == 'GROUP' then | ||
| if string.find(string.lower(strName), "wreck") then | ||
| positions = extractUnitPositions(tblData, positions) | ||
| else | ||
| positions = extractPositionsFromWreckageGroups(tblData, positions) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return positions | ||
| end | ||
|
|
||
| ---Returns all unit wreckage positions. Extracted from army groups that contain `"wreck"` in their name. | ||
| ---@param scenario UIScenarioSaveFile | ||
| ---@return Vector[] | ||
| function GetWreckagePositions(scenario) | ||
| ---@type Vector[] | ||
| local positions = {} | ||
|
|
||
| for _, army in pairs(scenario.Armies) do | ||
| positions = extractPositionsFromWreckageGroups(army.Units, positions) | ||
| end | ||
|
|
||
| return positions | ||
| end | ||
|
|
||
| --#endregion | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the changelog spelling.
Line 1 spells
wreckageaswreckae. Replace it withwreckage.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~1-~1: Ensure spelling is correct
Context: - Improved wreckae detection for lobby map preview. (
#7269...(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🤖 Prompt for AI Agents
Source: Linters/SAST tools