Jump to content

"extending" a PartModule


Recommended Posts

OK folks, I have hit a bit of a problem, and need to take a step back to find the simple, elegent solution rather than keep hacking away!

What I am trying to achieve is to create a PartModule that can be added to a part and extends the functionality of each of any existing ModuleDockingNode for that part. (The idea is to add closeable hatches to each docking node).

I was planning to achieve this by adding in my new ModuleDockingNodeHatch in the same way that for example TAC Life Support adds itself to each part as required. However the problem is that if there isa part with more than one docking node, then I need to add more than one hatch, and I need to be able to associate the hatch module with the relevent docking node module. I need to to this in a way that will persist accross saves. The trouble is that ModuleDockingNode does not have any sort of identifier, or name so how can I distinguish ione from the other?

This then got me thinging is there a nice way of "exetending" to existing ModuleDockingNode class? Sure I could just inherit from it, and add some stuff, and then try to use ModuleManager to replace all exisitng ModuleDockingNodes with my new ModuleDockingNodeWithHatch, but I rather get the impression that will end up being a bit hacky and create more problems down the line thatn it solves.

What do you all think? What is the approach I should take? Is there a better way?

Link to comment
Share on other sites

If you replace ModuleDockingNodes, your mod will be incompatible with every other mod that uses ModuleDockingNodes. You'll have to create your class as a PartModule, then search the part you are attached to for any ModuleDockingNodes. Which parts have multiple docking nodes per part?

Link to comment
Share on other sites

If you replace ModuleDockingNodes, your mod will be incompatible with every other mod that uses ModuleDockingNodes. You'll have to create your class as a PartModule, then search the part you are attached to for any ModuleDockingNodes. Which parts have multiple docking nodes per part?

Thanks for replying - I thought no one would!

I agree with your thoughts on replacing ModuleDockingNode. However if I wrote a class that inherited from ModuleDockingNode then it could be treated as a ModuleDockingNode by other mods that need to do so (or maybe not - I am sure that it would not quite work). What other mods are there that do things with ModuleDockingNode objects?

In particular the Porkjet Flathab part has more than one docking port, and I am really keen to support it as it is such a good mod!

I have been wondering if I can just assign ModuleHatchs to ModuleDockingNode based on their position in the collection / config / save file (ie first hatch is for first docking port) It might just work, but would be vulnerable to breaking in the future.

I really do not know which way to go with this, and so have stopped making progess on this mod for now through indescision. I have recently been thinking the the inheritance approach might be a god way to go, but if someone can provide a firm example of where it break something else (either game or mod) then that will make up my mind for me.

Link to comment
Share on other sites

A quick goodle search of github shows that ModuleDockingNode is used by MechJeb2, RasterPropMonitor, Navball Docking Alignment indicator, Tweakable Everything, Kerbal Multiplayer and Probe Control Room, so you can test against those. List order may not stay the same in all cases. Have you looked at the ModuleDockingNode's nodeTransformName for parts with multiple nodes?

Link to comment
Share on other sites

Thanks for the suggestion of test cases. I will look at the code of those mods to see what they do. I am pretty sure that as long as they are casting to ModuleDockingNode or using TypeOf<ModuleDockingNode> to do their stuff then they should not notice the difference between having a ModuleDockingNode or a ModuleDockingNodeType.

Yes I have been considering the use of nodeTransformName for parts with more than one node.

Lets see how it all goes!

Link to comment
Share on other sites

  • 2 weeks later...

Well I hate to say it, but I think you were right. Although inheriting from ModuleDockingNode works really elegently in many ways, it is also causing me no end of other bothers, and I just do not trust ti to be stable.

However, I think I have found a way of indexing the ModuleDockingNodes in a part. A dockingNode has to have a reference to either an attachmentNode or a transform name so it know where the actual docking node is on the part. I am use these as an index if there is more than one docking node in a part, adn then just add my own module.

What do you think - any potential problems?

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...