Change some Exts.MakeArray calls into Enumerable.Range.

Avoid creating some arrays where sequences will suffice.
This commit is contained in:
RoosterDragon
2014-11-29 02:20:42 +00:00
parent 6ebaebd1d1
commit dc2e44da36
4 changed files with 10 additions and 7 deletions

View File

@@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA
{ {
// Pick a random port that faces the target // Pick a random port that faces the target
var bodyYaw = facing.Value != null ? WAngle.FromFacing(facing.Value.Facing) : WAngle.Zero; var bodyYaw = facing.Value != null ? WAngle.FromFacing(facing.Value.Facing) : WAngle.Zero;
var indices = Exts.MakeArray(Ports.Length, i => i).Shuffle(self.World.SharedRandom); var indices = Enumerable.Range(0, Ports.Length).Shuffle(self.World.SharedRandom);
foreach (var i in indices) foreach (var i in indices)
{ {
var yaw = bodyYaw + Ports[i].Yaw; var yaw = bodyYaw + Ports[i].Yaw;

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
@@ -66,8 +67,9 @@ namespace OpenRA.Mods.RA
public IEnumerable<PipType> GetPips(Actor self) public IEnumerable<PipType> GetPips(Actor self)
{ {
var pips = Info.PipCount != 0 ? Info.PipCount : Info.Ammo; var pips = Info.PipCount != 0 ? Info.PipCount : Info.Ammo;
return Exts.MakeArray(pips, return Enumerable.Range(0, pips).Select(i =>
i => (ammo * pips) / Info.Ammo > i ? Info.PipType : Info.PipTypeEmpty); (ammo * pips) / Info.Ammo > i ?
Info.PipType : Info.PipTypeEmpty);
} }
} }
} }

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
@@ -57,9 +58,9 @@ namespace OpenRA.Mods.RA
public IEnumerable<PipType> GetPips(Actor self) public IEnumerable<PipType> GetPips(Actor self)
{ {
return Exts.MakeArray(Info.PipCount, return Enumerable.Range(0, Info.PipCount).Select(i =>
i => (Player.Resources * Info.PipCount > i * Player.ResourceCapacity) Player.Resources * Info.PipCount > i * Player.ResourceCapacity
? Info.PipColor : PipType.Transparent); ? Info.PipColor : PipType.Transparent);
} }
public bool ShouldExplode(Actor self) { return Stored > 0; } public bool ShouldExplode(Actor self) { return Stored > 0; }

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return item; return item;
}; };
var options = Exts.MakeArray(teamCount + 1, i => i).ToList(); var options = Enumerable.Range(0, teamCount + 1);
dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem); dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem);
} }