KontrolSystem2 icon indicating copy to clipboard operation
KontrolSystem2 copied to clipboard

Access Vessel in the VAB

Open PhilouDS opened this issue 1 year ago • 7 comments

Hello. I've written some UI scripts to use inside the VAB with the main_editor function. That works very well.

I'm wondering if it's possible to have access to the vessel, more precisely to each part of the vessel. For now, it doesn't seem possible. I wanted to compute myself the mass and the delta-v of my craft. Even the mod MicroEngineer makes mistakes sometimes.

Thanks.

PhilouDS avatar Feb 23 '24 18:02 PhilouDS

I did some preparation to have entry points for all the different game modes, but this was mostly taken over from the original implementation for KSP1. Obviously the main focus has been on the flight-mode so far and wait for all the other parts of the game to settle down for a bit.

From what I can tell, inside the VAB the vessel (as understood by ksp::vessel::Vessel) does not even exist yet. It is "created" when pressing the launch button. Until then there just seems to be a collection of parts, that do not even need to be connected yet ... which kind of makes sense considering that you want to shift things around.

... in short: I do not think the current bindings in ksp::vessel will actually work in the VAB as they are right now. Most likely here has to be a different API, which might have a some overlap with the existing one.

I'll take a look if there are some low hanging fruits that do not require a total overhaul.

untoldwind avatar Feb 24 '24 10:02 untoldwind

Okay, I perfectly understand that. Thanks for your answer and for your great work!

PhilouDS avatar Feb 24 '24 11:02 PhilouDS

I am still trying to figure out want kind of information are available in to VAB and what is specific to the flight-mode, so this is still somewhat minimal. But there is now a ksp::oab module (https://kontrolsystem2.readthedocs.io/en/latest/reference/ksp/oab.html) to access the vessel parts in the VAB.

A little test script:

use { CONSOLE } from ksp::console
use { active_object_assembly_builder } from ksp::oab

pub fn main_editor() -> Result<Unit, string> = {
    CONSOLE.clear()

    const builder = active_object_assembly_builder()?

    CONSOLE.print_line(">>> " + builder.assemblies.length.to_string())
    const maybe_assembly = builder.main_assembly

    if(Some(assembly) = maybe_assembly) {
        for(part in assembly.parts) {
            CONSOLE.print_line(part.part_name + " " + part.relative_position.to_fixed(2))
        }
    } else {
        CONSOLE.print_line(">>> no main assembly")
    }
}

untoldwind avatar Feb 24 '24 18:02 untoldwind

Thank you! This is already a good start, very promising!

PhilouDS avatar Feb 24 '24 19:02 PhilouDS

Some examples of my UIs (the wrong stage info at the top is from MicroEngineer. The bottom UI is mine)

image

image

When I use WARP inside the VAB, at the end of the warp, the game automatically launches the craft. I don't know if it's a normal behaviour but it's handy :)

PhilouDS avatar Feb 29 '24 23:02 PhilouDS

I have the feeling that this is not a desired behavior, considering that the time-control UI is hidden in the VAB view. Maybe there is a way to have a clean put-vessel-to-launchpad-at-time helper.

untoldwind avatar Mar 01 '24 15:03 untoldwind

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar May 01 '24 02:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 15 '24 02:05 github-actions[bot]