untoldwind / KontrolSystem2

Autopilot scripting system for KSP2
Other
54 stars 14 forks source link

Access Vessel in the VAB #127

Closed PhilouDS closed 1 month ago

PhilouDS commented 4 months ago

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.

untoldwind commented 4 months ago

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.

PhilouDS commented 4 months ago

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

untoldwind commented 4 months ago

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")
    }
}
PhilouDS commented 4 months ago

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

PhilouDS commented 4 months ago

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 :)

untoldwind commented 4 months ago

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.

github-actions[bot] commented 2 months ago

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

github-actions[bot] commented 1 month ago

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