diff --git a/src/index.ts b/src/index.ts index cf54969..501d9b3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,6 +88,7 @@ export interface SendCustomMessage extends JsonMessage<2> { * @see https://api.tabletopsimulator.com/externaleditorapi/#execute-lua-code. */ export interface ExecuteLuaCode extends JsonMessage<3> { + returnID: number; guid: string; script: string; } @@ -108,6 +109,7 @@ export interface PushingNewObject extends JsonMessage<0> { */ export interface LoadingANewGame extends JsonMessage<1> { scriptStates: IncomingJsonObject[]; + savePath: string; // Undocumented } /** @@ -157,6 +159,7 @@ export interface CustomMessage extends JsonMessage<4> { */ export interface ReturnMessage extends JsonMessage<5> { returnValue: unknown; + returnID: number; // Undocumented } /** @@ -164,7 +167,9 @@ export interface ReturnMessage extends JsonMessage<5> { * * @see https://api.tabletopsimulator.com/externaleditorapi/#return-messages. */ -export type GameSaved = JsonMessage<6>; +export interface GameSaved extends JsonMessage<6> { + savePath: string; // Undocumented +} /** * Occurs whenever an object is created. @@ -358,9 +363,14 @@ export default class ExternalEditorApi extends Emittery.Typed< * * @see https://api.tabletopsimulator.com/externaleditorapi/#execute-lua-code */ - public async executeLuaCode(script: string, guid = '-1'): Promise { + public async executeLuaCode( + script: string, + guid = '-1', + returnID = 0, + ): Promise { const message: ExecuteLuaCode = { messageID: 3, + returnID, script, guid, }; @@ -370,8 +380,9 @@ export default class ExternalEditorApi extends Emittery.Typed< public async executeLuaCodeAndReturn( script: string, guid = '-1', + returnID = 0, ): Promise { - await this.executeLuaCode(script, guid); + await this.executeLuaCode(script, guid, returnID); return this.once('returnMessage').then((v) => v.returnValue as T); } } @@ -488,6 +499,8 @@ export class TTSApiBackend extends Emittery.Typed< public loadNewGame(scriptStates: IncomingJsonObject[]): Promise { const message: LoadingANewGame = { messageID: 1, + savePath: + 'C:\\Users\\FakeUser\\Documents\\My Games\\Tabletop Simulator\\Saves\\TS_Save_1.json', scriptStates, }; return this.send(message); @@ -526,6 +539,7 @@ export class TTSApiBackend extends Emittery.Typed< public returnMessage(returnValue: unknown): Promise { const message: ReturnMessage = { messageID: 5, + returnID: 0, returnValue, }; return this.send(message); @@ -534,6 +548,8 @@ export class TTSApiBackend extends Emittery.Typed< public gameSaved(): Promise { const message: GameSaved = { messageID: 6, + savePath: + 'C:\\Users\\FakeUser\\Documents\\My Games\\Tabletop Simulator\\Saves\\TS_Save_1.json', }; return this.send(message); } diff --git a/test/fake_tts_test.ts b/test/fake_tts_test.ts index 6ad8e06..e431afb 100644 --- a/test/fake_tts_test.ts +++ b/test/fake_tts_test.ts @@ -47,6 +47,8 @@ test('should receive pushingNewObject', async () => { test('should receive pushingNewObject', async () => { const data: LoadingANewGame = { messageID: 1, + savePath: + 'C:\\Users\\FakeUser\\Documents\\My Games\\Tabletop Simulator\\Saves\\TS_Save_1.json', scriptStates: [ { name: 'Global', @@ -97,6 +99,7 @@ test('should receive customMessage', async () => { test('should receive returnMessage', async () => { const data: ReturnMessage = { messageID: 5, + returnID: 0, returnValue: true, }; expect(client.once('returnMessage')).resolves.toEqual(data); @@ -120,6 +123,8 @@ test('should receive objectCreated', async () => { test('should send getLuaScripts', async () => { const outgoing: LoadingANewGame = { messageID: 1, + savePath: + 'C:\\Users\\FakeUser\\Documents\\My Games\\Tabletop Simulator\\Saves\\TS_Save_1.json', scriptStates: [ { name: 'Global', @@ -158,6 +163,8 @@ test('should send saveAndPlay', async () => { }; const outgoing: LoadingANewGame = { messageID: 1, + savePath: + 'C:\\Users\\FakeUser\\Documents\\My Games\\Tabletop Simulator\\Saves\\TS_Save_1.json', scriptStates: [ { name: 'Global', @@ -194,6 +201,7 @@ test('should send customMessage', async () => { test('should send executeLuaCode', async () => { const data: ExecuteLuaCode = { messageID: 3, + returnID: 0, guid: '-1', script: 'print("Hello, World")', };