Skip to content

Commit 4ba4323

Browse files
committed
fix unit toggle
1 parent 347a858 commit 4ba4323

File tree

3 files changed

+8
-103
lines changed

3 files changed

+8
-103
lines changed

src/dsstats.maui/dsstats.builder/dsstats.builder.tests/BuildAreaTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ public sealed class BuildAreaTests
66
[TestMethod]
77
public void CanPlaceUnit()
88
{
9-
var buildArea = new BuildArea();
9+
var buildArea = new BuildArea(2);
1010
var result = buildArea.PlaceUnit("Zergling", new(90, 75));
1111
Assert.IsTrue(result);
1212
}
1313

1414
[TestMethod]
1515
public void CannotPlaceUnit()
1616
{
17-
var buildArea = new BuildArea();
17+
var buildArea = new BuildArea(1);
1818
var result = buildArea.PlaceUnit("Zergling", new(0, 0));
1919
Assert.IsFalse(result);
2020
}

src/dsstats.maui/dsstats.builder/dsstats.builder.tests/ScreenAreaTests.cs

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/dsstats.maui/dsstats.builder/dsstats.builder/Builds/CmdrBuild.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ public virtual List<InputEvent> GetBuildEvents(string unitName, RlPoint pos, Scr
3131
if (toggleEvent != null)
3232
{
3333
events.AddRange(toggleEvent);
34-
var otherToggleUnit = UnitMap.FirstOrDefault(f => f.Value.Key == buildOption.Key && f.Key != unitName);
35-
if (!string.IsNullOrEmpty(otherToggleUnit.Key))
34+
var otherToggleUnits = UnitMap.Where(f => f.Value.Key == buildOption.Key && f.Key != unitName);
35+
foreach (var otherUnit in otherToggleUnits)
3636
{
37-
activeUnits[otherToggleUnit.Key] = false;
37+
if (activeUnits.ContainsKey(otherUnit.Key))
38+
{
39+
activeUnits[otherUnit.Key] = false;
40+
}
3841
}
3942
activeUnits[unitName] = true;
4043
}

0 commit comments

Comments
 (0)