Rewrite ActorInit queries.
This commit is contained in:
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
this.info = info;
|
||||
turret = turrets.FirstOrDefault();
|
||||
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
|
||||
skippedMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
||||
skippedMakeAnimation = init.Contains<SkipMakeAnimsInit>(info);
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Mods.Cnc.Activities;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
@@ -58,18 +59,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
: base(info)
|
||||
{
|
||||
self = init.Self;
|
||||
ReturnTicks = init.GetValue<ChronoshiftReturnInit, int>(info, 0);
|
||||
duration = init.GetValue<ChronoshiftDurationInit, int>(info, 0);
|
||||
Origin = init.GetValue<ChronoshiftOriginInit, CPos>(info, CPos.Zero);
|
||||
|
||||
if (init.Contains<ChronoshiftReturnInit>())
|
||||
ReturnTicks = init.Get<ChronoshiftReturnInit, int>();
|
||||
|
||||
if (init.Contains<ChronoshiftDurationInit>())
|
||||
duration = init.Get<ChronoshiftDurationInit, int>();
|
||||
|
||||
if (init.Contains<ChronoshiftOriginInit>())
|
||||
Origin = init.Get<ChronoshiftOriginInit, CPos>();
|
||||
|
||||
if (init.Contains<ChronoshiftChronosphereInit>())
|
||||
chronosphere = init.Get<ChronoshiftChronosphereInit, Actor>();
|
||||
// Defer to the end of tick as the lazy value may reference an actor that hasn't been created yet
|
||||
var chronosphereInit = init.GetOrDefault<ChronoshiftChronosphereInit>(info);
|
||||
if (chronosphereInit != null)
|
||||
init.World.AddFrameEndTask(w => chronosphere = chronosphereInit.Value(init.World).Value);
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
@@ -186,7 +183,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public ChronoshiftReturnInit() { }
|
||||
public ChronoshiftReturnInit(int init) { value = init; }
|
||||
public int Value(World world) { return value; }
|
||||
public int Value { get { return value; } }
|
||||
}
|
||||
|
||||
public class ChronoshiftDurationInit : IActorInit<int>
|
||||
@@ -196,7 +193,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public ChronoshiftDurationInit() { }
|
||||
public ChronoshiftDurationInit(int init) { value = init; }
|
||||
public int Value(World world) { return value; }
|
||||
public int Value { get { return value; } }
|
||||
}
|
||||
|
||||
public class ChronoshiftOriginInit : IActorInit<CPos>
|
||||
@@ -205,13 +202,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
readonly CPos value;
|
||||
|
||||
public ChronoshiftOriginInit(CPos init) { value = init; }
|
||||
public CPos Value(World world) { return value; }
|
||||
public CPos Value { get { return value; } }
|
||||
}
|
||||
|
||||
public class ChronoshiftChronosphereInit : IActorInit<Actor>
|
||||
public class ChronoshiftChronosphereInit : IActorInit
|
||||
{
|
||||
readonly Actor value;
|
||||
public ChronoshiftChronosphereInit(Actor init) { value = init; }
|
||||
public Actor Value(World world) { return value; }
|
||||
|
||||
public Lazy<Actor> Value(World world) { return new Lazy<Actor>(() => value); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
@@ -94,19 +95,15 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
health = self.Trait<Health>();
|
||||
|
||||
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
|
||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
||||
faction = init.GetValue<FactionInit, string>(info, self.Owner.Faction.InternalName);
|
||||
returnTicks = init.GetValue<ChronoshiftReturnInit, int>(info, 0);
|
||||
duration = init.GetValue<ChronoshiftDurationInit, int>(info, 0);
|
||||
origin = init.GetValue<ChronoshiftOriginInit, CPos>(info, CPos.Zero);
|
||||
|
||||
if (init.Contains<ChronoshiftReturnInit>())
|
||||
returnTicks = init.Get<ChronoshiftReturnInit, int>();
|
||||
|
||||
if (init.Contains<ChronoshiftDurationInit>())
|
||||
duration = init.Get<ChronoshiftDurationInit, int>();
|
||||
|
||||
if (init.Contains<ChronoshiftOriginInit>())
|
||||
origin = init.Get<ChronoshiftOriginInit, CPos>();
|
||||
|
||||
if (init.Contains<ChronoshiftChronosphereInit>())
|
||||
chronosphere = init.Get<ChronoshiftChronosphereInit, Actor>();
|
||||
// Defer to the end of tick as the lazy value may reference an actor that hasn't been created yet
|
||||
var chronosphereInit = init.GetOrDefault<ChronoshiftChronosphereInit>(info);
|
||||
if (chronosphereInit != null)
|
||||
init.World.AddFrameEndTask(w => chronosphere = chronosphereInit.Value(init.World).Value);
|
||||
}
|
||||
|
||||
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
public InfiltrateForTransform(ActorInitializer init, InfiltrateForTransformInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
||||
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||
}
|
||||
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, BitSet<TargetableType> types)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
if (init.Contains<HideBibPreviewInit>() && init.Get<HideBibPreviewInit, bool>())
|
||||
if (init.Contains<HideBibPreviewInit>(this))
|
||||
yield break;
|
||||
|
||||
if (Palette != null)
|
||||
@@ -45,10 +45,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
var bibOffset = bi.Dimensions.Y - rows;
|
||||
var centerOffset = bi.CenterOffset(init.World);
|
||||
var map = init.World.Map;
|
||||
var location = CPos.Zero;
|
||||
|
||||
if (init.Contains<LocationInit>())
|
||||
location = init.Get<LocationInit, CPos>();
|
||||
var location = init.GetValue<LocationInit, CPos>(this, CPos.Zero);
|
||||
|
||||
for (var i = 0; i < rows * width; i++)
|
||||
{
|
||||
@@ -136,13 +133,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
}
|
||||
}
|
||||
|
||||
class HideBibPreviewInit : IActorInit<bool>, ISuppressInitExport
|
||||
class HideBibPreviewInit : IActorInit, ISuppressInitExport
|
||||
{
|
||||
[FieldFromYamlKey]
|
||||
readonly bool value = true;
|
||||
|
||||
public HideBibPreviewInit() { }
|
||||
public HideBibPreviewInit(bool init) { value = init; }
|
||||
public bool Value(World world) { return value; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
var wsb = init.Actor.TraitInfos<WithSpriteBodyInfo>().FirstOrDefault();
|
||||
|
||||
// Show the correct turret facing
|
||||
var facing = WAngle.FromFacing(init.Contains<TurretFacingInit>() ? init.Get<TurretFacingInit>().Value(init.World) : t.InitialFacing);
|
||||
var facing = WAngle.FromFacing(init.GetValue<TurretFacingInit, int>(this, t.InitialFacing));
|
||||
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), wsb.Sequence));
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
{
|
||||
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var frame = init.Contains<BodyAnimationFrameInit>() ? init.Get<BodyAnimationFrameInit, uint>() : 0;
|
||||
var frame = init.GetValue<BodyAnimationFrameInit, uint>(this, 0);
|
||||
|
||||
yield return new ModelAnimation(model, () => WVec.Zero,
|
||||
() => new[] { body.QuantizeOrientation(orientation(), facings) },
|
||||
@@ -102,6 +102,6 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
|
||||
public BodyAnimationFrameInit() { }
|
||||
public BodyAnimationFrameInit(uint init) { value = init; }
|
||||
public uint Value(World world) { return value; }
|
||||
public uint Value { get { return value; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,13 +80,15 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
Info = info;
|
||||
self = init.Self;
|
||||
|
||||
if (init.Contains<LocationInit>())
|
||||
SetPosition(self, init.Get<LocationInit, CPos>());
|
||||
var locationInit = init.GetOrDefault<LocationInit>(info);
|
||||
if (locationInit != null)
|
||||
SetPosition(self, locationInit.Value);
|
||||
|
||||
if (init.Contains<CenterPositionInit>())
|
||||
SetPosition(self, init.Get<CenterPositionInit, WPos>());
|
||||
var centerPositionInit = init.GetOrDefault<CenterPositionInit>(info);
|
||||
if (centerPositionInit != null)
|
||||
SetPosition(self, centerPositionInit.Value);
|
||||
|
||||
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : Info.GetInitialFacing();
|
||||
Facing = init.GetValue<FacingInit, int>(info, Info.GetInitialFacing());
|
||||
|
||||
// Prevent mappers from setting bogus facings
|
||||
if (Facing != 64 && Facing != 192)
|
||||
|
||||
Reference in New Issue
Block a user