Replace IActorInit with an abstract class.

A shared ValueActorInit<T> is introduced to reduce duplication
in the most common init cases, and an ActorInitActorReference
allow actors to be referenced by map.yaml name.
This commit is contained in:
Paul Chote
2020-06-02 19:37:18 +01:00
committed by teinarss
parent 4df5ac0385
commit b38018af9c
28 changed files with 365 additions and 306 deletions

View File

@@ -11,6 +11,7 @@
using System;
using OpenRA.Mods.Cnc.Activities;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
@@ -66,7 +67,7 @@ namespace OpenRA.Mods.Cnc.Traits
// 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);
init.World.AddFrameEndTask(w => chronosphere = chronosphereInit.Value.Actor(init.World).Value);
}
void ITick.Tick(Actor self)
@@ -176,40 +177,27 @@ namespace OpenRA.Mods.Cnc.Traits
void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init) { ModifyActorInit(init); }
}
public class ChronoshiftReturnInit : IActorInit<int>
public class ChronoshiftReturnInit : ValueActorInit<int>
{
[FieldFromYamlKey]
readonly int value = 0;
public ChronoshiftReturnInit() { }
public ChronoshiftReturnInit(int init) { value = init; }
public int Value { get { return value; } }
public ChronoshiftReturnInit(int value)
: base(value) { }
}
public class ChronoshiftDurationInit : IActorInit<int>
public class ChronoshiftDurationInit : ValueActorInit<int>
{
[FieldFromYamlKey]
readonly int value = 0;
public ChronoshiftDurationInit() { }
public ChronoshiftDurationInit(int init) { value = init; }
public int Value { get { return value; } }
public ChronoshiftDurationInit(int value)
: base(value) { }
}
public class ChronoshiftOriginInit : IActorInit<CPos>
public class ChronoshiftOriginInit : ValueActorInit<CPos>
{
[FieldFromYamlKey]
readonly CPos value;
public ChronoshiftOriginInit(CPos init) { value = init; }
public CPos Value { get { return value; } }
public ChronoshiftOriginInit(CPos value)
: base(value) { }
}
public class ChronoshiftChronosphereInit : IActorInit
public class ChronoshiftChronosphereInit : ValueActorInit<ActorInitActorReference>
{
readonly Actor value;
public ChronoshiftChronosphereInit(Actor init) { value = init; }
public Lazy<Actor> Value(World world) { return new Lazy<Actor>(() => value); }
public ChronoshiftChronosphereInit(Actor value)
: base(value) { }
}
}

View File

@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Cnc.Traits
// 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);
init.World.AddFrameEndTask(w => chronosphere = chronosphereInit.Value.Actor(init.World).Value);
}
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()

View File

@@ -133,8 +133,5 @@ namespace OpenRA.Mods.Cnc.Traits
}
}
class HideBibPreviewInit : IActorInit, ISuppressInitExport
{
public HideBibPreviewInit() { }
}
class HideBibPreviewInit : RuntimeFlagInit { }
}

View File

@@ -95,13 +95,9 @@ namespace OpenRA.Mods.Cnc.Traits.Render
}
}
public class BodyAnimationFrameInit : IActorInit<uint>
public class BodyAnimationFrameInit : ValueActorInit<uint>
{
[FieldFromYamlKey]
readonly uint value = 0;
public BodyAnimationFrameInit() { }
public BodyAnimationFrameInit(uint init) { value = init; }
public uint Value { get { return value; } }
public BodyAnimationFrameInit(uint value)
: base(value) { }
}
}