Only expose Facing for actors that define a facing.

This commit is contained in:
Paul Chote
2024-12-30 19:46:38 +00:00
committed by Gustas
parent cac6aebb6c
commit 0651308210

View File

@@ -96,7 +96,6 @@ namespace OpenRA.Mods.Common.Scripting
[ScriptPropertyGroup("General")] [ScriptPropertyGroup("General")]
public class GeneralProperties : ScriptActorProperties public class GeneralProperties : ScriptActorProperties
{ {
readonly IFacing facing;
readonly AutoTarget autotarget; readonly AutoTarget autotarget;
readonly ScriptTags scriptTags; readonly ScriptTags scriptTags;
readonly Tooltip[] tooltips; readonly Tooltip[] tooltips;
@@ -104,24 +103,11 @@ namespace OpenRA.Mods.Common.Scripting
public GeneralProperties(ScriptContext context, Actor self) public GeneralProperties(ScriptContext context, Actor self)
: base(context, self) : base(context, self)
{ {
facing = self.TraitOrDefault<IFacing>();
autotarget = self.TraitOrDefault<AutoTarget>(); autotarget = self.TraitOrDefault<AutoTarget>();
scriptTags = self.TraitOrDefault<ScriptTags>(); scriptTags = self.TraitOrDefault<ScriptTags>();
tooltips = self.TraitsImplementing<Tooltip>().ToArray(); tooltips = self.TraitsImplementing<Tooltip>().ToArray();
} }
[Desc("The direction that the actor is facing.")]
public WAngle Facing
{
get
{
if (facing == null)
throw new LuaException($"Actor '{Self}' doesn't define a facing");
return facing.Facing;
}
}
[ScriptActorPropertyActivity] [ScriptActorPropertyActivity]
[Desc("Instantly moves the actor to the specified cell.")] [Desc("Instantly moves the actor to the specified cell.")]
public void Teleport(CPos cell) public void Teleport(CPos cell)
@@ -220,4 +206,19 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("The actor position in world coordinates.")] [Desc("The actor position in world coordinates.")]
public WPos CenterPosition => Self.CenterPosition; public WPos CenterPosition => Self.CenterPosition;
} }
[ScriptPropertyGroup("General")]
public class FacingProperties : ScriptActorProperties, Requires<IFacingInfo>
{
readonly IFacing facing;
public FacingProperties(ScriptContext context, Actor self)
: base(context, self)
{
facing = self.Trait<IFacing>();
}
[Desc("The direction that the actor is facing.")]
public WAngle Facing => facing.Facing;
}
} }