Rename "Created" to "Initialize" and let it handle adding to the world
This commit is contained in:
@@ -172,7 +172,7 @@ namespace OpenRA
|
||||
SyncHashes = TraitsImplementing<ISync>().Select(sync => new SyncHash(sync)).ToArray();
|
||||
}
|
||||
|
||||
internal void Created()
|
||||
internal void Initialize(bool addToWorld = true)
|
||||
{
|
||||
created = true;
|
||||
|
||||
@@ -226,6 +226,9 @@ namespace OpenRA
|
||||
activity.Queue(CurrentActivity);
|
||||
CurrentActivity = activity;
|
||||
}
|
||||
|
||||
if (addToWorld)
|
||||
World.Add(this);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
|
||||
@@ -169,12 +169,11 @@ namespace OpenRA
|
||||
// Special case handling is required for the Player actor:
|
||||
// Since Actor.Created would be called before PlayerActor is assigned here
|
||||
// querying player traits in INotifyCreated.Created would crash.
|
||||
// Therefore only call the constructor of Actor and run the Created callbacks ourselves.
|
||||
// Add the PlayerActor to the world afterwards.
|
||||
// Therefore assign the uninitialized actor and run the Created callbacks
|
||||
// by calling Initialize ourselves.
|
||||
var playerActorType = world.Type == WorldType.Editor ? EditorPlayerActorType : PlayerActorType;
|
||||
PlayerActor = new Actor(world, playerActorType, new TypeDictionary { new OwnerInit(this) });
|
||||
PlayerActor.Created();
|
||||
world.Add(PlayerActor);
|
||||
PlayerActor.Initialize(true);
|
||||
|
||||
Shroud = PlayerActor.Trait<Shroud>();
|
||||
FrozenActorLayer = PlayerActor.TraitOrDefault<FrozenActorLayer>();
|
||||
|
||||
@@ -337,10 +337,7 @@ namespace OpenRA
|
||||
public Actor CreateActor(bool addToWorld, string name, TypeDictionary initDict)
|
||||
{
|
||||
var a = new Actor(this, name, initDict);
|
||||
a.Created();
|
||||
if (addToWorld)
|
||||
Add(a);
|
||||
|
||||
a.Initialize(addToWorld);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user