Beispiel #1
0
        public static void DumpCarPrefab(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;
                }

                JToken contents = GameObjectDumper.DumpObject(prefab);
                GameObjectDumper.SendJsonToFile(name, "prefab", contents);
            }
            else
            {
                Debug.LogWarning("Invalid car type " + name);
            }
        }
Beispiel #2
0
        public static void ExportInteriorColliders(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;
                }

                TrainCar car = prefab.GetComponent <TrainCar>();
                if (!car)
                {
                    Debug.LogError($"Couldn't find TrainCar on carType {name}");
                    return;
                }

                if (!car.interiorPrefab)
                {
                    Debug.LogWarning($"TrainCar on carType {name} doesn't have an interiorPrefab assigned");
                    return;
                }

                var colliderJson = GetCollidersRecursive(car.interiorPrefab.transform);
                GameObjectDumper.SendJsonToFile(name, "interior_colliders", colliderJson);
            }
        }
        private static JToken AudioPoolData(AudioPoolReferences.AudioPoolData poolData)
        {
            var prefabInfo = GameObjectDumper.DumpObject(poolData.audioPrefab);

            return(new JObject()
            {
                { "trainCarType", poolData.trainCarType.DisplayName() },
                { "poolSize", poolData.poolSize },
                { "audioPrefab", prefabInfo }
            });
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        public static void DumpTrainCar(CommandArg[] args)
        {
            TrainCar currentCar = PlayerManager.Car;

            if (currentCar == null)
            {
                Debug.Log("Player is not currently on a car");
                return;
            }

            Debug.Log($"Dumping structure of {currentCar.carType.DisplayName()}");
            var structure = GameObjectDumper.DumpObject(currentCar.gameObject);

            GameObjectDumper.SendJsonToFile(currentCar.name, "spawned", structure);
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        public static void ExportCabControls(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;
                }

                TrainCar car = prefab.GetComponent <TrainCar>();
                if (!car)
                {
                    Debug.LogError($"Couldn't find TrainCar on carType {name}");
                    return;
                }

                if (!car.interiorPrefab)
                {
                    Debug.LogWarning($"TrainCar on carType {name} doesn't have an interiorPrefab assigned");
                    return;
                }

                var specList     = new JArray();
                var controlSpecs = car.interiorPrefab.GetComponentsInChildren <ControlSpec>();
                foreach (ControlSpec spec in controlSpecs)
                {
                    specList.Add(ComponentsToJson.GenericObject(spec));
                }

                var indicators = car.interiorPrefab.GetComponentsInChildren <Indicator>();
                foreach (Indicator ind in indicators)
                {
                    specList.Add(ComponentsToJson.GenericObject(ind));
                }

                GameObjectDumper.SendJsonToFile(name, "control_spec", specList);
            }
        }
Beispiel #8
0
        public static void ExportCarColliders(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;
                }

                Transform colliderRoot = prefab.transform.Find("[colliders]");
                if (!colliderRoot)
                {
                    Debug.LogWarning($"CarType {name} does not have a colliders root transform");
                    return;
                }

                var colliderDict = new JObject();

                foreach (string categoryName in colliderCategories)
                {
                    Transform subTransform = colliderRoot.Find(categoryName);
                    if (subTransform)
                    {
                        Collider[] colliders = subTransform.gameObject.GetComponentsInChildren <Collider>();

                        var colliderCategory = ComponentsToJson.Colliders(colliders);
                        colliderDict.Add(new JProperty(categoryName, colliderCategory));
                    }
                }

                GameObjectDumper.SendJsonToFile(name, "colliders", colliderDict);
            }
            else
            {
                Debug.LogWarning("Invalid car type " + name);
            }
        }
        public static void DumpComponentPools(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            JToken audioPool = ComponentsToJson.AudioPoolReferences(TrainComponentPool.Instance.audioPoolReferences);
            //JToken cargoPool = ComponentsToJson.GenericObject(TrainComponentPool.Instance.cargoPoolReferences.poolData);

            var output = new JObject()
            {
                new JProperty("audioPool", audioPool),
                //new JProperty("cargoPool", cargoPool)
            };

            GameObjectDumper.SendJsonToFile("TrainComponentPool", "members", output);
        }
Beispiel #10
0
        public static void DumpObjStructure(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            string name = args[0].String;

            var gameObj = GameObject.Find(name);

            if (gameObj == null)
            {
                Debug.LogWarning("Couldn't find object " + name);
                return;
            }

            var contents = GameObjectDumper.DumpObject(gameObj);

            GameObjectDumper.SendJsonToFile(name, "object", contents);
        }
Beispiel #11
0
        public static void DumpCarInterior(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;
                }

                TrainCar car = prefab.GetComponent <TrainCar>();
                if (!car)
                {
                    Debug.LogError($"Couldn't find TrainCar on carType {name}");
                    return;
                }

                if (!car.interiorPrefab)
                {
                    Debug.LogWarning($"TrainCar on carType {name} doesn't have an interiorPrefab assigned");
                    return;
                }

                JToken contents = GameObjectDumper.DumpObject(car.interiorPrefab);
                GameObjectDumper.SendJsonToFile(name, "interior", contents);
            }
            else
            {
                Debug.LogWarning("Invalid car type " + name);
            }
        }