-
Notifications
You must be signed in to change notification settings - Fork 309
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
feat(cmd_blueprint): add filtering for unbuildable blueprints #3861
Draft
salinecitrine
wants to merge
4
commits into
beyond-all-reason:master
Choose a base branch
from
salinecitrine:blueprint-unloaded-units
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5101a19
fix(test_runner): only run test files that end in .lua
salinecitrine e739acb
fix(cmd_blueprint): use VFS.LoadFile to read blueprints file
salinecitrine d524554
test(cmd_blueprint): update tests to reset blueprints better
salinecitrine ca01134
feat(cmd_blueprint): add filtering for unbuildable blueprints
salinecitrine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
luaui/Widgets/Tests/cmd_blueprint/test_cmd_blueprint_filter.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
local widgetName = "Blueprint" | ||
|
||
function skip() | ||
return Spring.GetGameFrame() <= 0 | ||
end | ||
|
||
function setup() | ||
assert(widgetHandler.knownWidgets[widgetName] ~= nil) | ||
|
||
Test.clearMap() | ||
|
||
initialWidgetActive = widgetHandler.knownWidgets[widgetName].active | ||
if initialWidgetActive then | ||
widgetHandler:DisableWidget(widgetName) | ||
end | ||
widgetHandler:EnableWidget(widgetName, true) | ||
|
||
initialCameraState = Spring.GetCameraState() | ||
|
||
Spring.SetCameraState({ | ||
mode = 5, | ||
}) | ||
end | ||
|
||
function cleanup() | ||
Test.clearMap() | ||
|
||
widgetHandler:DisableWidget(widgetName) | ||
if initialWidgetActive then | ||
widgetHandler:EnableWidget(widgetName, false) | ||
end | ||
Comment on lines
+28
to
+31
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. You can remove lines 28-31 here, the widget restoring will be done automatically by the test runner when you use |
||
|
||
Spring.SetCameraState(initialCameraState) | ||
end | ||
|
||
local delay = 5 | ||
function test() | ||
VFS.Include("luarules/configs/customcmds.h.lua") | ||
|
||
widget = widgetHandler:FindWidget(widgetName) | ||
assert(widget) | ||
|
||
mock_saveBlueprintsToFile = Test.mock(widget, "saveBlueprintsToFile") | ||
|
||
-- load test blueprints | ||
widget.BLUEPRINT_FILE_PATH = "LuaUI/Widgets/Tests/cmd_blueprint/test_cmd_blueprint_filter_blueprints.json" | ||
widget.loadBlueprintsFromFile() | ||
|
||
Test.clearMap() | ||
|
||
local builderUnitDefName = "armck" | ||
|
||
local myTeamID = Spring.GetMyTeamID() | ||
local x, z = Game.mapSizeX / 2, Game.mapSizeZ / 2 | ||
local y = Spring.GetGroundHeight(x, z) | ||
local facing = 1 | ||
|
||
local builderUnitID = SyncedRun(function(locals) | ||
return Spring.CreateUnit( | ||
locals.builderUnitDefName, | ||
locals.x, | ||
locals.y, | ||
locals.z, | ||
locals.facing, | ||
locals.myTeamID | ||
) | ||
end) | ||
|
||
Spring.SelectUnit(builderUnitID) | ||
|
||
Test.waitFrames(delay) | ||
|
||
Spring.SetActiveCommand( | ||
Spring.GetCmdDescIndex(CMD_BLUEPRINT_PLACE), | ||
1, | ||
true, | ||
false, | ||
false, | ||
false, | ||
false, | ||
false | ||
) | ||
|
||
Test.waitFrames(delay) | ||
|
||
assert(widget.blueprintPlacementActive) | ||
|
||
-- make sure we skipped the blueprint #1, which is invalid | ||
assert(widget.selectedBlueprintIndex == 2, widget.selectedBlueprintIndex) | ||
|
||
-- make sure we skipped blueprint #3, which is cortex and unbuildable by armada | ||
widget.handleBlueprintNextAction() | ||
assert(widget.selectedBlueprintIndex == 4, widget.selectedBlueprintIndex) | ||
|
||
-- make sure we rotate to the next valid blueprint, #2 | ||
widget.handleBlueprintDeleteAction() | ||
assert(widget.selectedBlueprintIndex == 2, widget.selectedBlueprintIndex) | ||
|
||
-- reset blueprints | ||
widget.loadBlueprintsFromFile() | ||
|
||
-- make sure we rotate to the next valid blueprint, #3 (which shifted from #4) | ||
widget.handleBlueprintDeleteAction() | ||
assert(widget.selectedBlueprintIndex == 3, widget.selectedBlueprintIndex) | ||
|
||
-- make sure we rotate to the next valid blueprint, nil | ||
widget.handleBlueprintDeleteAction() | ||
assert(widget.selectedBlueprintIndex == nil, widget.selectedBlueprintIndex) | ||
end |
61 changes: 61 additions & 0 deletions
61
luaui/Widgets/Tests/cmd_blueprint/test_cmd_blueprint_filter_blueprints.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"savedBlueprints": [ | ||
{ | ||
"ordered": true, | ||
"name": "", | ||
"spacing": 0, | ||
"facing": 0, | ||
"units": [ | ||
{ | ||
"unitName": "INVALID", | ||
"facing": 0, | ||
"position": [0, 0, 0] | ||
} | ||
] | ||
}, | ||
{ | ||
"ordered": true, | ||
"name": "", | ||
"spacing": 0, | ||
"facing": 0, | ||
"units": [ | ||
{ | ||
"unitName": "armwin", | ||
"facing": 0, | ||
"position": [0, 0, 0] | ||
} | ||
] | ||
}, | ||
{ | ||
"ordered": true, | ||
"name": "", | ||
"spacing": 0, | ||
"facing": 0, | ||
"units": [ | ||
{ | ||
"unitName": "corwin", | ||
"facing": 0, | ||
"position": [0, 0, 0] | ||
} | ||
] | ||
}, | ||
{ | ||
"ordered": true, | ||
"name": "", | ||
"spacing": 0, | ||
"facing": 0, | ||
"units": [ | ||
{ | ||
"unitName": "armwin", | ||
"facing": 0, | ||
"position": [-24, 0, 0] | ||
}, | ||
{ | ||
"unitName": "corwin", | ||
"facing": 0, | ||
"position": [24, 0, 0] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You can now replace this (lines 8, and 12 to 16) by
Test.prepareWidget(widgetName)
. Also need to rebase or merge master to fix the same lines on test_cmd_blueprint_line.lua and test_cmd_blueprint_single.lua, they're already adapted in master. Check how it looks in master.