Exemple #1
0
        static void Postfix(LocoControllerBase __instance)
        {
            // use switch on fireman's side of cab instead of reverser for steam loco
            if (__instance.train.carType == TrainCarType.LocoSteamHeavy)
            {
                return;
            }

            LocoLights locoLights = __instance.train.transform.gameObject.GetComponent <LocoLights>();

            if (locoLights == null)
            {
                return;
            }

            locoLights.SetDirection(__instance.reverser);
        }
        static IEnumerator AttachListeners()
        {
            yield return(null);

            var light_switch = GameObjectUtils.FindObject(instance.transform.gameObject, "C light lever");

            DV.CabControls.ControlImplBase lightCtrl = light_switch
                                                       .gameObject.GetComponent <DV.CabControls.ControlImplBase>();

            if (PlayerManager.Car.carType == TrainCarType.LocoSteamHeavy)
            {
                locoLights = PlayerManager.Car.GetComponent <LocoLights>();
            }

            var isInitialized = Traverse.Create(lightCtrl).Field("isInitialized");

            Main.Log("pausing until Lever is initialized");
            while (!isInitialized.GetValue <bool>())
            {
                yield return(null);
            }
            Main.Log("Lever is initialized; resuming");

            if (locoLights != null)
            {
                float position = DirectionToLeverPosition(locoLights.IsOn ? locoLights.Direction : 0f);
                lightCtrl.SetValue(position);
            }

            lightCtrl.ValueChanged += (e =>
            {
                if (locoLights != null)
                {
                    float direction = LeverPositionToDirection(e.newValue);
                    locoLights.SetLights(Mathf.Abs(direction) > 0.25f);
                    locoLights.SetDirection(Mathf.Abs(direction) > 0.75f ? direction : 0f);
                }
            });
        }