Exemple #1
0
        public static void ExportLocoControllerCurves(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            string name = args[0].String;

            if (Enum.TryParse(name, out TrainCarType carType))
            {
                GameObject prefab = CarTypes.GetCarPrefab(carType);
                if (!prefab)
                {
                    Debug.LogError($"CarType {name} has missing prefab");
                    return;
                }

                LocoControllerBase locoController = prefab.GetComponent <LocoControllerBase>();
                if (!locoController)
                {
                    Debug.LogWarning($"CarType {name} prefab does not have a loco controller");
                    return;
                }

                var props = new JObject();

                // brake & traction
                JObject brakeCurve = ComponentsToJson.AnimationCurve(locoController.brakePowerCurve);
                props.Add("brakePowerCurve", brakeCurve);

                if (locoController is LocoControllerDiesel lcd)
                {
                    var tractionCurve = ComponentsToJson.AnimationCurve(lcd.tractionTorqueCurve);
                    props.Add("tractionTorqueCurve", tractionCurve);
                }
                else if (locoController is LocoControllerSteam lcs)
                {
                    var tractionCurve = ComponentsToJson.AnimationCurve(lcs.tractionTorqueCurve);
                    props.Add("tractionTorqueCurve", tractionCurve);
                }
                else if (locoController is LocoControllerShunter lcShunt)
                {
                    var tractionCurve = ComponentsToJson.AnimationCurve(lcShunt.tractionTorqueCurve);
                    props.Add("tractionTorqueCurve", tractionCurve);
                }

                // driving force
                props.Add("drivingForce", ComponentsToJson.DrivingForce(locoController.drivingForce));

                GameObjectDumper.SendJsonToFile(name, "loco_curves", props);
            }
        }
Exemple #2
0
        public static void ExportDamageProperties(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            string name = args[0].String;

            if (Enum.TryParse(name, out TrainCarType carType))
            {
                GameObject prefab = CarTypes.GetCarPrefab(carType);
                if (!prefab)
                {
                    Debug.LogError($"CarType {name} has missing prefab");
                    return;
                }

                var damage = prefab.GetComponent <DamageController>();
                if (!damage)
                {
                    Debug.LogWarning($"CarType {name} prefab does not have a damage controller");
                    return;
                }

                var ctrlProps = new JObject
                {
                    { "wheelsHP", damage.wheels.fullHitPoints },
                    { "speedToBrakeDamageCurve", ComponentsToJson.AnimationCurve(damage.speedToBrakeDamageCurve) },
                };

                if (damage is DamageControllerDiesel dcd)
                {
                    ctrlProps.Add("engineHP", dcd.engine.fullHitPoints);
                }
                else if (damage is DamageControllerShunter dcs)
                {
                    ctrlProps.Add("engineHP", dcs.engine.fullHitPoints);
                }

                if (TrainCarAndCargoDamageProperties.carDamageProperties.TryGetValue(carType, out CarDamageProperties dmgProps))
                {
                    ctrlProps.Add("bodyDamage", ComponentsToJson.CarDamageProperties(dmgProps));
                }

                GameObjectDumper.SendJsonToFile(name, "damage", ctrlProps);
            }
        }