Stellarium Scripting with Typescript

Stellarium Automation with Typescript and Visual Studio Code

Introduction

Stellarium is an open source astronomy software capable of rendering the night sky with near photographic realism. One of the features of Stellarium is its scriptability. In this article i will explain how to set up the Visual Studio Code development environment for developing Stellarium scripts in Typescript.

Why Typescript?

The script API of Stellarium is quite powerfull but there are certain limitations that make writing complex scripts difficult. Stellarium is using QtScript which is an implementation of the ECMAScript specification. The Typescript language is a strict syntactical superset of ECMAScript. It was developed to make working with ECMAScript easier and safer. Typescript code is not executed directly but transpiled into ECMAScript.

The benefits of using Typescript and Visual Studio Code:

Here is how a minimalistic example of Stellarium Typescript code looks like:

// Author: Ingo Berg
// Version: 1.0
// License: Public Domain
// Name: HelloWorld
// Description: A demonstrational script for tramnspiling typescript to stellarium

import { Helper } from "../Shared/Helper"

function main() : void {
	try
	{
		core.wait(2);

		Helper.InstallDebugHooks();

		LabelMgr.labelScreen("Hello world", 400, 550, true, 100, "#66ccff");
	
		core.debug("Debug Output:")
		core.debug("  + Control Stellarium with Typescript!")
		core.debug("  + Keep your sanity whilst working with ECMA script")
		core.debug("  + get a onscreen display of core.debug messages")

		for (var i=0; i<10; ++i) {
			core.debug("Teminating in " + (10-i).toString() + " seconds")
			core.wait(1)
		}
	}
	catch(err)
	{
		core.debug(err);
	}
	finally
	{
		LabelMgr.deleteAllLabels();
		Helper.RemoveDebugHooks()
	}
}

main();

This typescript will be transpiled into stellariums native SSC code. If you want to test it copy and paste the result of the transpilation directly into stellariums script console to execute it. (Press F12 to open Stellariums script console)
back      next

You might also like: