コード例 #1
0
        /// <summary>
        /// Writes out a mapdecal config
        /// </summary>
        /// <param name="instance"></param>
        internal static void SaveMapDecalInstance(MapDecalInstance instance)
        {
            if (!Directory.Exists(KSPUtil.ApplicationRootPath + "GameData/" + KerbalKonstructs.newInstancePath))
            {
                Directory.CreateDirectory(KSPUtil.ApplicationRootPath + "GameData/" + KerbalKonstructs.newInstancePath);
            }

            if (instance.configPath == null)
            {
                instance.configPath = KerbalKonstructs.newInstancePath + "/KK_MapDecal_" + instance.Name + ".cfg";
                if (System.IO.File.Exists(instance.configPath))
                {
                    instance.configPath = KerbalKonstructs.newInstancePath + "/KK_MapDecal_" + instance.Name + "_" + Guid.NewGuid() + ".cfg";
                }
            }

            ConfigNode masterNode   = new ConfigNode("");
            ConfigNode instanceNode = new ConfigNode("KK_MapDecal");

            WriteMapDecalConfig(instance, instanceNode);

            masterNode.AddNode(instanceNode);

            masterNode.Save(KSPUtil.ApplicationRootPath + "GameData/" + instance.configPath, "Generated by Kerbal Konstructs");
        }
コード例 #2
0
 /// <summary>
 /// Writer for MapDecalObjects
 /// </summary>
 /// <param name="mapDecalInstance"></param>
 /// <param name="cfgNode"></param>
 internal static void WriteMapDecalConfig(MapDecalInstance mapDecalInstance, ConfigNode cfgNode)
 {
     foreach (var mapDecalSetting in ConfigUtil.mapDecalFields)
     {
         if (mapDecalSetting.Value.GetValue(mapDecalInstance) != null)
         {
             ConfigUtil.Write2CfgNode(mapDecalInstance, mapDecalSetting.Value, cfgNode);
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Removes a Instance from the group and instance lists.
        /// </summary>
        /// <param name="instance"></param>
        internal static void DeleteMapDecalInstance(MapDecalInstance instance)
        {
            if (_allMapDecalInstances.Contains(instance))
            {
                _allMapDecalInstances.Remove(instance);
                allMapDecalInstances = _allMapDecalInstances.ToArray();
                Log.Debug("MapDecal instace " + instance.Name + " removed from Database");

                System.IO.File.Delete(KSPUtil.ApplicationRootPath + "GameData/" + instance.configPath);
            }
        }
コード例 #4
0
        /// <summary>
        /// Parser for MapDecalInstance Objects
        /// </summary>
        /// <param name="target"></param>
        /// <param name="cfgNode"></param>
        internal static void ParseMapDecalConfig(MapDecalInstance target, ConfigNode cfgNode)
        {
            if (!ConfigUtil.initialized)
            {
                ConfigUtil.InitTypes();
            }

            foreach (var field in ConfigUtil.mapDecalFields.Values)
            {
                ConfigUtil.ReadCFGNode(target, field, cfgNode);
            }
        }
コード例 #5
0
        /// <summary>
        /// Loads all KK_MAPDecals and places them on the planets
        /// </summary>
        internal static void LoadAllMapDecals()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("KK_MapDecal");

            foreach (UrlDir.UrlConfig conf in configs)
            {
                //create new Instance and Register in Database
                MapDecalInstance newMapDecalInstance = new MapDecalInstance();
                // Load Settings into instance
                ConfigParser.ParseMapDecalConfig(newMapDecalInstance, conf.config);
                // set the configpath for saving
                newMapDecalInstance.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
            }

            HashSet <CelestialBody> bodies2Update = new HashSet <CelestialBody>();

            // remove all instances where no planet was assigned
            foreach (MapDecalInstance instance in DecalsDatabase.allMapDecalInstances)
            {
                if (instance.CelestialBody == null)
                {
                    Log.Normal("No valid CelestialBody found: removing MapDecal instance " + instance.configPath);
                    DecalsDatabase.DeleteMapDecalInstance(instance);
                    continue;
                }
                else
                {
                    //Log.Normal("Loaded MapDecal instance " + instance.Name);
                    if (!bodies2Update.Contains(instance.CelestialBody))
                    {
                        bodies2Update.Add(instance.CelestialBody);
                    }


                    instance.mapDecal.transform.position = instance.CelestialBody.GetWorldSurfacePosition(instance.Latitude, instance.Longitude, instance.AbsolutOffset);
                    instance.mapDecal.transform.up       = instance.CelestialBody.GetSurfaceNVector(instance.Latitude, instance.Longitude);

                    instance.Update(false);

                    instance.Group = DecalsDatabase.GetCloesedCenter(instance.mapDecal.transform.position).Group;
                }
            }
            // Rebuild spheres on all plants with new MapDecals
            foreach (CelestialBody body in bodies2Update)
            {
                Log.Normal("Rebuilding PQS sphere on: " + body.name);
                body.pqsController.RebuildSphere();
            }
        }
コード例 #6
0
        internal static MapDecalInstance SpawnNewDecalInstance()
        {
            MapDecalInstance newMapDecal = new MapDecalInstance();

            newMapDecal.CelestialBody     = FlightGlobals.currentMainBody;
            newMapDecal.mapDecal.position = FlightGlobals.currentMainBody.transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position);

            newMapDecal.mapDecal.transform.position = FlightGlobals.ActiveVessel.transform.position;

            double lat, lon, alt;


            FlightGlobals.currentMainBody.GetLatLonAlt(FlightGlobals.ActiveVessel.transform.position, out lat, out lon, out alt);

            newMapDecal.Latitude              = lat;
            newMapDecal.Longitude             = lon;
            newMapDecal.AbsolutOffset         = (float)alt;
            newMapDecal.mapDecal.transform.up = FlightGlobals.currentMainBody.GetSurfaceNVector(lat, lon);

            //Log.Normal("New MapDecalInstance created");
            return(newMapDecal);
        }
コード例 #7
0
 /// <summary>
 /// Adds the Instance to the instances and Group lists. Also sets the PQSCity.name
 /// </summary>
 /// <param name="instance"></param>
 internal static void RegisterMapDecalInstance(MapDecalInstance instance)
 {
     _allMapDecalInstances.Add(instance);
     allMapDecalInstances = _allMapDecalInstances.ToArray();
 }