示例#1
0
            public LaunchConfig(string craftDirectory, string name, string launchSite, bool recover)
            {
                LaunchSite = launchSite;
                Recover    = recover;
                // Load the vessel and its default crew
                if (craftDirectory == "VAB")
                {
                    EditorDriver.editorFacility = EditorFacility.VAB;
                }
                else if (craftDirectory == "SPH")
                {
                    EditorDriver.editorFacility = EditorFacility.SPH;
                }
                else
                {
                    throw new ArgumentException("Invalid craftDirectory, should be VAB or SPH");
                }
                Path     = ShipConstruction.GetSavePath(name);
                template = ShipConstruction.LoadTemplate(Path);
                if (template == null)
                {
                    throw new InvalidOperationException("Failed to load template for vessel");
                }
                manifest = HighLogic.CurrentGame.CrewRoster.DefaultCrewForVessel(
                    template.config, VesselCrewManifest.FromConfigNode(template.config));

                facility      = (craftDirectory == "SPH") ? SpaceCenterFacility.SpaceplaneHangar : SpaceCenterFacility.VehicleAssemblyBuilding;
                facilityLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(facility);
                site          = (launchSite == "Runway") ? SpaceCenterFacility.Runway : SpaceCenterFacility.LaunchPad;
                siteLevel     = ScenarioUpgradeableFacilities.GetFacilityLevel(site);
                isPad         = (site == SpaceCenterFacility.LaunchPad);
            }
示例#2
0
        public static CraftTemplate GetTemplateByName(string name, string facility)
        {
            if (string.IsNullOrEmpty(facility))
            {
                facility = "<empty>";
            }
            if (!string.IsNullOrEmpty(name))
            {
                switch (facility.ToLower())
                {
                case ("vab"):
                    EditorDriver.editorFacility = EditorFacility.VAB;
                    break;

                case ("sph"):
                    EditorDriver.editorFacility = EditorFacility.SPH;
                    break;

                default:
                    throw new KOSException("Failed to load craft.  Facility " + facility + " not recognized, expected \"VAB\" or \"SPH\"");
                }
                var path     = ShipConstruction.GetSavePath(name);
                var template = ShipConstruction.LoadTemplate(path);
                if (template == null)
                {
                    throw new KOSException("Failed to load craft named \"" + name + "\" from given path:\n  " + path);
                }
                return(new CraftTemplate(path, template));
            }
            throw new KOSException("Failed to load craft named " + name + " from facility " + facility);
        }
        public void RefreshSubassemblies()
        {
            subs.Clear();
            buttons.Clear();
            var path = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/Subassemblies/";

            Directory.CreateDirectory(path);
            var directoryInfo = new DirectoryInfo(path);

            FileInfo[] files = directoryInfo.GetFiles("*.craft");
            for (int i = 0, len = files.Length; i < len; i++)
            {
                var sub = ShipConstruction.LoadTemplate(files[i].FullName);
                if (sub == null || sub.partCount == 0 || !sub.shipPartsUnlocked)
                {
                    continue;
                }
                var label = string.Format("<color=yellow><b>{0}</b></color>\n" +
                                          "<color=silver>mass:</color> {1:F1}t " +
                                          "<color=silver>cost:</color> {2:F0} " +
                                          "<color=silver>size:</color> {3}",
                                          sub.shipName, sub.totalMass, sub.totalCost,
                                          Utils.formatDimensions(sub.GetShipSize()));
                var button = string.IsNullOrEmpty(sub.shipDescription)? new GUIContent(label) : new GUIContent(label, sub.shipDescription);
                buttons.Add(button);
                subs.Add(sub);
            }
        }
示例#4
0
        public static ListValue GetAllTemplates()
        {
            ListValue ret   = new ListValue();
            var       files = GetAllPathStrings();

            foreach (string path in files)
            {
                var template = ShipConstruction.LoadTemplate(path);
                if (template != null)
                {
                    ret.Add(new CraftTemplate(path, template));
                }
            }
            return(ret);
        }
示例#5
0
        // public void Update(); declared in SaveManager.cs

        public static bool LoadSelectedShip(CraftBrowser.LoadType t)
        {
            if (selectedShip == null)
            {
                return(false);
            }
            if (t == CraftBrowser.LoadType.Normal)
            {
                EditorLogic.LoadShipFromFile(selectedShip.file.FullName);
            }
            else if (EditorLogic.RootPart == null)
            {
                return(false);
            }
            else
            {
                //ShipConstruction.LoadSubassembly(selectedShip.file.FullName);
                EditorLogic.fetch.SpawnTemplate(ShipConstruction.LoadTemplate(selectedShip.file.FullName));
            }
            return(true);
        }
示例#6
0
        static void ReadAllCraftFiles(string editorFacility, string shipDirectory)
        {
            foreach (var craftFile in Directory.GetFiles(shipDirectory, "*.craft"))
            {
                try
                {
                    string validFileName = Path.GetFileNameWithoutExtension(craftFile);
                    if (validFileName == "Auto-Saved Ship")
                    {
                        continue;                                     // Skip these, they would lead to duplicates, we only use finished crafts.
                    }
                    var cachedTemplate = new CachedShipTemplate();
                    switch (editorFacility)
                    {
                    case "VAB": cachedTemplate.templateOrigin = TemplateOrigin.VAB; break;

                    case "SPH": cachedTemplate.templateOrigin = TemplateOrigin.SPH; break;

                    case "Subassemblies": cachedTemplate.templateOrigin = TemplateOrigin.SubAssembly; break;
                    }

                    cachedTemplate.template = ShipConstruction.LoadTemplate(craftFile);

                    if (cachedTemplate.template == null)
                    {
                        continue;
                    }
                    if (cachedTemplate.template.shipPartsExperimental || !cachedTemplate.template.shipPartsUnlocked)
                    {
                        continue;                                                                                              // We won't bother with ships we can't use anyways.
                    }
                    // Try to load the thumbnail for this craft:
                    var thumbFile = KSPUtil.ApplicationRootPath + "thumbs/" + HighLogic.SaveFolder + "_" + editorFacility + "_" + validFileName + ".png";

                    Texture2D thumbnail;

                    //
                    // Make the thumbnail file if it doesn't exist.
                    // Needed for the subassemblies, will also replace any missing thumbnail files for regular craft
                    //
                    if (!HighLogic.LoadedSceneIsFlight)
                    {
                        if (!File.Exists(thumbFile))
                        {
                            Log.Info("Missing Thumbfile: " + thumbFile);
                            ShipConstruct ship = ShipConstruction.LoadShip(craftFile);
                            ThumbnailHelper.CaptureThumbnail(ship, 256, "thumbs/", HighLogic.SaveFolder + "_" + editorFacility + "_" + validFileName);
                        }
                    }

                    bool placeholder = false;
                    if (File.Exists(thumbFile))
                    {
                        thumbnail = new Texture2D(256, 256, TextureFormat.RGBA32, false);
                        thumbnail.LoadImage(File.ReadAllBytes(thumbFile));
                    }
                    else
                    {
                        thumbnail   = placeholderImage;
                        placeholder = true;
                    }

                    // The thumbnails are rather large, so we have to resize them first:
                    cachedTemplate.thumbnail = GUI.ResizeTexture(thumbnail, 64, 64);
                    if (!placeholder)
                    {
                        Destroy(thumbnail);
                    }
                    GUI.shipTemplates.Add(cachedTemplate);
                }
                catch (Exception e)
                {
                    Debug.LogError("UpdateShipTemplateCache() processing '" + craftFile + "': " + e.ToString());
                }
            }
        }
示例#7
0
 public CraftTemplate(string filePath)
     : this(filePath, ShipConstruction.LoadTemplate(filePath))
 {
 }
示例#8
0
文件: GUI.cs 项目: MrKiel/KSTS
        // Updates the cache we use to store the meta-data of the various ships the player has designed:
        public static void UpdateShipTemplateCache()
        {
            if (GUI.shipTemplates == null)
            {
                GUI.shipTemplates = new List <CachedShipTemplate>();
            }
            string[] editorFacilities = { "VAB", "SPH" }; // This is usually an enum, but we need the string later.
            GUI.shipTemplates.Clear();

            foreach (string editorFacility in editorFacilities)
            {
                string shipDirectory = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/Ships/" + editorFacility; // Directory where the crafts are stored for the current game.
                if (!Directory.Exists(shipDirectory))
                {
                    continue;
                }

                // Get all crafts the player has designed in this savegame:
                foreach (string craftFile in Directory.GetFiles(shipDirectory, "*.craft"))
                {
                    try
                    {
                        if (Path.GetFileNameWithoutExtension(craftFile) == "Auto-Saved Ship")
                        {
                            continue;                                                                   // Skip these, they would lead to duplicates, we only use finished crafts.
                        }
                        CachedShipTemplate cachedTemplate = new CachedShipTemplate();

                        cachedTemplate.template = ShipConstruction.LoadTemplate(craftFile);
                        if (cachedTemplate.template == null)
                        {
                            continue;
                        }
                        if (cachedTemplate.template.shipPartsExperimental || !cachedTemplate.template.shipPartsUnlocked)
                        {
                            continue;                                                                                              // We won't bother with ships we can't use anyways.
                        }
                        // Try to load the thumbnail for this craft:
                        string    thumbFile = KSPUtil.ApplicationRootPath + "/thumbs/" + HighLogic.SaveFolder + "_" + editorFacility + "_" + cachedTemplate.template.shipName + ".png";
                        Texture2D thumbnail;
                        if (File.Exists(thumbFile))
                        {
                            thumbnail = new Texture2D(256, 256, TextureFormat.RGBA32, false);
                            thumbnail.LoadImage(File.ReadAllBytes(thumbFile));
                        }
                        else
                        {
                            thumbnail = placeholderImage;
                        }

                        // The thumbnails are rather large, so we have to resize them first:
                        cachedTemplate.thumbnail = GUI.ResizeTexture(thumbnail, 64, 64);

                        GUI.shipTemplates.Add(cachedTemplate);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("[KSTS] UpdateShipTemplateCache() processing '" + craftFile + "': " + e.ToString());
                    }
                }
            }

            GUI.shipTemplates.Sort((x, y) => x.template.shipName.CompareTo(y.template.shipName));
        }