From 065130821094a3efe8782e42c12f70e585564063 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 30 Dec 2024 19:46:38 +0000 Subject: [PATCH] Only expose Facing for actors that define a facing. --- .../Scripting/Properties/GeneralProperties.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs index 702ec3bf2f..17feb2e60f 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs @@ -96,7 +96,6 @@ namespace OpenRA.Mods.Common.Scripting [ScriptPropertyGroup("General")] public class GeneralProperties : ScriptActorProperties { - readonly IFacing facing; readonly AutoTarget autotarget; readonly ScriptTags scriptTags; readonly Tooltip[] tooltips; @@ -104,24 +103,11 @@ namespace OpenRA.Mods.Common.Scripting public GeneralProperties(ScriptContext context, Actor self) : base(context, self) { - facing = self.TraitOrDefault(); autotarget = self.TraitOrDefault(); scriptTags = self.TraitOrDefault(); tooltips = self.TraitsImplementing().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] [Desc("Instantly moves the actor to the specified cell.")] public void Teleport(CPos cell) @@ -220,4 +206,19 @@ namespace OpenRA.Mods.Common.Scripting [Desc("The actor position in world coordinates.")] public WPos CenterPosition => Self.CenterPosition; } + + [ScriptPropertyGroup("General")] + public class FacingProperties : ScriptActorProperties, Requires + { + readonly IFacing facing; + + public FacingProperties(ScriptContext context, Actor self) + : base(context, self) + { + facing = self.Trait(); + } + + [Desc("The direction that the actor is facing.")] + public WAngle Facing => facing.Facing; + } }