A Node.js implementation of the External Editor API for Tabletop Simulator.
This is intended to make it easier to write development tools and plugins intead of using the built-in script editor or the Official Atom Plugin for Tabletop Simulator. There are two classes provided by this API - ExternalEditorApi and TTSApiBackend.
This is the client/server representing the editor. You can listen for connections from an active instance of Tabletop Simulator, and send messages to an active instance.
(async () => {
// Create an API client and listen to incoming messages.
const api = new ExternalEditorApi();
await api.listen();
// You are now ready to send/receive messages.
await api.executeLuaCode('print("Hello, World")');
})();
You can send four outgoing message types:
https://api.tabletopsimulator.com/externaleditorapi/#get-lua-scripts
async function getLuaScripts(api: ExternalEditorApi) {
const gameState = await api.getLuaScripts();
console.log(gameState);
}
https://api.tabletopsimulator.com/externaleditorapi/#save-play
async function saveAndPlay(api: ExternalEditorApi) {
const gameState = await api.saveAndPlay();
console.log(gameState);
}
https://api.tabletopsimulator.com/externaleditorapi/#custom-message
async function customMessage(api: ExternalEditorApi) {
await api.customMessage({
foo: 'Hello',
bar: 'World',
});
}
https://api.tabletopsimulator.com/externaleditorapi/#pushing-new-object
async function executeLuaCode(api: ExternalEditorApi) {
await api.executeLuaCode('print("Hello, World")');
}
You can also listen to eight incoming message types:
https://api.tabletopsimulator.com/externaleditorapi/#pushing-new-object
async function pushingNewObject(api: ExternalEditorApi) {
const gameState = await api.once('pushingNewObject');
console.log(gameState);
}
https://api.tabletopsimulator.com/externaleditorapi/#loading-a-new-game
async function loadingANewGame(api: ExternalEditorApi) {
const gameState = await api.once('loadingANewGame');
console.log(gameState);
}
https://api.tabletopsimulator.com/externaleditorapi/#printdebug-messages
async function printDebugMessage(api: ExternalEditorApi) {
const debugMessage = await api.once('printDebugMessage');
console.log(debugMessage);
}
https://api.tabletopsimulator.com/externaleditorapi/#error-messages
async function errorMessage(api: ExternalEditorApi) {
const errorMessage = await api.once('errorMessage');
console.log(errorMessage);
}
https://api.tabletopsimulator.com/externaleditorapi/#custom-messages
async function customMessage(api: ExternalEditorApi) {
const customMessage = await api.once('customMessage');
console.log(customMessage);
}
https://api.tabletopsimulator.com/externaleditorapi/#return-messages
async function returnMessage(api: ExternalEditorApi) {
const returnMessage = await api.once('returnMessage');
console.log(returnMessage);
}
https://api.tabletopsimulator.com/externaleditorapi/#game-saved
async function gameSaved(api: ExternalEditorApi) {
await api.once('gameSaved');
}
https://api.tabletopsimulator.com/externaleditorapi/#object-created
async function objectCreated(api: ExternalEditorApi) {
const objectCreated = await api.once('objectCreated');
console.log(objectCreated);
}
A stub of the Tabletop Simulator server, or backend, is also provided to make
it easier to test usages of the ExternalEditorApi
client. For examples of use see test/fake_tts_test.ts
.