Add ISingleInstanceInit interface.
Inits that are logically singletons (e.g. actor location or owner) should implement this interface to avoid runtime inconsistencies. Duplicate instances are rejected at init-time, allowing simpler queries when they are used.
This commit is contained in:
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
},
|
||||
(actor, value) =>
|
||||
{
|
||||
actor.ReplaceInit(new DeployStateInit(this, value ? DeployState.Deployed : DeployState.Undeployed));
|
||||
actor.ReplaceInit(new DeployStateInit(value ? DeployState.Deployed : DeployState.Undeployed));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
|
||||
canTurn = self.Info.HasTraitInfo<IFacingInfo>();
|
||||
move = self.TraitOrDefault<IMove>();
|
||||
deployState = init.GetValue<DeployStateInit, DeployState>(info, DeployState.Undeployed);
|
||||
deployState = init.GetValue<DeployStateInit, DeployState>(DeployState.Undeployed);
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
@@ -337,11 +337,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class DeployStateInit : ValueActorInit<DeployState>
|
||||
public class DeployStateInit : ValueActorInit<DeployState>, ISingleInstanceInit
|
||||
{
|
||||
public DeployStateInit(TraitInfo info, DeployState value)
|
||||
: base(info, value) { }
|
||||
|
||||
public DeployStateInit(DeployState value)
|
||||
: base(value) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user