public override void AddTo(SharedObjects shared) { _shared = shared; _shared.BindingMgr.AddSetter("TARGET", delegate(CPU cpu, object val) { if (val is ITargetable) { VesselUtils.SetTarget((ITargetable)val); } else if (val is VesselTarget) { VesselUtils.SetTarget(((VesselTarget)val).target); } else if (val is BodyTarget) { VesselUtils.SetTarget(((BodyTarget)val).target); } else { var body = VesselUtils.GetBodyByName(val.ToString()); if (body != null) { VesselUtils.SetTarget(body); return; } var vessel = VesselUtils.GetVesselByName(val.ToString(), _shared.Vessel); if (vessel != null) { VesselUtils.SetTarget(vessel); return; } } }); _shared.BindingMgr.AddGetter("TARGET", delegate(CPU cpu) { var currentTarget = FlightGlobals.fetch.VesselTarget; if (currentTarget is Vessel) { return(new VesselTarget((Vessel)currentTarget, _shared.Vessel)); } else if (currentTarget is CelestialBody) { return(new BodyTarget((CelestialBody)currentTarget, _shared.Vessel)); } return(null); }); }
public override void AddTo(BindingManager manager) { manager.AddSetter("TARGET", delegate(CPU cpu, object val) { if (val is ITargetable) { VesselUtils.SetTarget((ITargetable)val); } else if (val is VesselTarget) { VesselUtils.SetTarget(((VesselTarget)val).target); } else { var vessel = VesselUtils.GetVesselByName(val.ToString(), cpu.Vessel); VesselUtils.SetTarget(vessel); } }); manager.AddGetter("TARGET", delegate(CPU cpu) { return(new VesselTarget((Vessel)FlightGlobals.fetch.VesselTarget, cpu)); }); }