From 321cbb559dae0b0c803472c30dca9b58a5b587f3 Mon Sep 17 00:00:00 2001 From: Paul Wheeler Date: Sat, 15 Aug 2020 02:01:50 -1000 Subject: [PATCH] Made it possible to specify a craft by name instead of just id. --- .../Vizzy/SetContextPropertyInstruction.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Vizzy/SetContextPropertyInstruction.cs b/Assets/Scripts/Vizzy/SetContextPropertyInstruction.cs index b075148..d346873 100644 --- a/Assets/Scripts/Vizzy/SetContextPropertyInstruction.cs +++ b/Assets/Scripts/Vizzy/SetContextPropertyInstruction.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Xml.Linq; +using Assets.Scripts.Flight; using Assets.Scripts.Objects; using ModApi.Craft.Program; using UnityEngine; @@ -187,8 +189,20 @@ protected override void ExecuteImpl(IThreadContext context) { switch (this.Origin) { case PositionType.CraftLocal: case PositionType.CraftPCI: - this.DrawingContext.CraftId = - (Int32)this.GetExpression(0).Evaluate(context).NumberValue; + var expression = this.GetExpression(0).Evaluate(context); + if (expression.IsNumberOrNumberAsText) { + this.DrawingContext.CraftId = (Int32)expression.NumberValue; + } else { + var matchingCraft = + FlightSceneScript.Instance.FlightState.CraftNodes + .FirstOrDefault(c => + String.Equals( + c.Name, + expression.TextValue, + StringComparison.OrdinalIgnoreCase)); + + this.DrawingContext.CraftId = matchingCraft?.NodeId ?? -1; + } break; case PositionType.PlanetPCI: case PositionType.PlanetLatLogAsl: