private static void OnPQSLoaderPostApply(PQSLoader pqs, ConfigNode node) { // You need to pay for rocks if (!ExpansionsLoader.IsExpansionInstalled("Serenity")) { return; } PQSROCControl rockController = pqs.Value.GetComponentInChildren <PQSROCControl>(); if (!rockController) { GameObject rockControllerObject = new GameObject("My rocks are bigger than yours."); rockController = rockControllerObject.AddComponent <PQSROCControl>(); rockController.sphere = pqs.Value; rockController.modEnabled = true; rockController.order = 987654321; rockController.transform.parent = rockController.sphere.transform; rockController.rocs = new List <LandClassROC>(); } // We support modding rockController.currentCBName = pqs.Value.name; }
public PQSLoader(CelestialBody body) { // Is this a spawned body? if (body.scaledBody == null || Injector.IsInPrefab) { throw new InvalidOperationException("The body must be already spawned by the PSystemManager."); } if (body.pqsController != null) { // Save the PQSVersion Value = body.pqsController; // Get the required PQS information _transform = Utility.GetMod <PQSMod_CelestialBodyTransform>(Value); _collider = Utility.GetMod <PQSMod_QuadMeshColliders>(Value); } else { // Create a new PQS GameObject controllerRoot = new GameObject(); controllerRoot.transform.parent = body.transform; Value = controllerRoot.AddComponent <PQS>(); PSystemBody laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(laythe.pqsVersion, Value); // Create the fallback material (always the same shader) FallbackMaterial = new PQSProjectionFallbackLoader(); // Create the celestial body transform _transform = Utility.AddMod <PQSMod_CelestialBodyTransform>(Value, 10); _transform.forceActivate = false; _transform.deactivateAltitude = 115000; _transform.forceRebuildOnTargetChange = false; _transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade { fadeFloatName = "_PlanetOpacity", fadeStart = 100000.0f, fadeEnd = 110000.0f, valueStart = 0.0f, valueEnd = 1.0f, secondaryRenderers = new List <GameObject>() }; _transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; // Crete the quad mesh colliders _collider = Utility.AddMod <PQSMod_QuadMeshColliders>(Value, 100); _collider.maxLevelOffset = 0; // Create the material direction Utility.AddMod <PQSMod_MaterialSetDirection>(Value, 100).valueName = "_sunLightDirection"; // Create the UV planet relative position Utility.AddMod <PQSMod_UVPlanetRelativePosition>(Value, 999999); } // Assigning the new PQS body.pqsController = Value; Transform transform = body.transform; body.pqsController.name = transform.name; body.pqsController.transform.name = transform.name; body.pqsController.gameObject.name = transform.name; body.pqsController.radius = body.Radius; // Add an OnDemand Handler if (!Utility.HasMod <PQSMod_OnDemandHandler>(Value)) { Utility.AddMod <PQSMod_OnDemandHandler>(Value, 0); } // Add fixes for LandControl and TextureAtlas if (!Utility.HasMod <PQSLandControlFixer>(Value)) { Utility.AddMod <PQSLandControlFixer>(Value, 0); } #if (KSP_VERSION_1_9_1 || KSP_VERSION_1_10_1 || KSP_VERSION_1_11_1) if (!Utility.HasMod <PQSMod_TextureAtlasFixer>(Value)) { Utility.AddMod <PQSMod_TextureAtlasFixer>(Value, 0); } #endif // Add the PQSROCControl mod for surface anomalies if (!Utility.HasMod <PQSROCControl>(Value)) { PQSROCControl roc = Utility.AddMod <PQSROCControl>(Value, 999999); roc.rocs = new List <LandClassROC>(); roc.currentCBName = Value.name; } else { PQSROCControl roc = Utility.GetMod <PQSROCControl>(Value); roc.currentCBName = Value.name; } // Load existing mods PQSMod[] mods = Utility.GetMods <PQSMod>(Value); for (Int32 i = 0; i < mods.Length; i++) { Type modType = mods[i].GetType(); Type modLoaderType = typeof(ModLoader <>).MakeGenericType(modType); for (Int32 j = 0; j < Parser.ModTypes.Count; j++) { if (!modLoaderType.IsAssignableFrom(Parser.ModTypes[j])) { continue; } IModLoader loader = (IModLoader)Activator.CreateInstance(Parser.ModTypes[j]); loader.Create(mods[i], Value); Mods.Add(loader); } } }
/// <summary> /// Creates a new PQS Loader from the Injector context. /// </summary> public PQSLoader() { // Is this the parser context? if (!Injector.IsInPrefab) { throw new InvalidOperationException("Must be executed in Injector context."); } if (generatedBody.pqsVersion != null) { // Save the PQSVersion Value = generatedBody.pqsVersion; // Get the required PQS information _transform = Utility.GetMod <PQSMod_CelestialBodyTransform>(Value); _collider = Utility.GetMod <PQSMod_QuadMeshColliders>(Value); } else { // Create a new PQS GameObject controllerRoot = new GameObject(); controllerRoot.transform.parent = generatedBody.celestialBody.transform; Value = controllerRoot.AddComponent <PQS>(); // I (Teknoman) am at this time unable to determine some of the magic parameters which cause the PQS to work... // And I (Thomas) am at this time just too lazy to do it differently... PSystemBody laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(laythe.pqsVersion, Value); // Create the fallback material (always the same shader) FallbackMaterial = new PQSProjectionFallbackLoader(); // Create the celestial body transform _transform = Utility.AddMod <PQSMod_CelestialBodyTransform>(Value, 10); _transform.forceActivate = false; _transform.deactivateAltitude = 115000; _transform.forceRebuildOnTargetChange = false; _transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade { fadeFloatName = "_PlanetOpacity", fadeStart = 100000.0f, fadeEnd = 110000.0f, valueStart = 0.0f, valueEnd = 1.0f, secondaryRenderers = new List <GameObject>() }; _transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; // Crete the quad mesh colliders _collider = Utility.AddMod <PQSMod_QuadMeshColliders>(Value, 100); _collider.maxLevelOffset = 0; // Create the material direction Utility.AddMod <PQSMod_MaterialSetDirection>(Value, 100).valueName = "_sunLightDirection"; // Create the UV planet relative position Utility.AddMod <PQSMod_UVPlanetRelativePosition>(Value, 999999); } // Assigning the new PQS generatedBody.pqsVersion = Value; generatedBody.pqsVersion.name = generatedBody.name; generatedBody.pqsVersion.transform.name = generatedBody.name; generatedBody.pqsVersion.gameObject.name = generatedBody.name; generatedBody.pqsVersion.radius = generatedBody.celestialBody.Radius; generatedBody.celestialBody.pqsController = generatedBody.pqsVersion; // Add an OnDemand Handler if (!Utility.HasMod <PQSMod_OnDemandHandler>(Value)) { Utility.AddMod <PQSMod_OnDemandHandler>(Value, 0); } // Add fixes for LandControl and TextureAtlas if (!Utility.HasMod <PQSLandControlFixer>(Value)) { Utility.AddMod <PQSLandControlFixer>(Value, 0); } #if (KSP_VERSION_1_9_1 || KSP_VERSION_1_10_1 || KSP_VERSION_1_11_1) if (!Utility.HasMod <PQSMod_TextureAtlasFixer>(Value)) { Utility.AddMod <PQSMod_TextureAtlasFixer>(Value, 0); } #endif // hacky hack if (generatedBody.celestialBody.isHomeWorld && Value.gameObject.GetChild("KSC") == null) { PSystemBody kerbinTemplate = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Kerbin"); GameObject scTree = kerbinTemplate.pqsVersion.gameObject.GetChild("KSC"); GameObject newScTree = Object.Instantiate(scTree, Value.transform, true); newScTree.transform.localPosition = scTree.transform.localPosition; newScTree.transform.localScale = scTree.transform.localScale; newScTree.transform.localRotation = scTree.transform.localRotation; newScTree.name = "KSC"; } // Add the PQSROCControl mod for surface anomalies if (!Utility.HasMod <PQSROCControl>(Value)) { PQSROCControl roc = Utility.AddMod <PQSROCControl>(Value, 999999); roc.rocs = new List <LandClassROC>(); roc.currentCBName = Value.name; } else { PQSROCControl roc = Utility.GetMod <PQSROCControl>(Value); roc.currentCBName = Value.name; } // Load existing mods PQSMod[] mods = Utility.GetMods <PQSMod>(Value); for (Int32 i = 0; i < mods.Length; i++) { Type modType = mods[i].GetType(); Type modLoaderType = typeof(ModLoader <>).MakeGenericType(modType); for (Int32 j = 0; j < Parser.ModTypes.Count; j++) { if (!modLoaderType.IsAssignableFrom(Parser.ModTypes[j])) { continue; } IModLoader loader = (IModLoader)Activator.CreateInstance(Parser.ModTypes[j]); loader.Create(mods[i], Value); Mods.Add(loader); } } }