Skip to content

Commit

Permalink
Made it possible to specify a craft by name instead of just id.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Wheeler committed Aug 15, 2020
1 parent 31b8123 commit 321cbb5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Assets/Scripts/Vizzy/SetContextPropertyInstruction.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 321cbb5

Please sign in to comment.