linuxgurugamer

[1.4.1]Craft Import released

Recommended Posts

Greetings,

 

Updated for 1.4.1

  • updated for KSP 1.4.1
  • Deleted all unused KerbalX code
  • Added support for Toolbarcontrol and ClickthrougBlocker
  • Added option to load as assembly
  • Added code to check for comment after ship name  in craft file
  • Added localizer code in case ship name is localized

This mod now depends on and requires the ToolbarController mod, available here:

This mod now depends on and requires the ClickThroughBlocker mod, available here: 

I've just released a mod I've been working on called Craft Import. It is designed to allow you to import a craft file directly into the game by either downloading from an external website or a local file.

This will make it much easier to download files from KerbalX.com, among other places, all you will need is the download URL which you can simply paste into the entry field.

Download it here: http://spacedock.info/mod/47/Craft%20Import%20%26%20Upload

License is GPLv3

 

0.1.0 initial release
0.2.0 Fixed bug where showDrives wasn't being honored, so that drives were always being shown
0.3.0 Removed unnecessary dialog for file selection
   Added initial error checking for valid craft file, more needs to be done
   Changed file selection to only show directories and craft files
   Fixed bug where after you download one file, you can't do any more. Related to unnecessary dialog
0.4.0 Added integration with KerbalX. CKan file is downloaded and saved in case the imported craft file needs additional mods to be    used, and then provides instructions on screen
0.5.0 Changed visibility to only be visible in VAB and SPHIf no http/https/file is at the beginning of the craft name, checks to see if it is    a local file. If not, it prepends "http://"
0.7.0 Added upload ability to KerbalX
   Added "OK" button in case of error, will return to GUI screen with craftURL intact for retrying
   Upload functionality + ship snapshot
   Added option to load craft after import
   Added option to copy text to clipboard
   Made Import and Upload to KerbalX buttons bigger
   Changed spacing of elements on upload screen
   Added check to see if downloaded craft has all necessary mods
   Added check for login error
   Added check to see if all parts needed are available
   Generated image is dynamically updated as values are edited.
0.7.1 Removed code which prevented destruction of data on scene load
0.8.0 1.0.5 compatibility
0.8.1 Fixed issue with lagging during flight
   Fixed locking of screen when exiting editor while settings window was open
0.8.2 Fixed a couple of null ref exceptions
Blocked KerbalX from downloads due to security problem on site
Added message about kerbalx being blocked

Kudos to SpaceTiger, who very kindly show me how to load a subassembly in the editor

Donations gratefully accepted

Patreon.png

https://www.patreon.com/linuxgurugamer

Description

This is a small mod which will allow you to download and import craft files from websites. It will take a URL, which you can get from the site and just paste it into the URL field.

Additionally, if you have craft files on your local disk, you will be able to select and import them as well.

There is an additional field available to rename the craft to a new craft name if desired. This can be useful if, for example, you already have a craft by that name and don't want to overwrite it.

Also, if you DO want to overwrite an existing file, there is a toggle field which will allow you to do that.

Finally, if you like, you can save the craft file in the sandbox directory rather than the current games's directory

Available options include the ability to use the Blizzy Toolbar if it is available, and for the file selection dialog on Windows, to show all the available drive letters. If the drive letters are not shown, then you will be limited to the drive that the game is installed on

The buttons on the main dialog consist of the following:

[TABLE=width: 500]

[TR]

[TD]Select Local File[/TD]

[TD]Open the file selection dialog[/TD]

[/TR]

[TR]

[TD]Import[/TD]

[TD]Import the craft listed in the URL field[/TD]

[/TR]

[TR]

[TD]Cancel[/TD]

[TD][/TD]

[/TR]

[/TABLE]

The toolbar icon looks like this:

CI-toolbar.png

The main dialog:

ci-pg1.png

The file selection shows the folders and files in the current directory. Only craft files and folders are selectable.

ci-pg3.png

This dialog shows what it looks like after I descended into the sandbox ships directory, in the VAB:

ci-pg4.png

and this is after I selected a craft file to import. Note that for local files, the complete file name is actually transformed into a URL by adding "file://:" in front of it.

ci-pg5.png

This is where I'm ready to download a craft file from Kerbalx.com. Note that for Kerbalx, it seems to work so that once you get to the web page of the craft you want, that using the url is sufficient, no need to copy the "Download" url

ci-pg6.png

and this is what happens when you try to overwrite a file when you didn't select the overwrite toggle:

ci-pg7.png

This is a major update to the Craft Import mod.

There are two new additions:

1. When downloading a file from KerbalX.com, it will also download a CKAN file which can be used by CKAN to install any missing mods. When you do a download, instructions will be provided after the craft file is downloaded.

2. Craft Import now has the ability to UPLOAD to KerbalX.com.

You will need a login to KerbalX in order to do this, of course.

So, here is how it works:

The Craft Import button is only available in the VAB or SPH.

Very Important: Please note, any craft you have loaded in the editor will be lost and replaced with the craft being uploaded!

On the main Craft Import screen, click the button which says "Upload to KerbalX". You will be presented with the

File Selection dialog:

ci-pg3.png

If you are in the VAB, the VAB directory of your current save will be displayed. If you are in the SPH, the SPH

directory will be shown.

Select your file, either by double-clicking or clicking one and then clicking the Select button

You will then get to the Craft Import screen:

kerbalx-1.png

There are two required fields, highlighted in yellow:

Userid This is your login id to KerbalX.com

Password This is your password to KerbalX.com

Picture URL This label is also a button. The field is a url to a previously uploaded picture of the craft.

If using Imgur, be sure to select the Direct Link url, as the others will generate an error. You can also

specify an Imgur album here. If specifying an Imgur album, you need to use one of three formats:

1. The "Share Link" from Imgur

2. the 5 character album identifier

3. The album identified surrounded by imgur tags as follows (note that there shouldn't be spaces between the brackets):

[ imgur ]12345[ /imgur ]

If you press the button, then a dialog will open up where you will be able to select a local image file (either PNG or JPG). It will initially open up in the screenshots directory of the current install.

If no picture is specified (either URL or local file), then a 1024x1024 image will be automatically generated and uploaded.

WARNING: Any images uploaded in this manner will be stored on Imgur, and will be undeletable. You will be able to replace it on the web page, but the image will stay on Imgur forever!

Generate a custom snapshot This button will bring up a dialog where you will be able to generate a snapshot of the craft with a custom background color.

There are check boxes to save both the userid and password. THESE ARE SAVED IN CLEAR TEXT! So only select them if you are comfortable with having them stored on your disk.

Other fields on the screen are:

Tags Space separated string of words used on KerbalX as ship tags

Video URL URL to a YouTube video

Action Groups This button brings up a new window where you can enter descriptions of the action groups which are set:

kerbalx-snapshot.png

The top line of this screen shows the name of the craft you are uploading.

the next set of lines control the camera:

Display Resolution This controls the size of the image window on screen.

It will never be larger than the Image Resolution. Changing this takes effect

immediately.

Image Resolution This is the final size of the picture (will be square)

The following values control the camera. The default values are set to what

KSP uses when generating a thumbnail in either the VAB or SPH, depending on

the craft. Change them slowly, one at a time to get a feel for how they work.

Elevation

Pitch

Heading

FOV Smaller values effectively moves the camera away from the ship

Next will be the background color. The label:

"Click on desired background color" will be the color of the background color

you select.

There are 4 buttons on the screen:

Generate Craft Image The image will not be generated (or regenerated) until

you click this button. When you click this for the first time, the main

window will be moved to the right edge, and the craft image will be displayed

in another window on the left side.

Reset to VAB Defaults (or SPH) This will reset the values

OK Accept this image for upload

Cancel Discard the changes

kerbalx-actiongroups.png

If the craft has a B9 info drive, this will be ignored. Right now, KerbalX only stores the standard Action Groups. If in the future KerbalX is enhanced to support the Action Groiups Extended (250 action groups), this will be mirrored in Craft Import. This i

There is a toggle which say "Force new upload (if existing)". This means that if the craft you are uploading already exists, KerbalX will create a new craft and append a number to keep them unique.

If you upload a craft which already exists and you did not select the force new upload, you will be presented with a window showing the existing craft which match what you are uploading. The middle column will be a clickable button, which will open that craft in a browser window. Once you have decided which one to replace, select the toggle in the right column and then click OK.

Special note: If you know you are going to replace an existing craft, you can instead click the button "Select Existing Craft to Replace", a list of all your existing craft will be downloaded and displayed. If you do this, then you can replace ANY of your existing craft, not just the ones which match the craft you are uploading. Once you have filled out the information, click the button "Upload to KerbalX".

The progress will be displayed in a counter. When completed, the results will be displayed. If it was a successful upload, a browser window will be opened to allow you to do any additional editing of the craft record on KerbalX

Picture Urls are verified before uploading. YouTube Urls are validated for correct syntax before uploading.

Edited by linuxgurugamer
  • Like 8

Share this post


Link to post
Share on other sites

isnt importing craft files easy enough? like, its just drag and drop a .craft file? unless this will let you do it, without having to go the main menu and back again.

Share this post


Link to post
Share on other sites
isnt importing craft files easy enough? like, its just drag and drop a .craft file? unless this will let you do it, without having to go the main menu and back again.

That is correct. This will let you do it.

It removes the need to do a drag and drop, especially if you have a lot of games/game files. It is entirely in-game, and will be in CKAN as soon as it gets updated

Share this post


Link to post
Share on other sites
isnt importing craft files easy enough? like, its just drag and drop a .craft file? unless this will let you do it, without having to go the main menu and back again.

Since when do you have to go to the main menu? I can just be in the VAB/SPH and add a craft file to the folder and click load and it's there to be loaded.

Share this post


Link to post
Share on other sites

This would be useful for players on Steam who use the Steam overlay for web browsing. They could go to the KerbalX site through the steam overlay, then copy and paste the url without ever having to exit the game. Very nice!

I personally never download craft files, so I probably won't have a use for it, but it's nice to know it exists.

A couple things:

1) Craft thumbnails. It should be possible to get and display them on your file browser. Not sure exactly where they're stored though.

2) Regarding addon posting rules: You might want to add a very clear message on your post saying that it pulls files off the web (if you tell it to pull files off the web). I realize that's excessively obvious, but better safe than sorry. Probably not needed. A moderator would know for sure.

Share this post


Link to post
Share on other sites
This would be useful for players on Steam who use the Steam overlay for web browsing. They could go to the KerbalX site through the steam overlay, then copy and paste the url without ever having to exit the game. Very nice!

I personally never download craft files, so I probably won't have a use for it, but it's nice to know it exists.

A couple things:

1) Craft thumbnails. It should be possible to get and display them on your file browser. Not sure exactly where they're stored though.

2) Regarding addon posting rules: You might want to add a very clear message on your post saying that it pulls files off the web (if you tell it to pull files off the web). I realize that's excessively obvious, but better safe than sorry. Probably not needed. A moderator would know for sure.

Ummm, craft thumbnails would be extremely difficult, especially if downloading from the web.

Re. a craft file outside the game dir, I'm not sure it's possible without a lot of extra coding, but I'll think about it.

Re. downloading, doesn't it specifically say that's what it's doing? Either way, I changed the wording and underlined the downloading part, so I'm not going to worry about it unless contacted by a moderator.

Share this post


Link to post
Share on other sites
Ummm, craft thumbnails would be extremely difficult, especially if downloading from the web.

Re. a craft file outside the game dir, I'm not sure it's possible without a lot of extra coding, but I'll think about it.

Re. downloading, doesn't it specifically say that's what it's doing? Either way, I changed the wording and underlined the downloading part, so I'm not going to worry about it unless contacted by a moderator.

I just meant the craft thumbnails for craft on your computer, which KSP automatically generates and saves somewhere. I was just suggesting that you could probably get access to those and display them in your file browser (this one) without too much trouble. Obviously you can't do that with craft files from the web unless the site provides them. Although, now that I think about it, I'm pretty sure there's a function to force the generation of a thumbnail, but you'd still have to download the craft first, so not that useful by that point.

I didn't mention craft files from outside of the game directory, and according to the addon rules a plugin isn't allowed to access any folders outside of the KSP directory. With the Steam overlay they can just copy and paste URLs really easily, which is really nice.

As for the downloading thing, I just brought it up because the addons rules state

5. Contacting another network or computer system

Add-ons that contact another network or computer system must tell users exactly what it's sending or receiving in a clear and obvious way in all locations it is offered for download.

and some people get really, really touchy about anything ever contacting the outside world. It's pretty obvious that downloading a craft requires downloading something, so it's probably not really needed, but after the ModStatistics fiasco, and the small fiasco with DebRefund, I'd rather overstate something than understate it.

But, if I didn't make it clear before, a very cool mod :)

Share this post


Link to post
Share on other sites

I wouldn't worry about it. You make it quite clear that this is intended to communicate with other websites.

Share this post


Link to post
Share on other sites

For a power user and seasoned KSP player/modder, this sort of addon makes absolutely no sense. However I can't even begin to say how useful this would have been before I knew how all this stuff worked. If I was brand new to this stuff, I'd download this immediately.

Share this post


Link to post
Share on other sites

I didn't mention craft files from outside of the game directory, and according to the addon rules a plugin isn't allowed to access any folders outside of the KSP directory. With the Steam overlay they can just copy and paste URLs really easily, which is really nice.

The addon rules state this:

"Edit, delete, or create files outside of the KSP installation folder"

But it IS allowed to read files outside the KSP installation folder.

But, if I didn't make it clear before, a very cool mod :)

Thank you

Share this post


Link to post
Share on other sites

Hi, I just used your mod and it seems to work only once. I downloaded this craft "http://kerbalx.com/embix/KL-26D-AG-LR" form KerbalX.com and it loaded perfectly. However, I can't download another craft and it keeps showing the same window over and over again even when I clic the "OK" button. Here is a proof :

Mod List : 31c4b96b28.png8806c77cfe.png7b419b771a.png

Share this post


Link to post
Share on other sites

Thanks for the bug report.

I'll be updating this on Sunday, will make sure this is fixed along with another.

Could you list both craft, not just the first?

Thanks

LGG

Edit: I just tested with the craft you listed on a dev version which fixes a couple of bugs. On the dev version, it works, so look for an update tomorrow.

also, you listed a local image file, that doesn't work, you need to upload the image somewhere else.

Edited by linuxgurugamer

Share this post


Link to post
Share on other sites
here is the second aircraft I wanted to download : http://kerbalx.com/embix/KL-26D-AA-LR

but it won't let, because the plugin's window is blank

here is the proof : http://imgur.com/VcrGwDj

or here : http://imgur.com/VcrGwDj

OK, thanks.

I actually found this just before I saw your bug report. The entire second dialog is being removed as being totally unnecessary.

Release soon

- - - Updated - - -

OK, thanks.

I actually found this just before I saw your bug report. The entire second dialog is being removed as being totally unnecessary.

Release soon

0.3.0 released.

Share this post


Link to post
Share on other sites

Just released 0.4.0, which adds KerbalX support

Share this post


Link to post
Share on other sites

Feature request within your add-in: add capability to browse for KerbalX crafts, pulling their primary picture, and brief description, and then mark them for download.

Share this post


Link to post
Share on other sites
Beware, I kept getting a graphics hiccup / stutter twice a second - even on the home screen where it says "Start Game" and I restarted my computer, shutdown external programs (including my firewall!), reset the graphics settings, and even opened my computer and disconnected my second hard drive trying to track down what was causing it. It wasn't until I deleted THIS mod that it went away.

I thought it was a cool idea, but what is this mod doing? Polling the HDD or network twice a second?

Share this post


Link to post
Share on other sites
On 11/22/2015 at 6:24 PM, neamerjell said:

Beware, I kept getting a graphics hiccup / stutter twice a second - even on the home screen where it says "Start Game" and I restarted my computer, shutdown external programs (including my firewall!), reset the graphics settings, and even opened my computer and disconnected my second hard drive trying to track down what was causing it. It wasn't until I deleted THIS mod that it went away.

I thought it was a cool idea, but what is this mod doing? Polling the HDD or network twice a second?

Ummm, a bit late, but is this still happening?  Been quite a while, and you didn't bother to post a log file back then, so it got ignored.

Share this post


Link to post
Share on other sites

He is right some one else had the same problem over in the Memgraph thread. I reproduced this with stock + your mod + memgraph and submitted a bug report. Also reproduced on different systems and many different mod set ups.

Edited by SpaceFoon
  • Like 1

Share this post


Link to post
Share on other sites

According to the Unity profiler the memory usage is happening in MainMenuGui.OnGUI.  I've not rebuilt a debug version to get more information about where in the function the big usage is but I can see several quite worrying things about the function anyway.  First, you appear to be calling your MonoBehaviour's Awake function from it and this is adding a handler to an event which will allocate a number of memory blocks and, called repeatedly, is presumably causing the list of handler functions to be reallocated to double the size when the available space fills up.  Second, you are recreating all sorts of things on each call rather than caching them in the class instance.  This includes a number of GUIStyle and Rectangle objects.  Third, your use of the various GUILayout functions that return a GUILayoutOption is exceedingly rampant.  Every time you call one of those functions (looks like mostly Width and Height) it allocates a new object from the heap.  These can also be created once and cached in class instance.

If fixing the repeated adding of the event handler fixes the bulk of the problem then you would probably be better off changing the UI to use the new system rather than the old one.  GUILayout, in particular, still generates a large amount of garbage even if you optimise the style and layout option usage.  However, there may be something else going on that will require a debug build of the plugin (or a more in-depth examination of the code) to locate...

  • Like 1

Share this post


Link to post
Share on other sites

This was the 1st mod I wrote which did anything significant, as such, it needs some love.

I've marked it for attention in the near future

Thanks

Share this post


Link to post
Share on other sites

Pull request submitted. It puts this line

                styleItems.SelectionChanged += styleItemSelectionChanged;

inside the `if (!firstAwake)` block. With that fix, I'm able to run the plugin without problems.

  • Like 1

Share this post


Link to post
Share on other sites
On 1/12/2017 at 0:15 PM, linuxgurugamer said:

This was the 1st mod I wrote which did anything significant, as such, it needs some love.

I've marked it for attention in the near future

Thanks

No thank you for writing a bazillion mods I can't live without!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now