Jump to content

Editor UNDO Ship Construct


Recommended Posts

Alright, does anyone know, or know of a mod I could look at, that deals with the UNDO function in the editor.

I'm after the absolutely basic information here, I've never even worked with a ship construct, let alone the Undo function in the editor.

For reference, I'm trying to reset an action when a part is recreated. IE: Part with action assigned is deleted and then brought back with Undo, I want the action to come back also.

Note that default KSP behavior is to lose the action as well, so far it looks like rather the the same part coming back, KSP makes a new part of the same type in the same location.

D.

Link to comment
Share on other sites

Okay, my own research has revealed some oddities in how the Undo function is handled.

First, the undo function works on a whole ship basis. More specifically, it looks like the Editor saves a series of ShipConstructs rather then keeping track of individual parts.

So when you hit the Undo command, the current ship is deleted in its entirety and the ShipContruct in the the Undo queue is loaded.

Now, because a ShipConstruct saves the partModules, this is not actually an issue for most mods. Your partModule will load form the shipConstruct with the settings it had when the shipConstruct was created.

However, if you are referring to the Parts themselves from an external source be aware that the 'same' Part will be different as far as the code is concerned before and after the Undo. (Part.constructID changes for the same part as compared to before and after the Undo.)

If you are referring to a part from a partModule on the part, you will have no issues as your partModule will also be replaced when the ShipConstruct loads and will refresh its pointers.

I could not find any sort of event or field I could monitor to see when an Undo happened so I had to setup a compare so that if LastFrameRootPart != ThisFrameRootPart, assume an Undo has just taken place.

I'm not sure if there are odd circumstances that would mean I falsely detect an Undo action, but in my specific case if I detect an Undo action at the wrong time it does not cause my mod issues so it is working for me.

D.

Link to comment
Share on other sites

[snip]

I could not find any sort of event or field I could monitor to see when an Undo happened so I had to setup a compare so that if LastFrameRootPart != ThisFrameRootPart, assume an Undo has just taken place.

Although I guess you allready considered this and have a good reason for not using that methode..

but if you could live with a dirty trick, you could allways listen for the undo key combination and consider this an event.

it's not .... but it should work stable I think..

Link to comment
Share on other sites

Although I guess you allready considered this and have a good reason for not using that methode..

but if you could live with a dirty trick, you could allways listen for the undo key combination and consider this an event.

it's not .... but it should work stable I think..

I considered that, but I've been burned by that before where I was listening for a keystroke instead of looking for an event in code and pretty much refuse to use that method ever again. Notably that does not work for a command not issued by the keyboard.

Now, Undo currently can only be issued by the keyboard so it would work for default KSP but I am explicitly trying to support as many mods as I can so that means I'm assuming there is a mod out there that adds an undo button to the editor that can be mouse clicked.

D.

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...