Jump to content

[0.20] Subassembly Loader - 0.20 Compatibility Patch


TheUndeadFish

Recommended Posts

I made my own patch that uses relative position instead of absolute for the icon (on my screen it gets places immediately to the left of Part editor toggle button), and I also fixed the subdirectory/category loading/saving features since they weren't working for me in linux (tested only in linux as well).

Here is the diff:

--- Source/subassemblyLoader.cs	2013-06-02 03:30:48.409197029 -0500
+++ SubassemblyLoader/SubassemblyLoader/SubAssemlyLoader.cs 2013-06-02 03:31:39.285196251 -0500
@@ -1,30 +1,32 @@
-//v0.2
+//v0.2
using System;
using KSP.IO;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

+[KSPAddon(KSPAddon.Startup.EditorAny, false)]
public class subassemblyLoader : MonoBehaviour
{
public static GameObject GameObjectInstance;
- private static PluginConfiguration config = PluginConfiguration.CreateForType<subassemblyLoader> ();
private static string root = KSPUtil.ApplicationRootPath.Replace ("\\", "/");
- private static string subassemblyFolder = "PluginData/subassemblyLoader/subassemblies";
+ private static string subassemblyFolder = "GameData/SubassemblyLoader/PluginData/subassemblies";
+ private static string iconsFolder = "GameData/SubassemblyLoader/PluginData/icons";
private string subassemblyFilename = "Untitled";
private string subassemblyType = "";
private string subassemblyFolderName = root + subassemblyFolder;
+ private static string iconsFolderName = root + iconsFolder;
private bool showFilenamePrompt;
private bool isAttachable = true;
private FileBrowser fileBrowser;
private GUIStyle buttonStyle = new GUIStyle ();

// Load static button images
- private WWW img1 = new WWW ("file://" + root + "PluginData/subassemblyLoader/icons/buttonDisabled.png");
- private WWW img2 = new WWW ("file://" + root + "PluginData/subassemblyLoader/icons/buttonInactive.png");
- private WWW img3 = new WWW ("file://" + root + "PluginData/subassemblyLoader/icons/buttonHover.png");
- private WWW img4 = new WWW ("file://" + root + "PluginData/subassemblyLoader/icons/file.png");
- private WWW img5 = new WWW ("file://" + root + "PluginData/subassemblyLoader/icons/folder.png");
+ private WWW img1 = new WWW ("file://" + iconsFolderName + "/buttonDisabled.png");
+ private WWW img2 = new WWW ("file://" + iconsFolderName + "/buttonInactive.png");
+ private WWW img3 = new WWW ("file://" + iconsFolderName + "/buttonHover.png");
+ private WWW img4 = new WWW ("file://" + iconsFolderName + "/file.png");
+ private WWW img5 = new WWW ("file://" + iconsFolderName + "/folder.png");
private Texture2D buttonDisabled = new Texture2D (0, 0);
private Texture2D buttonInactive = new Texture2D (0, 0);
private Texture2D buttonHover = new Texture2D (0, 0);
@@ -33,7 +35,7 @@
private Texture2D button;

public void Awake ()
- {
+ {
DontDestroyOnLoad (this);

// Save static button images to textures
@@ -70,15 +72,28 @@

public void loadSubassembly (string filename)
{
+ Debug.Log ("loadSubassembly");
+
EditorLogic editor = EditorLogic.fetch;
-
+
+ if (filename == null) {
+ //Close Subassembly Browser
+ fileBrowser = null;
+ editor.Unlock ();
+ return;
+ }
+
+ if (!filename.Substring (filename.LastIndexOf ("/"), (filename.Length - filename.LastIndexOf ("/"))).Contains (".craft")) {
+ subassemblyFolderName = filename;
+ subassemblyType = subassemblyFolderName.Substring (subassemblyFolderName.LastIndexOf ('/'), (subassemblyFolderName.Length - subassemblyFolderName.LastIndexOf ('/')));
+ fileBrowser.CurrentDirectory = subassemblyFolderName;
+ return;
+ }
+
//Close Subassembly Browser
fileBrowser = null;
- editor.Unlock ();
+ editor.Unlock ();

- if (filename == null)
- return;
-
// Get current root, load subassembly construct, reset root
Part shipRoot = EditorLogic.startPod;
ShipConstruct subassemblyConstruct = ShipConstruction.LoadShip (filename);
@@ -92,6 +107,15 @@
// Check new construct is attachable
checkAttachable (editor.PartSelected);
}
+
+ public void changeCategory (string category)
+ {
+ if (category != null) {
+ subassemblyFolderName = category;
+ subassemblyType = subassemblyFolderName.Substring (subassemblyFolderName.LastIndexOf ('/'), (subassemblyFolderName.Length - subassemblyFolderName.LastIndexOf ('/')));
+ }
+ fileBrowser = null;
+ }

// Check if part is attachable
private bool checkAttachable (Part part)
@@ -129,7 +153,7 @@


// Draw top menu button
- if (GUI.Button (new Rect (Screen.width - 300, 1, 48, 36), new GUIContent (button, "Subassembly"), buttonStyle) && !EditorLogic.softLock)
+ if (GUI.Button (new Rect (Screen.width - 800, 1, 48, 36), new GUIContent (button, "Subassembly"), buttonStyle) && !EditorLogic.softLock)
if (EditorLogic.SelectedPart) {
if (checkAttachable (EditorLogic.SelectedPart))
showFilenamePrompt = true;
@@ -163,10 +187,15 @@
fileBrowser.OnGUI ();

// Draw "Up" button (if applicable)
- if (current != root + subassemblyFolder)
- if (GUI.Button (new Rect (Screen.width / 2 + 190, 562, 40, 30), "/.."))
- fileBrowser.CurrentDirectory = current.Substring (0, current.LastIndexOf ('/'));
-
+ if (current != root + subassemblyFolder) {
+ fileBrowser.BrowserType = FileBrowserType.File;
+ if (GUI.Button (new Rect (Screen.width / 2 + 190, 562, 40, 30), "/..")) {
+ fileBrowser.CurrentDirectory = current.Substring (0, current.LastIndexOf ('/'));
+ }
+ }
+ else {
+ fileBrowser.BrowserType = FileBrowserType.Directory;
+ }
// Reset Skin
list.normal.textColor = new Color (.739f, 0.739f, 0.739f);
list.contentOffset = new Vector2 (1, 42.4f);
@@ -198,10 +227,9 @@
// Category button
GUILayout.BeginHorizontal ();
GUILayout.Label ("Category:", GUILayout.Width (75));
- if (GUILayout.Button (subassemblyType == "" ? "Miscellaneous" : subassemblyType))
- createFileBrowser ("Select subassembly category", true, (string filename) => {
- subassemblyFolderName = fileBrowser.CurrentDirectory;
- fileBrowser = null; });
+ if (GUILayout.Button (subassemblyType == "" ? "Miscellaneous" : subassemblyType)) {
+ createFileBrowser ("Select subassembly category", true, changeCategory);
+ }
GUILayout.EndHorizontal ();

// Ok / Cancel buttons
@@ -237,21 +265,19 @@
private void createFileBrowser (string title, bool isDir, FileBrowser.FinishedCallback callback)
{
fileBrowser = new FileBrowser (new Rect (Screen.width / 2, 100, 350, 500), title, callback, true);
- fileBrowser.BrowserType = isDir ? FileBrowserType.Directory : FileBrowserType.File;
+ fileBrowser.BrowserType = FileBrowserType.Directory;//isDir ? FileBrowserType.Directory : FileBrowserType.File;
fileBrowser.CurrentDirectory = root + subassemblyFolder;
fileBrowser.FileImage = fileIcon;
fileBrowser.DirectoryImage = folderIcon;
fileBrowser.disallowDirectoryChange = true;
- if (!isDir)
- fileBrowser.SelectionPattern = "*.craft";
}
}

-public class subassemblyLoaderInit : KSP.Testing.UnitTest
+public class subassemblyLoaderInit
{
public subassemblyLoaderInit ()
{
var gameobject = new GameObject ("subassemblyLoader", typeof(subassemblyLoader));
UnityEngine.Object.DontDestroyOnLoad (gameobject);
}
-}
+}

My directory structure for the plugin is now:

KSP/GameData/SubassemblyLoader

PluginData

icons

buttonDisabled.png

buttonHover.png

buttonInactive.png

file.png

folder.png

subassemblies

Landers

2 Stage.craft

Lifters

Example.craft

Probes

Small Probe.craft

Plugins

SubassemblyLoader.dll

If anyone wants the .dll I can upload it on a share site somewhere I'm sure... I used MonoDevelop on Ubuntu 12.04 x86_64, and it works like a charm for me now :-)

Link to comment
Share on other sites

I have applied damien667's patch successfully (although the mangled whitespace forced me to do it manually) and can confirm that it works on Arch Linux 64bit and fixes the annoying can't-use-subdirectories issue.

Here's the zip file hosted on Dropbox:

The updated source is inside the zip just like original.

Remeber, unpack this directly into GameData folder just like explained above !!!

Edited by sal_vager
Link to comment
Share on other sites

I have applied damien667's patch successfully (although the mangled whitespace forced me to do it manually) and can confirm that it works on Arch Linux 64bit and fixes the annoying can't-use-subdirectories issue.

Here's the zip file hosted on Dropbox:

The updated source is inside the zip just like original.

Remeber, unpack this directly into GameData folder just like explained above !!!

Yeah... MonoDevelop auto-format did its miracle on whitespace... Sorry about the inconsistency with original code. Glad it works for you too :-)

Edited by sal_vager
Link to comment
Share on other sites

I've messing with the code and for some reason it just doesn't want to save the subassemblies now. It crashes on this line...

Part[] children = selected.FindChildParts<Part>(true);

The debug monitor says this... gNKfwbB.png

The code in the dll is this (I put the debug messages in to see which like caused the problem)...

public void saveSubassembly(string filename)

{

Debug.Log("Woooot");

//Close Filename Prompt

showFilenamePrompt = false;

EditorLogic.fetch.Unlock();

Debug.Log("Step 2");

// Create new construct

ShipConstruct subassemblyConstruct = new ShipConstruct(1);

subassemblyConstruct.shipName = filename;

Debug.Log("Step 3");

// Add selected part

Part selected = EditorLogic.fetch.PartSelected;

subassemblyConstruct.Add(selected);

Debug.Log("Step 4");

// Add selected part's children

Part[] children = selected.FindChildParts<Part>(true);

Debug.Log("Step 5");

foreach (Part part in children) subassemblyConstruct.Add(part);

// Save construct

Debug.Log("../../../../" + subassemblyFolder + '/' + subassemblyType + '/' + filename);

ShipConstruction.SaveShip(subassemblyConstruct, "../../../../" + subassemblyFolder + '/' + subassemblyType + '/' + filename);

}

I just can't get my head around this at the moment. I can get all the types of subassemblies to show up and I can load them... I just can't get the darn thing to save lol.

4rgOoJf.png

Edited by NeoMorph
Link to comment
Share on other sites

I could despareately use some help, as well. My problem is that, every time I load a subassembly, the bottom-most connection node is missing. For example:

NZQWA7i.jpg

The small unplaced selection is a probe lander loaded from SubAssembly Loader. The bottom part is a normally-saved Lifter. Note that the only placement nodes that exist are on the lifter and the top of the subassembly... but not the bottom. No matter how many parts I replace, and no matter what part I make the "root" of the subassembly, the "bottom" node is always gone. The top is always fine, the bottom is always gone. I can flip that probe lander upside down and it works fine... but that's not my intention here. Anyone else having this issue?

Link to comment
Share on other sites

@Kardea Does it help to flip the probe upside down, paste it to the rocket, then pick it up again, flip it in the correct position and then paste it again? I've also seen nodes missing but they were restored once the subassembly was attached to the rocket. A bit inconvenient but you can work around it.

Link to comment
Share on other sites

I have to admit that I have zero experience in coding with Unity. Is there a manual available anywhere?

If you actually fix Subassembly Loader, you're crowned king of KSP. You know that, right?

Link to comment
Share on other sites

If you actually fix Subassembly Loader, you're crowned king of KSP. You know that, right?

Well it's not going to be me fixing it. I have ZERO knowledge of Unity and with my morphine addled brain I have zero chance of learning it. It's the one reason I had to pack in work being a programmer. I just cannot retain language skills anymore.

What's worse is that I cannot figure out what the problem is with the save code. If that could be fixed then the whole thing would be working fine. If you read some of the comments in this mod you would know that the coder hates Unity too. Like this for instance...

// The rest of this entire file a giant cluster*BLEEEP*of kludges upon hacks in order to get a working file browser despite KSP.IOs total lack of directory methods.

The real annoying thing is that it was working perfectly in 0.19.

Link to comment
Share on other sites

Unfortunately, no. I can attach the subassembly upside-down, but it doesn't restore the missing node.

What if you remove the offending piece and attach a new one after placing it upside down? You probably already tried that though.

Link to comment
Share on other sites

What if you remove the offending piece and attach a new one after placing it upside down? You probably already tried that though.

I doubt if he can... Remember you cannot split apart that group until it is connected to the root... and he can't connect it to the root because the node is missing. Catch-22 situation.

Link to comment
Share on other sites

Well this is strange... I was using the wrong source code to base my work on. Made some changes with the current source code and it works well now (thanks UndeadFish).

One thing I have noticed though is that there used to be a delete button to delete messed up subassemblies but the button isn't there now. Other than that, the thing works well and now lets me put my subassemblies into categories correctly.

Link to comment
Share on other sites

@Kardea

I think you may have to redo your probe. You can put something inside the decoupler, and sometimes this causes the attachment system to break. What I would suggest is get a small capsule, or control pod, drop your probe on whichever way possible, remove the decoupler, and put it back on, and re-save the probe.

Edited by Pontiac
Link to comment
Share on other sites

I could despareately use some help, as well. My problem is that, every time I load a subassembly, the bottom-most connection node is missing. For example:

NZQWA7i.jpg

The small unplaced selection is a probe lander loaded from SubAssembly Loader. The bottom part is a normally-saved Lifter. Note that the only placement nodes that exist are on the lifter and the top of the subassembly... but not the bottom. No matter how many parts I replace, and no matter what part I make the "root" of the subassembly, the "bottom" node is always gone. The top is always fine, the bottom is always gone. I can flip that probe lander upside down and it works fine... but that's not my intention here. Anyone else having this issue?

That's actually just the way KSP works. If the root of your probe is at the top, then you can only grab it by the root, and you can only reattach it by the root. It works the same way with or without subassembly loader. subassembly loader just lets you save and load subassemblies into different rockets, but you can still only attach them to new rockets in the same way as they were attached to the old one. If the subassembly -is- the old rocket, it can only be attached by the root node, aka, the original command capsule or probe core. To get around this when making probes, consider building them attached to a main probe, and grabbing them from the attachment point to save in subassembly.

Link to comment
Share on other sites

So Subassembly loader isn't working for me anymore. Any time I load a subassembly, all of the parts appear in my VAB, but none of them are connected to each other, and I can only grab them one at a time. Furthermore after loading one, the VAB load interface breaks until I reload the game.

Link to comment
Share on other sites

By my own diagnosis, there is some kind of issue with with KSP in which how the assemblies are loaded. If the "root" part you're saving isn't a command module (CM) (Manned or unmanned) things like your asparagus setup will break. What you do is you put a new CM down, doesn't matter which one, attach that new CM to the existing payload if there is one, attach your subassembly you want to save to the new command module, then drag the new CM to the subassembly icon and save as normal. When you load up an old assembly, attach your assembly to the new payload as per normal, but if you want to get rid of that new CM, take the assembly off the new CM, remove the extra CM, then reattach the assembly. Few extra steps, but I ain't wiring up 30 fuel lines.

I didn't come up with this method, and I'm not sure where that post is, but it does work as I have a very massive asparagus rocket that was misbehaving until I put a command module on.

I've looked at the code myself and tried reorganizing how the mod saves the data before I knew about the CM fix, but it didn't help. I've specifically tried saving the fuel lines to the bottom of the assembly file, but it didn't work. I didn't try putting the pipes at the top of the file because that wouldn't make sense. The parts the fuel lines attach to possibly wouldn't exist yet, so, didn't drive down that line. Then I saw the suggestion with saving with a command module came along, it worked, so I stopped trying to fix it. Personally, I think its something to do with KSP handling either the load or the save, but I can't determine which is the problem. A diff between the two files (One without a command module, and one with) yields different physical positioning of each item, a new ID for each item, but the general order of each item matches. I attribute the change in physical positions because I'm not that good at moving objects to the exact same place on the screen. ;)

Its also unfortunate that there are several people with their fingers on this code trying to submit fixes. Everyone has their own version that they're using, and somewhere down the line, something broke. If you're interested in my version, you can grab it from one of my last posts in the "official" forum. I'm using it, because I deleted the code that deletes the assembly if you try to put a command module in the save that doesn't have an additional spot for an attachment. :P

Link to comment
Share on other sites

I would ask for this buttong to be placed somehwere else. I play at 1024x600 windowed and the two left side buttons will certainly cover the subassembly loader button.

Link to comment
Share on other sites

I didn't find a thread dedicated to the Subassembly Loader mod, so I had to create this one.

Using the source code provided along with the mod, I just made a patched version that will work with 0.20. This moves the button to a usable location in the VAB as well as eliminates the lag caused by the plugin not loading properly.

I only intend this as a quick-and-dirty fix until the mod's author can release a proper updated version of it.

Download:

Disclaimer: Use at your own risk, since I'm rather new to KSP modding.

Do I just need this patch or the original as well - still having functionality issues.

Cheers.

Edited by sal_vager
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...