Stellarium Scripting with Typescript

Stellarium Automation with Typescript and Visual Studio Code

Project Structure

Each typescript project consists of the files and folders listed below. The easiest way to create a new project is to copy an existing one.

Project Files and Folders

The Shared Folder

The shared folder is located at the same level as the project folders. It contains supplementary typescript classes used by the sample scripts as well as the Typescript declaration file for the Stellarium-Scripting-API. This file is telling Typescript and Visual Studio Code which functions are supported by Stellarium and how their definition looks like. At the time of me writing this article the file contains most, but not all Stellarium functions.

Please note that Stellarium script API functions which are missing in this file will be marked as syntax errors in Visual Studio Code but the code can still be transpiled.

In Addition the Scripts subdirectory contains bash (Linux) and powershell (Windows) scripts which are required by Visual Studio Code for launching Stellarium.

Opening and building a project

A project is opened by loading its workspace file into Visual Studio code. All sample projects use identic workspace files. The workspace file is named "stellarium-project.code-workspace".

The "Hello World" workspace

Once you have opened a workspace you can build and execute it by pressing "Ctrl + B".

Press CTRL + B to open the build options menu

You have two choices: "Execute Stellarium Script" and "Build Stellarium Script". The first option will launch Stellarium with the current project being its startup project. The second option will transpile your typescript code into a single Stellarium file. The output file will be named like your project folder with the extension SSC appended.

Project Output

The build process will create a stellarium script file that is named after the project folder with the extension ssc added.

When the build option "Execute Stellarium Script" is selected the output file together with the optional assets folder is copied to the local stellarium script folder and stellarium is started with the script as its startup-script.

You are now ready to start coding in typescript for Stellarium. If you are serious about Stellarium scripting i highly recommend switching to Typescript. Give it a try you will not look back...

back     

You might also like: