Merge pull request #8868 from pchote/readonly-traits

Make trait fields readonly
This commit is contained in:
Matthias Mailänder
2015-08-01 15:58:42 +02:00
20 changed files with 48 additions and 46 deletions

View File

@@ -36,9 +36,11 @@ namespace OpenRA.Mods.Common.Effects
class Contrail : ITick, IRender class Contrail : ITick, IRender
{ {
ContrailInfo info; readonly ContrailInfo info;
readonly IBodyOrientation body;
// This is a mutable struct, so it can't be readonly.
ContrailRenderable trail; ContrailRenderable trail;
IBodyOrientation body;
public Contrail(Actor self, ContrailInfo info) public Contrail(Actor self, ContrailInfo info)
{ {

View File

@@ -21,20 +21,20 @@ namespace OpenRA.Mods.Common.Traits
class ExternalCapturableBar : ISelectionBar class ExternalCapturableBar : ISelectionBar
{ {
ExternalCapturable cap; readonly ExternalCapturable capturable;
public ExternalCapturableBar(Actor self) public ExternalCapturableBar(Actor self)
{ {
this.cap = self.Trait<ExternalCapturable>(); capturable = self.Trait<ExternalCapturable>();
} }
public float GetValue() public float GetValue()
{ {
// only show when building is being captured // only show when building is being captured
if (!cap.CaptureInProgress) if (!capturable.CaptureInProgress)
return 0f; return 0f;
return (float)cap.CaptureProgressTime / (cap.Info.CaptureCompleteTime * 25); return (float)capturable.CaptureProgressTime / (capturable.Info.CaptureCompleteTime * 25);
} }
public Color GetColor() { return Color.Orange; } public Color GetColor() { return Color.Orange; }

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
class RenderBuildingTurreted : RenderBuilding class RenderBuildingTurreted : RenderBuilding
{ {
Turreted t; readonly Turreted turreted;
static Func<int> MakeTurretFacingFunc(Actor self) static Func<int> MakeTurretFacingFunc(Actor self)
{ {
@@ -48,14 +48,14 @@ namespace OpenRA.Mods.Common.Traits
public RenderBuildingTurreted(ActorInitializer init, RenderBuildingInfo info) public RenderBuildingTurreted(ActorInitializer init, RenderBuildingInfo info)
: base(init, info, MakeTurretFacingFunc(init.Self)) : base(init, info, MakeTurretFacingFunc(init.Self))
{ {
t = init.Self.TraitsImplementing<Turreted>().FirstOrDefault(); turreted = init.Self.TraitsImplementing<Turreted>().FirstOrDefault();
t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
} }
public override void DamageStateChanged(Actor self, AttackInfo e) public override void DamageStateChanged(Actor self, AttackInfo e)
{ {
base.DamageStateChanged(self, e); base.DamageStateChanged(self, e);
t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
} }
} }
} }

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
class RenderDetectionCircle : IPostRenderSelection class RenderDetectionCircle : IPostRenderSelection
{ {
Actor self; readonly Actor self;
public RenderDetectionCircle(Actor self) { this.self = self; } public RenderDetectionCircle(Actor self) { this.self = self; }

View File

@@ -56,8 +56,8 @@ namespace OpenRA.Mods.Common.Traits
class RenderRangeCircle : IPostRenderSelection class RenderRangeCircle : IPostRenderSelection
{ {
Actor self; readonly Actor self;
AttackBase attack; readonly AttackBase attack;
public RenderRangeCircle(Actor self) public RenderRangeCircle(Actor self)
{ {

View File

@@ -73,11 +73,11 @@ namespace OpenRA.Mods.Common.Traits
public class RenderVoxels : IRender, INotifyOwnerChanged public class RenderVoxels : IRender, INotifyOwnerChanged
{ {
readonly List<VoxelAnimation> components = new List<VoxelAnimation>(); readonly List<VoxelAnimation> components = new List<VoxelAnimation>();
Actor self; readonly Actor self;
RenderVoxelsInfo info; readonly RenderVoxelsInfo info;
IBodyOrientation body; readonly IBodyOrientation body;
WRot camera; readonly WRot camera;
WRot lightSource; readonly WRot lightSource;
public RenderVoxels(Actor self, RenderVoxelsInfo info) public RenderVoxels(Actor self, RenderVoxelsInfo info)
{ {

View File

@@ -35,8 +35,8 @@ namespace OpenRA.Mods.Common.Traits
class WithBuildingExplosion : INotifyKilled class WithBuildingExplosion : INotifyKilled
{ {
WithBuildingExplosionInfo info; readonly WithBuildingExplosionInfo info;
BuildingInfo buildingInfo; readonly BuildingInfo buildingInfo;
public WithBuildingExplosion(Actor self, WithBuildingExplosionInfo info) public WithBuildingExplosion(Actor self, WithBuildingExplosionInfo info)
{ {

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.Common.Traits
public class WithBuildingPlacedAnimation : INotifyBuildingPlaced, INotifyBuildComplete public class WithBuildingPlacedAnimation : INotifyBuildingPlaced, INotifyBuildComplete
{ {
WithBuildingPlacedAnimationInfo info; readonly WithBuildingPlacedAnimationInfo info;
RenderSimple renderSimple; readonly RenderSimple renderSimple;
bool buildComplete; bool buildComplete;
public WithBuildingPlacedAnimation(Actor self, WithBuildingPlacedAnimationInfo info) public WithBuildingPlacedAnimation(Actor self, WithBuildingPlacedAnimationInfo info)

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
public class WithBuildingPlacedOverlay : INotifyBuildComplete, INotifySold, INotifyDamageStateChanged, INotifyBuildingPlaced, INotifyTransform public class WithBuildingPlacedOverlay : INotifyBuildComplete, INotifySold, INotifyDamageStateChanged, INotifyBuildingPlaced, INotifyTransform
{ {
Animation overlay; readonly Animation overlay;
bool buildComplete; bool buildComplete;
public WithBuildingPlacedOverlay(Actor self, WithBuildingPlacedOverlayInfo info) public WithBuildingPlacedOverlay(Actor self, WithBuildingPlacedOverlayInfo info)

View File

@@ -30,8 +30,8 @@ namespace OpenRA.Mods.Common.Traits
class WithHarvestOverlay : INotifyHarvesterAction class WithHarvestOverlay : INotifyHarvesterAction
{ {
WithHarvestOverlayInfo info; readonly WithHarvestOverlayInfo info;
Animation anim; readonly Animation anim;
bool visible; bool visible;
public WithHarvestOverlay(Actor self, WithHarvestOverlayInfo info) public WithHarvestOverlay(Actor self, WithHarvestOverlayInfo info)

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
public class WithIdleOverlay : UpgradableTrait<WithIdleOverlayInfo>, INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyTransform public class WithIdleOverlay : UpgradableTrait<WithIdleOverlayInfo>, INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyTransform
{ {
Animation overlay; readonly Animation overlay;
bool buildComplete; bool buildComplete;
public WithIdleOverlay(Actor self, WithIdleOverlayInfo info) public WithIdleOverlay(Actor self, WithIdleOverlayInfo info)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
public class WithProductionOverlay : INotifyDamageStateChanged, ITick, INotifyBuildComplete, INotifySold public class WithProductionOverlay : INotifyDamageStateChanged, ITick, INotifyBuildComplete, INotifySold
{ {
Animation overlay; readonly Animation overlay;
ProductionQueue queue; ProductionQueue queue;
bool buildComplete; bool buildComplete;

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
public class WithRepairAnimation : INotifyRepair public class WithRepairAnimation : INotifyRepair
{ {
WithRepairAnimationInfo info; readonly WithRepairAnimationInfo info;
public WithRepairAnimation(Actor self, WithRepairAnimationInfo info) public WithRepairAnimation(Actor self, WithRepairAnimationInfo info)
{ {

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
public class WithRepairOverlay : INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyRepair public class WithRepairOverlay : INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyRepair
{ {
Animation overlay; readonly Animation overlay;
bool buildComplete; bool buildComplete;
public WithRepairOverlay(Actor self, WithRepairOverlayInfo info) public WithRepairOverlay(Actor self, WithRepairOverlayInfo info)

View File

@@ -45,9 +45,9 @@ namespace OpenRA.Mods.Common.Traits
public class WithRotor : ITick public class WithRotor : ITick
{ {
WithRotorInfo info; readonly WithRotorInfo info;
Animation rotorAnim; readonly Animation rotorAnim;
IMove movement; readonly IMove movement;
public WithRotor(Actor self, WithRotorInfo info) public WithRotor(Actor self, WithRotorInfo info)
{ {

View File

@@ -58,11 +58,11 @@ namespace OpenRA.Mods.Common.Traits
public class WithTurret : UpgradableTrait<WithTurretInfo>, ITick, INotifyDamageStateChanged public class WithTurret : UpgradableTrait<WithTurretInfo>, ITick, INotifyDamageStateChanged
{ {
RenderSprites rs; readonly RenderSprites rs;
IBodyOrientation body; readonly IBodyOrientation body;
AttackBase ab; readonly AttackBase ab;
Turreted t; readonly Turreted t;
Armament[] arms; readonly Armament[] arms;
public readonly Animation DefaultAnimation; public readonly Animation DefaultAnimation;
public WithTurret(Actor self, WithTurretInfo info) public WithTurret(Actor self, WithTurretInfo info)

View File

@@ -48,11 +48,11 @@ namespace OpenRA.Mods.Common.Traits
public class WithVoxelBarrel public class WithVoxelBarrel
{ {
WithVoxelBarrelInfo info; readonly WithVoxelBarrelInfo info;
Actor self; readonly Actor self;
Armament armament; readonly Armament armament;
Turreted turreted; readonly Turreted turreted;
IBodyOrientation body; readonly IBodyOrientation body;
public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info) public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info)
{ {

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
public class WithVoxelBody : IAutoSelectionSize public class WithVoxelBody : IAutoSelectionSize
{ {
int2 size; readonly int2 size;
public WithVoxelBody(Actor self, WithVoxelBodyInfo info) public WithVoxelBody(Actor self, WithVoxelBodyInfo info)
{ {

View File

@@ -28,8 +28,8 @@ namespace OpenRA.Mods.Common.Traits
class SmokeTrailWhenDamaged : ITick class SmokeTrailWhenDamaged : ITick
{ {
IBodyOrientation body; readonly SmokeTrailWhenDamagedInfo info;
SmokeTrailWhenDamagedInfo info; readonly IBodyOrientation body;
int ticks; int ticks;
public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info) public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info)

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits
class NukePower : SupportPower class NukePower : SupportPower
{ {
readonly NukePowerInfo info; readonly NukePowerInfo info;
IBodyOrientation body; readonly IBodyOrientation body;
public NukePower(Actor self, NukePowerInfo info) public NukePower(Actor self, NukePowerInfo info)
: base(self, info) : base(self, info)