Jump to content

Kerbal Web Program (KWP) [Automation and Stats using any language]


ShadowDev

Recommended Posts

Kerbal Web Program (0.2.0)
Download: https://spacedock.info/mod/3275/Kerbal Web Program
Wiki: https://kwp.kerbal.wiki
Kerbal Web Program is a mod that allows you to use API's to control your game
This mod also provides an easy to use web server so you don't have to install external software.

Example use of the web server:
Create a dashboard with commands that you can send to your ship to perform actions such as staging, orientation locking, thrust. 

By using this mod you can fully automate a ship launch using any language you like, I recommend using the provided web server to run JS in your browser. 
The api that the mod provides can also be expanded to fit your needs, the wiki provides more details on this.
You can see the current api's provided by the mod by going to http://localhost:8080/docs when the game is loaded

Current features:

  • Rest API
  • Basic endpoints
  • inbuilt web hosting for your own frontend
  • Autogenerated api docs
  • Expandable API (through API expansion system and external mods) 
  • Ingame web browser
  • Button api

Example Dashboard with code editor and runner:

Spoiler

Paste this into the index.html at file path 

Kerbal Space Program 2\BepInEx\plugins\kerbal_web_program\Server\public

Dashboard example:
Uses the microsoft monaco editor (same one that vscode uses)

<html data-bs-theme="dark">

<head>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
        integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
        crossorigin="anonymous"></script>
    <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>

</head>

<body style="margin: 5px;">
    <div class="container-fluid">
        <div class="row" style="height: 100%;">
            <div class="col" style="height: 100%;">
                <div id="Codearea" style="height: 100%;">

                </div>
            </div>
            <div class="col" style="height: 100%; overflow: scroll;" id="ConsoleScrollArea" >
                <button type="button" class="btn btn-sm btn-success" style="margin-bottom: 5px;" onclick="RunUserScript()">
                    <span class="material-symbols-outlined">
                        play_arrow
                        </span>
                </button>
                <div id="ConsoleArea">

                </div>
            </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
        integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD"
        crossorigin="anonymous"></script>
    <script src="https://unpkg.com/monaco-editor@latest/min/vs/loader.js"></script>
    </script>
    <script>
        var editor
        setTimeout(() => {
            require.config({ paths: { 'vs': 'https://unpkg.com/monaco-editor@latest/min/vs' } });
        window.MonacoEnvironment = { getWorkerUrl: () => proxy };

        let proxy = URL.createObjectURL(new Blob([`
	self.MonacoEnvironment = {
		baseUrl: 'https://unpkg.com/monaco-editor@latest/min/'
	};
	importScripts('https://unpkg.com/monaco-editor@latest/min/vs/base/worker/workerMain.js');
`], { type: 'text/javascript' }));
        require(["vs/editor/editor.main"], function () {
            editor = monaco.editor.create(document.getElementById('Codearea'), {
                value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
                language: 'javascript',
                automaticLayout: true,
                theme: "vs-dark",
                autoIndent: "full"
            });
        });
        }, 500)
        console.log = function(data){
            var ConsoleArea = document.getElementById("ConsoleArea")
            var ConsoleScrollArea = document.getElementById("ConsoleScrollArea")
            ConsoleArea.innerHTML = ConsoleArea.innerHTML + `<a>${data}</a><br>`
            ConsoleScrollArea.scrollTo(0, ConsoleScrollArea.scrollHeight);
        }
        console.warn = function(data){
            var ConsoleArea = document.getElementById("ConsoleArea")
            ConsoleArea.innerHTML = ConsoleArea.innerHTML + `<a>${data}</a><br>`
            ConsoleScrollArea.scrollTo(0, ConsoleScrollArea.scrollHeight);
        }
        console.info = function(data){
            var ConsoleArea = document.getElementById("ConsoleArea")
            ConsoleArea.innerHTML = ConsoleArea.innerHTML + `<a>${data}</a><br>`
            ConsoleScrollArea.scrollTo(0, ConsoleScrollArea.scrollHeight);
        }
        console.error = function(data){
            var ConsoleArea = document.getElementById("ConsoleArea")
            ConsoleArea.innerHTML = ConsoleArea.innerHTML + `<a>${data}</a><br>`
            ConsoleScrollArea.scrollTo(0, ConsoleScrollArea.scrollHeight);
        }
        function RunUserScript(){
            var userScript = new Function(editor.getValue())
            userScript()
        }
    </script>
</body>

</html>


 

I look forward to seeing what crazy things you all create with this mod. Expect updates in the coming weeks with more features such as api hotreload and an official dashboard.  

[if you want your api extension adding to this list DM me (ShadowDev#6969) on discord or ask in the ksp 2 modding discord]
KWP API Extension list


git: https://github.com/Bit-Studios/KerbalWebProgram License: CC-BY-NC-ND

Edited by ShadowDev
kwp 0.2.0
Link to comment
Share on other sites

  • 9 months later...
  • 3 weeks later...

I'm totaly new to this but the idea is really cool!

I have a multi monitor set up and I'd love to have in flight information on my 2nd and 3rd monitor.

Such as map view and such. Is that possible to make with this mod and how should one go about making it? I looked at the wiki but the only thing I could find was the button tutorial. 

Keep up the great work!

Link to comment
Share on other sites

14 hours ago, Jorntmeister said:

I'm totaly new to this but the idea is really cool!

I have a multi monitor set up and I'd love to have in flight information on my 2nd and 3rd monitor.

Such as map view and such. Is that possible to make with this mod and how should one go about making it? I looked at the wiki but the only thing I could find was the button tutorial. 

Keep up the great work!

yes that is possible to make.

I would recommend using html and js for that.

you can use the celestial body api to get the positions of the planets and their orbital characteristics
when you have the game loaded go to http://localhost:8080/docs for more info. that page auto generates based on the apis you have installed with the mod
if you want to get the craft position data you can use this api created by Steven_VaanUltra https://github.com/stevn999/VaansExpansion/releases/latest

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