Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added undocumented fields #16

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -108,6 +109,7 @@ export interface PushingNewObject extends JsonMessage<0> {
*/
export interface LoadingANewGame extends JsonMessage<1> {
scriptStates: IncomingJsonObject[];
savePath: string; // Undocumented
}

/**
Expand Down Expand Up @@ -157,14 +159,17 @@ export interface CustomMessage extends JsonMessage<4> {
*/
export interface ReturnMessage extends JsonMessage<5> {
returnValue: unknown;
returnID: number; // Undocumented
}

/**
* Occurs whenever the game was saved.
*
* @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.
Expand Down Expand Up @@ -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<void> {
public async executeLuaCode(
script: string,
guid = '-1',
returnID = 0,
): Promise<void> {
const message: ExecuteLuaCode = {
messageID: 3,
returnID,
script,
guid,
};
Expand All @@ -370,8 +380,9 @@ export default class ExternalEditorApi extends Emittery.Typed<
public async executeLuaCodeAndReturn<T>(
script: string,
guid = '-1',
returnID = 0,
): Promise<T> {
await this.executeLuaCode(script, guid);
await this.executeLuaCode(script, guid, returnID);
return this.once('returnMessage').then((v) => v.returnValue as T);
}
}
Expand Down Expand Up @@ -488,6 +499,8 @@ export class TTSApiBackend extends Emittery.Typed<
public loadNewGame(scriptStates: IncomingJsonObject[]): Promise<void> {
const message: LoadingANewGame = {
messageID: 1,
savePath:
'C:\\Users\\FakeUser\\Documents\\My Games\\Tabletop Simulator\\Saves\\TS_Save_1.json',
scriptStates,
};
return this.send(message);
Expand Down Expand Up @@ -526,6 +539,7 @@ export class TTSApiBackend extends Emittery.Typed<
public returnMessage(returnValue: unknown): Promise<void> {
const message: ReturnMessage = {
messageID: 5,
returnID: 0,
returnValue,
};
return this.send(message);
Expand All @@ -534,6 +548,8 @@ export class TTSApiBackend extends Emittery.Typed<
public gameSaved(): Promise<void> {
const message: GameSaved = {
messageID: 6,
savePath:
'C:\\Users\\FakeUser\\Documents\\My Games\\Tabletop Simulator\\Saves\\TS_Save_1.json',
};
return this.send(message);
}
Expand Down
8 changes: 8 additions & 0 deletions test/fake_tts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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")',
};
Expand Down