Migrate to System.Lazy.

This commit is contained in:
Paul Chote
2014-03-12 22:48:47 +13:00
parent 67cd0645a4
commit 1b2a90c00c
25 changed files with 87 additions and 125 deletions

View File

@@ -60,9 +60,9 @@ namespace OpenRA.Mods.RA
public readonly Barrel[] Barrels;
public readonly Actor self;
OpenRA.FileFormats.Lazy<Turreted> Turret;
OpenRA.FileFormats.Lazy<IBodyOrientation> Coords;
OpenRA.FileFormats.Lazy<LimitedAmmo> limitedAmmo;
Lazy<Turreted> Turret;
Lazy<IBodyOrientation> Coords;
Lazy<LimitedAmmo> limitedAmmo;
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
public WRange Recoil;
@@ -75,9 +75,9 @@ namespace OpenRA.Mods.RA
Info = info;
// We can't resolve these until runtime
Turret = Lazy.New(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
Coords = Lazy.New(() => self.Trait<IBodyOrientation>());
limitedAmmo = Lazy.New(() => self.TraitOrDefault<LimitedAmmo>());
Turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
Coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
limitedAmmo = Exts.Lazy(() => self.TraitOrDefault<LimitedAmmo>());
Weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
Burst = Weapon.Burst;

View File

@@ -33,8 +33,8 @@ namespace OpenRA.Mods.RA
{
[Sync] public bool IsAttacking { get; internal set; }
public IEnumerable<Armament> Armaments { get { return GetArmaments(); } }
protected OpenRA.FileFormats.Lazy<IFacing> facing;
protected OpenRA.FileFormats.Lazy<Building> building;
protected Lazy<IFacing> facing;
protected Lazy<Building> building;
protected Func<IEnumerable<Armament>> GetArmaments;
readonly Actor self;
@@ -45,13 +45,13 @@ namespace OpenRA.Mods.RA
this.self = self;
this.info = info;
var armaments = Lazy.New(() => self.TraitsImplementing<Armament>()
var armaments = Exts.Lazy(() => self.TraitsImplementing<Armament>()
.Where(a => info.Armaments.Contains(a.Info.Name)));
GetArmaments = () => armaments.Value;
facing = Lazy.New(() => self.TraitOrDefault<IFacing>());
building = Lazy.New(() => self.TraitOrDefault<Building>());
facing = Exts.Lazy(() => self.TraitOrDefault<IFacing>());
building = Exts.Lazy(() => self.TraitOrDefault<Building>());
}
protected virtual bool CanAttack(Actor self, Target target)

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
public readonly FirePort[] Ports;
AttackGarrisonedInfo info;
OpenRA.FileFormats.Lazy<IBodyOrientation> coords;
Lazy<IBodyOrientation> coords;
List<Armament> armaments;
List<AnimationWithOffset> muzzles;
Dictionary<Actor, IFacing> paxFacing;
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA
: base(self, info)
{
this.info = info;
coords = Lazy.New(() => self.Trait<IBodyOrientation>());
coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
armaments = new List<Armament>();
muzzles = new List<AnimationWithOffset>();
paxFacing = new Dictionary<Actor, IFacing>();

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.FileFormats;
@@ -30,9 +31,9 @@ namespace OpenRA.Mods.RA
public CombatDebugOverlay(Actor self)
{
attack = Lazy.New(() => self.TraitOrDefault<AttackBase>());
coords = Lazy.New(() => self.Trait<IBodyOrientation>());
health = Lazy.New(() => self.TraitOrDefault<Health>());
attack = Exts.Lazy(() => self.TraitOrDefault<AttackBase>());
coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
var localPlayer = self.World.LocalPlayer;
devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Effects;
using OpenRA.FileFormats;
@@ -51,10 +52,10 @@ namespace OpenRA.Mods.RA.Effects
self.World.AddFrameEndTask(w => w.Add(this));
huf = Lazy.New(() => self.TraitOrDefault<HiddenUnderFog>());
fuf = Lazy.New(() => self.TraitOrDefault<FrozenUnderFog>());
disguise = Lazy.New(() => self.TraitOrDefault<Disguise>());
cloak = Lazy.New(() => self.TraitOrDefault<Cloak>());
huf = Exts.Lazy(() => self.TraitOrDefault<HiddenUnderFog>());
fuf = Exts.Lazy(() => self.TraitOrDefault<FrozenUnderFog>());
disguise = Exts.Lazy(() => self.TraitOrDefault<Disguise>());
cloak = Exts.Lazy(() => self.TraitOrDefault<Cloak>());
watcher = new Cache<Player, GpsWatcher>(p => p.PlayerActor.Trait<GpsWatcher>());
frozen = new Cache<Player, FrozenActorLayer>(p => p.PlayerActor.Trait<FrozenActorLayer>());

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
@@ -41,9 +42,9 @@ namespace OpenRA.Mods.RA
// Spawned actors (e.g. building husks) shouldn't be revealed
startsRevealed = info.StartsRevealed && !init.Contains<ParentActorInit>();
footprint = FootprintUtils.Tiles(init.self);
tooltip = Lazy.New(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
tooltip = Lazy.New(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
health = Lazy.New(() => init.self.TraitOrDefault<Health>());
tooltip = Exts.Lazy(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
tooltip = Exts.Lazy(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
health = Exts.Lazy(() => init.self.TraitOrDefault<Health>());
frozen = new Dictionary<Player, FrozenActor>();
visible = init.world.Players.ToDictionary(p => p, p => false);

3
OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs Executable file → Normal file
View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
@@ -34,7 +35,7 @@ namespace OpenRA.Mods.RA
{
self = init.self;
DevMode = init.self.Trait<DeveloperMode>();
RadarPings = Lazy.New(() => init.world.WorldActor.TraitOrDefault<RadarPings>());
RadarPings = Exts.Lazy(() => init.world.WorldActor.TraitOrDefault<RadarPings>());
init.world.ActorAdded += ActorAdded;
init.world.ActorRemoved += ActorRemoved;

4
OpenRA.Mods.RA/Widgets/ResourceBarWidget.cs Executable file → Normal file
View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Widgets
{
public readonly string TooltipTemplate;
public readonly string TooltipContainer;
OpenRA.FileFormats.Lazy<TooltipContainerWidget> tooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer;
public string TooltipFormat = "";
public ResourceBarOrientation Orientation = ResourceBarOrientation.Vertical;
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Widgets
[ObjectCreator.UseCtor]
public ResourceBarWidget(World world)
{
tooltipContainer = Lazy.New(() =>
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}