public void CreatePreviewInstance(StaticModel model)
        {
            StaticObject obj = new StaticObject();
            obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));
            obj.setSetting("RadiusOffset", (float)FlightGlobals.ActiveVessel.altitude);
            obj.setSetting("CelestialBody", KerbalKonstructs.instance.getCurrentBody());
            obj.setSetting("Group", "Ungrouped");
            obj.setSetting("RadialPosition", KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position));
            obj.setSetting("RotationAngle", 0f);
            obj.setSetting("Orientation", Vector3.up);
            obj.setSetting("VisibilityRange", 25000f);

            obj.model = model;

            KerbalKonstructs.instance.getStaticDB().addStatic(obj);
            obj.spawnObject(true, true);
            // KerbalKonstructs.instance.selectObject(obj, false);
            currPreview = obj;
        }
        public void loadObjects()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");

            foreach(UrlDir.UrlConfig conf in configs)
            {
                StaticModel model = new StaticModel();
                model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
                model.config = conf.url;
                model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
                model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

                if (model.settings.ContainsKey("LocalToSave"))
                {
                    if ((string)model.getSetting("LocalToSave") == "True")
                        continue;
                    // Ignore it for second pass
                }

                /* if (model.settings.ContainsKey("mesh"))
                {
                    string sMesh = (string)model.getSetting("mesh");
                    if (sMesh.Contains(".mu"))
                    {}
                    else
                    {
                        Debug.Log("KK: mesh name missing suffix. Adding it.");
                        sMesh = sMesh + ".mu";
                        model.setSetting("mesh", sMesh);
                    }
                } */

                if (model.settings.ContainsKey("pointername"))
                {
                    if ((string)model.getSetting("pointername") != "None")
                        continue;
                    // Ignore it for second pass
                }

                foreach (ConfigNode ins in conf.config.GetNodes("MODULE"))
                {
                    StaticModule module = new StaticModule();
                    foreach (ConfigNode.Value value in ins.values)
                    {
                        switch (value.name)
                        {
                            case "namespace":
                                module.moduleNamespace = value.value;
                                break;
                            case "name":
                                module.moduleClassname = value.value;
                                break;
                            default:
                                module.moduleFields.Add(value.name, value.value);
                                break;
                        }
                    }
                    model.modules.Add(module);
                }

                loadInstances(conf.config, model);

                staticDB.registerModel(model);
            }
        }
        public void loadInstances(ConfigNode confconfig, StaticModel model, bool bSecondPass = false)
        {
            if (model == null)
            {
                Debug.Log("KK: Attempting to loadInstances for a null model. Check your model and config.");
                return;
            }

            if (confconfig == null)
            {
                Debug.Log("KK: Attempting to loadInstances for a null ConfigNode. Check your model and config.");
                return;
            }

            foreach (ConfigNode ins in confconfig.GetNodes("Instances"))
            {
                StaticObject obj = new StaticObject();
                obj.model = model;

                obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));

                if (obj.gameObject == null)
                {
                    Debug.Log("KK: Could not find " + model.getSetting("mesh") + ".mu! Did the modder forget to include it or did you actually install it?");
                    continue;
                }

                // Fix colliders
                if (!String.IsNullOrEmpty(model.getSetting("concaveColliders").ToString().Trim()))
                {
                    string value = model.getSetting("concaveColliders").ToString();
                    string[] names = value.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    MeshCollider[] colliders = obj.gameObject.GetComponentsInChildren<MeshCollider>(true);
                    MeshCollider[] concave = value.ToLower() == "all" ? colliders : colliders.Where(c => names.Contains(c.name)).ToArray();
                    foreach (MeshCollider collider in concave)
                    {
                        if (DebugMode) Debug.Log("KK: Making collider " + collider.name + " concave.");
                        collider.convex = false;
                    }
                }

                obj.settings = KKAPI.loadConfig(ins, KKAPI.getInstanceSettings());

                if (obj.settings == null)
                {
                    Debug.Log("KK: Error loading instances for " + model.getSetting("mesh") + ".mu! Check your model and config.");
                    continue;
                }

                if (bSecondPass)
                {
                    Vector3 secondInstanceKey = (Vector3)obj.getSetting("RadialPosition");
                    bool bSpaceOccupied = false;

                    foreach (StaticObject soThis in KerbalKonstructs.instance.getStaticDB().getAllStatics())
                    {
                        Vector3 firstInstanceKey = (Vector3)soThis.getSetting("RadialPosition");

                        if (firstInstanceKey == secondInstanceKey)
                        {
                            string sThisMesh = (string)soThis.model.getSetting("mesh");
                            string sThatMesh = (string)obj.model.getSetting("mesh");

                            if (DebugMode)
                                Debug.Log("KK: Custom instance has a RadialPosition that already has an instance."
                                + sThisMesh + ":"
                                + (string)soThis.getSetting("Group") + ":" + firstInstanceKey.ToString() + "|"
                                + sThatMesh + ":"
                                + (string)obj.getSetting("Group") + ":" + secondInstanceKey.ToString());

                            if (sThisMesh == sThatMesh)
                            {
                                float fThisOffset = (float)soThis.getSetting("RadiusOffset");
                                float fThatOffset = (float)obj.getSetting("RadiusOffset");
                                float fThisRotation = (float)soThis.getSetting("RotationAngle");
                                float fThatRotation = (float)obj.getSetting("RotationAngle");

                                if ((fThisOffset == fThatOffset) && (fThisRotation == fThatRotation))
                                {
                                    bSpaceOccupied = true;
                                    break;
                                }
                                else
                                {
                                    if (DebugMode) Debug.Log("KK: Different rotation or offset. Allowing. Could be a feature of the same model such as a doorway being used. Will cause z tearing probably.");
                                }
                            }
                            else
                            {
                                if (DebugMode) Debug.Log("KK: Different models. Allowing. Could be a terrain foundation or integrator.");
                            }
                        }
                    }

                    if (bSpaceOccupied)
                    {
                        Debug.Log("KK: Attempted to import identical custom instance to same RadialPosition as existing instance. Skipped. Check for duplicate custom statics you have installed. Did you export the custom instances to make a pack? If not, ask the mod-makers if they are duplicating the same stuff as each other.");
                        continue;
                    }
                }

                if (!obj.settings.ContainsKey("LaunchPadTransform") && obj.settings.ContainsKey("LaunchSiteName"))
                {
                    if (model.settings.Keys.Contains("DefaultLaunchPadTransform"))
                    {
                        obj.settings.Add("LaunchPadTransform", model.getSetting("DefaultLaunchPadTransform"));
                    }
                    else
                    {
                        Debug.Log("KK: Launch site is missing a transform. Defaulting to " + obj.getSetting("LaunchSiteName") + "_spawn...");

                        if (obj.gameObject.transform.Find(obj.getSetting("LaunchSiteName") + "_spawn") != null)
                        {
                            obj.settings.Add("LaunchPadTransform", obj.getSetting("LaunchSiteName") + "_spawn");
                        }
                        else
                        {
                            Debug.Log("KK: FAILED: " + obj.getSetting("LaunchSiteName") + "_spawn does not exist! Attempting to use any transform with _spawn in the name.");
                            Transform lastResort = obj.gameObject.transform.Cast<Transform>().FirstOrDefault(trans => trans.name.EndsWith("_spawn"));

                            if (lastResort != null)
                            {
                                Debug.Log("KK: Using " + lastResort.name + " as launchpad transform");
                                obj.settings.Add("LaunchPadTransform", lastResort.name);
                            }
                            else
                            {
                                Debug.Log("KK: All attempts at finding a launchpad transform have failed (╯°□°)╯︵ ┻━┻ This static isn't configured for KK properly. Tell the modder.");
                            }
                        }
                    }
                }

                staticDB.addStatic(obj);
                obj.spawnObject(false, false);

                if (obj.settings.ContainsKey("LaunchPadTransform") && obj.settings.ContainsKey("LaunchSiteName"))
                    LaunchSiteManager.createLaunchSite(obj);
            }
        }
        public void importCustomInstances()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");

            foreach (UrlDir.UrlConfig conf in configs)
            {
                StaticModel model = new StaticModel();
                model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
                model.config = conf.url;
                model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
                model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

                if (!model.settings.ContainsKey("pointername"))
                    continue;

                string sPointerName = (string)model.getSetting("pointername");

                foreach (StaticModel model2 in staticDB.getModels())
                {
                    ConfigNode modelConfig = GameDatabase.Instance.GetConfigNode(model2.config);

                    if ((string)modelConfig.GetValue("name") == sPointerName)
                    {
                        loadInstances(conf.config, model2, true);
                        break;
                    }
                }
            }
        }
        public StaticObject spawnInstance(StaticModel model)
        {
            StaticObject obj = new StaticObject();
            obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));
            obj.setSetting("RadiusOffset", (float)FlightGlobals.ActiveVessel.altitude);
            obj.setSetting("CelestialBody", KerbalKonstructs.instance.getCurrentBody());
            obj.setSetting("Group", "Ungrouped");
            obj.setSetting("RadialPosition", KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position));
            obj.setSetting("RotationAngle", 0f);
            obj.setSetting("Orientation", Vector3.up);
            obj.setSetting("VisibilityRange", 25000f);

            string sPad = ((string)model.getSetting("DefaultLaunchPadTransform"));
            if (sPad != null) obj.setSetting("LaunchPadTransform", sPad);

            if (!KerbalKonstructs.instance.DevMode)
            {
                obj.setSetting("CustomInstance", "True");
            }

            obj.model = model;

            KerbalKonstructs.instance.getStaticDB().addStatic(obj);
            enableColliders = false;
            obj.spawnObject(true, false);
            return obj;
        }
        public void updateSelection(StaticModel obj)
        {
            infAuthor = (string)obj.getSetting("author");
            infMesh = "" + obj.getSetting("mesh");
            infManufacturer = (string)obj.getSetting("manufacturer");
            infCost = obj.getSetting("cost").ToString();
            infDescription = (string)obj.getSetting("description");
            infTitle = (string)obj.getSetting("title");
            infCategory = (string)obj.getSetting("category");
            infLaunchTransform = (string)obj.getSetting("DefaultLaunchPadTransform");

            infLaunchLength = obj.getSetting("DefaultLaunchSiteLength").ToString();
            infLaunchWidth = obj.getSetting("DefaultLaunchSiteWidth").ToString();
            infFacType = (string)obj.getSetting("DefaultFacilityType");
            infFacLength = obj.getSetting("DefaultFacilityLength").ToString();
            infFacWidth = obj.getSetting("DefaultFacilityWidth").ToString();
            infFacHeight = obj.getSetting("DefaultFacilityHeight").ToString();
            infFacMassCap = obj.getSetting("DefaultFacilityMassCapacity").ToString();
            infFacCraftCap = obj.getSetting("DefaultFacilityCraftCapacity").ToString();
            infStaffMax = obj.getSetting("DefaultStaffMax").ToString();
            infLqFMax = obj.getSetting("LqFMax").ToString();
            infOxFMax = obj.getSetting("OxFMax").ToString();
            infMoFMax = obj.getSetting("MoFMax").ToString();
            infECMax = obj.getSetting("ECMax").ToString();
            infOreMax = obj.getSetting("OreMax").ToString();
            infPrOreMax = obj.getSetting("PrOreMax").ToString();
            infProdRateMax = obj.getSetting("DefaultProductionRateMax").ToString();
            infScienceMax = obj.getSetting("DefaultScienceOMax").ToString();
            infRepMax = obj.getSetting("DefaultRepOMax").ToString();
            infFundsMax = obj.getSetting("DefaultFundsOMax").ToString();
        }
		public void loadObjects()
		{
			UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");
			
			foreach(UrlDir.UrlConfig conf in configs)
			{
				StaticModel model = new StaticModel();
				model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
				model.config = conf.url;
				model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
				model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

				if (model.settings.ContainsKey("LocalToSave"))
				{
					if ((string)model.getSetting("LocalToSave") == "True")
					{
						// Debug.Log("KK: Static Config is local to save. Skipping model and its instances.");
						continue;
					}
				}

				foreach (ConfigNode ins in conf.config.GetNodes("MODULE"))
				{
					// Debug.Log("KK: Found module: "+ins.name+" in "+conf.name);
					StaticModule module = new StaticModule();
					foreach (ConfigNode.Value value in ins.values)
					{
						switch (value.name)
						{
							case "namespace":
								module.moduleNamespace = value.value;
								break;
							case "name":
								module.moduleClassname = value.value;
								break;
							default:
								module.moduleFields.Add(value.name, value.value);
								break;
						}
					}
					model.modules.Add(module);
					// Debug.Log("KK: Adding module");
				}

				loadInstances(conf.config, model);
				
				staticDB.registerModel(model);
			}
		}
		public void loadInstances(ConfigNode confconfig, StaticModel model)
		{
			foreach (ConfigNode ins in confconfig.GetNodes("Instances"))
			{
				// Debug.Log("KK: Loading models");
				StaticObject obj = new StaticObject();
				obj.model = model;
				obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));

				if (obj.gameObject == null)
				{
					Debug.Log("KK: Could not find " + model.getSetting("mesh") + ".mu! Did the mod forget to include it or did you actually install it?");
					continue;
				}
				// Debug.Log("KK: mesh is " + (string)model.getSetting("mesh"));

				obj.settings = KKAPI.loadConfig(ins, KKAPI.getInstanceSettings());

				if (!obj.settings.ContainsKey("LaunchPadTransform") && obj.settings.ContainsKey("LaunchSiteName"))
				{

					if (model.settings.Keys.Contains("DefaultLaunchPadTransform"))
					{
						obj.settings.Add("LaunchPadTransform", model.getSetting("DefaultLaunchPadTransform"));
					}
					else
					{
						Debug.Log("KK: Launch site is missing a transform. Defaulting to " + obj.getSetting("LaunchSiteName") + "_spawn...");

						if (obj.gameObject.transform.Find(obj.getSetting("LaunchSiteName") + "_spawn") != null)
						{
							obj.settings.Add("LaunchPadTransform", obj.getSetting("LaunchSiteName") + "_spawn");
						}
						else
						{
							Debug.Log("KK: FAILED: " + obj.getSetting("LaunchSiteName") + "_spawn does not exist! Attempting to use any transform with _spawn in the name.");
							Transform lastResort = obj.gameObject.transform.Cast<Transform>().FirstOrDefault(trans => trans.name.EndsWith("_spawn"));

							if (lastResort != null)
							{
								Debug.Log("KK: Using " + lastResort.name + " as launchpad transform");
								obj.settings.Add("LaunchPadTransform", lastResort.name);
							}
							else
							{
								Debug.Log("KK: All attempts at finding a launchpad transform have failed (╯°□°)╯︵ ┻━┻ This static isn't configured for KK properly. Tell the modder.");
							}
						}
					}
				}

				staticDB.addStatic(obj);
				spawnObject(obj, false);
				if (obj.settings.ContainsKey("LaunchSiteName"))
				{
					LaunchSiteManager.createLaunchSite(obj);
				}
			}
		}
        public void loadObjects()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");

            foreach(UrlDir.UrlConfig conf in configs)
            {
                StaticModel model = new StaticModel();
                model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
                model.config = conf.url;
                model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
                model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

                foreach (ConfigNode ins in conf.config.GetNodes("MODULE"))
                {
                    Debug.Log("KK: Found module: "+ins.name+" in "+conf.name);
                    StaticModule module = new StaticModule();
                    foreach (ConfigNode.Value value in ins.values)
                    {
                        switch (value.name)
                        {
                            case "namespace":
                                module.moduleNamespace = value.value;
                                break;
                            case "name":
                                module.moduleClassname = value.value;
                                break;
                            default:
                                module.moduleFields.Add(value.name, value.value);
                                break;
                        }
                    }
                    model.modules.Add(module);
                    Debug.Log("KK: Adding module");
                }

                foreach (ConfigNode ins in conf.config.GetNodes("Instances"))
                {
                    // Debug.Log("KK: Loading models");
                    StaticObject obj = new StaticObject();
                    obj.model = model;
                    obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));

                    if (obj.gameObject == null)
                    {
                        Debug.Log("KK: Could not find " + model.getSetting("mesh") + ".mu! Did the mod forget to include it or did you actually install it?");
                        continue;
                    }
                    // Debug.Log("KK: mesh is " + (string)model.getSetting("mesh"));

                    obj.settings = KKAPI.loadConfig(ins, KKAPI.getInstanceSettings());

                    if (!obj.settings.ContainsKey("LaunchPadTransform") && obj.settings.ContainsKey("LaunchSiteName"))
                    {

                        if (model.settings.Keys.Contains("DefaultLaunchPadTransform"))
                        {
                            obj.settings.Add("LaunchPadTransform", model.getSetting("DefaultLaunchPadTransform"));
                        }
                        else
                        {
                            Debug.Log("KK: Launch site is missing a transform. Defaulting to " + obj.getSetting("LaunchSiteName") + "_spawn...");

                            if (obj.gameObject.transform.Find(obj.getSetting("LaunchSiteName") + "_spawn") != null)
                            {
                                obj.settings.Add("LaunchPadTransform", obj.getSetting("LaunchSiteName") + "_spawn");
                            }
                            else
                            {
                                Debug.Log("KK: FAILED: " + obj.getSetting("LaunchSiteName") + "_spawn does not exist! Attempting to use any transform with _spawn in the name.");
                                Transform lastResort = obj.gameObject.transform.Cast<Transform>().FirstOrDefault(trans => trans.name.EndsWith("_spawn"));

                                if (lastResort != null)
                                {
                                    Debug.Log("KK: Using " + lastResort.name + " as launchpad transform");
                                    obj.settings.Add("LaunchPadTransform", lastResort.name);
                                }
                                else
                                {
                                    Debug.Log("KK: All attempts at finding a launchpad transform have failed (╯°□°)╯︵ ┻━┻ This static isn't configured for KK properly. Tell the modder.");
                                }
                            }
                        }
                    }

                    staticDB.addStatic(obj);
                    spawnObject(obj, false);
                    if (obj.settings.ContainsKey("LaunchSiteName"))
                    {
                        LaunchSiteManager.createLaunchSite(obj);
                    }
                }

                staticDB.registerModel(model);
            }
        }
示例#10
0
        public StaticObject spawnInstance(StaticModel model, float fOffset, Vector3 vPosition, float fAngle)
        {
            StaticObject obj = new StaticObject();
            obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));
            obj.setSetting("RadiusOffset", fOffset);
            obj.setSetting("CelestialBody", KerbalKonstructs.instance.getCurrentBody());
            obj.setSetting("Group", "Ungrouped");
            obj.setSetting("RadialPosition", vPosition);
            obj.setSetting("RotationAngle", fAngle);
            obj.setSetting("Orientation", Vector3.up);
            obj.setSetting("VisibilityRange", 25000f);
            obj.model = model;

            KerbalKonstructs.instance.getStaticDB().addStatic(obj);
            enableColliders = false;
            KerbalKonstructs.instance.spawnObject(obj, true);
            return obj;
        }
 public void updateSelection(StaticModel obj)
 {
     infAuthor = (string)obj.getSetting("author");
     infMesh = "" + obj.getSetting("mesh");
     infManufacturer = (string)obj.getSetting("manufacturer");
     infCost = obj.getSetting("cost").ToString();
     infDescription = (string)obj.getSetting("description");
     infTitle = (string)obj.getSetting("title");
     infCategory = (string)obj.getSetting("category");
 }