Add IActorPreviewInitModifier interface.
This commit is contained in:
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder, IResolveOrder, IOrderVoice, IDeathActorInitModifier,
|
||||
INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing
|
||||
INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing, IActorPreviewInitModifier
|
||||
{
|
||||
static readonly Pair<CPos, SubCell>[] NoCells = { };
|
||||
|
||||
@@ -660,5 +660,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
UnReserve();
|
||||
}
|
||||
|
||||
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
||||
{
|
||||
if (!inits.Contains<DynamicFacingInit>() && !inits.Contains<FacingInit>())
|
||||
inits.Add(new DynamicFacingInit(() => Facing));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public class Mobile : UpgradableTrait<MobileInfo>, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync,
|
||||
IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove
|
||||
IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove, IActorPreviewInitModifier
|
||||
{
|
||||
const int AverageTicksBeforePathing = 5;
|
||||
const int SpreadTicksBeforePathing = 5;
|
||||
@@ -716,6 +716,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
||||
{
|
||||
if (!inits.Contains<DynamicFacingInit>() && !inits.Contains<FacingInit>())
|
||||
inits.Add(new DynamicFacingInit(() => facing));
|
||||
}
|
||||
|
||||
class MoveOrderTargeter : IOrderTargeter
|
||||
{
|
||||
readonly Mobile mobile;
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
}
|
||||
}
|
||||
|
||||
public class RenderSprites : IRender, ITick, INotifyOwnerChanged, INotifyEffectiveOwnerChanged
|
||||
public class RenderSprites : IRender, ITick, INotifyOwnerChanged, INotifyEffectiveOwnerChanged, IActorPreviewInitModifier
|
||||
{
|
||||
class AnimationWrapper
|
||||
{
|
||||
@@ -231,5 +231,11 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
.Select(a => (a.Animation.Animation.Image.Size.XY * info.Scale).ToInt2())
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
||||
{
|
||||
if (!inits.Contains<FactionInit>())
|
||||
inits.Add(new FactionInit(faction));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +174,28 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
facings.Value(self.World).Add(Name, TurretFacing);
|
||||
}
|
||||
|
||||
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
||||
{
|
||||
var facings = inits.GetOrDefault<DynamicTurretFacingsInit>();
|
||||
if (facings == null)
|
||||
{
|
||||
facings = new DynamicTurretFacingsInit();
|
||||
inits.Add(facings);
|
||||
}
|
||||
|
||||
Func<int> bodyFacing = () => facing.Facing;
|
||||
var dynamicFacing = inits.GetOrDefault<DynamicFacingInit>();
|
||||
var staticFacing = inits.GetOrDefault<FacingInit>();
|
||||
if (dynamicFacing != null)
|
||||
bodyFacing = dynamicFacing.Value(self.World);
|
||||
else if (staticFacing != null)
|
||||
bodyFacing = () => staticFacing.Value(self.World);
|
||||
|
||||
// Freeze the relative turret facing to its current value
|
||||
var facingOffset = TurretFacing - bodyFacing();
|
||||
facings.Value(self.World).Add(Name, () => bodyFacing() + facingOffset);
|
||||
}
|
||||
}
|
||||
|
||||
public class TurretFacingInit : IActorInit<int>
|
||||
|
||||
@@ -125,4 +125,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
bool AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType, out CVec facing);
|
||||
void SetDirty();
|
||||
}
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface IActorPreviewInitModifier
|
||||
{
|
||||
void ModifyActorPreviewInit(Actor self, TypeDictionary inits);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user