From b4ab2e0c857871e1532218e43281aa25246cb590 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 29 Sep 2021 18:05:58 -0400 Subject: [PATCH] Move TTS JSON functions to a separate module --- resources/TTSDeck.js | 94 +++----------------------------------------- resources/TTSJson.js | 88 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 89 deletions(-) create mode 100644 resources/TTSJson.js diff --git a/resources/TTSDeck.js b/resources/TTSDeck.js index e292216..a375552 100644 --- a/resources/TTSDeck.js +++ b/resources/TTSDeck.js @@ -10,6 +10,8 @@ useLibrary('imageutils'); useLibrary('uilayout'); importClass(arkham.project.CopiesList); +const TTSJson = require('./TTSJson.js'); + // The resolution (in pixels per inch) of the exported images const RESOLUTION = 200; // The extension of the image file format to use, e.g., png, jpg @@ -36,92 +38,6 @@ function unload() { // Creates a test button during development that calls unload() to clean up. testProjectScript(); -function makeCardJSON(card_id, nickname, description) { - return { - Name: "Card", - Transform: { - posX: 0, - posY: 0, - posZ: 0, - rotX: 0, - rotY: 0, - rotZ: 0, - scaleX: 1.0, - scaleY: 1.0, - scaleZ: 1.0, - }, - Nickname: String(nickname), - CardID: card_id, - Description: String(description || ""), - ColorDiffuse: { - r: 0.713235259, - g: 0.713235259, - b: 0.713235259, - }, - Locked: false, - Grid: true, - Snap: true, - Autoraise: true, - Sticky: true, - Tooltip: true, - SidewaysCard: false, - }; -} - -function makeDeckJSON(face_url, back_url, num_width, num_height, cards, nickname, description) { - const deck_ids = cards.map(function (card) { - return card.CardID; - }); - return { - Name: "DeckCustom", - Transform: { - posX: 0, - posY: 0, - posZ: 0, - rotX: 0, - rotY: 0.0, - rotZ: 0.0, - scaleX: 1.0, - scaleY: 1.0, - scaleZ: 1.0, - }, - Nickname: String(nickname || ""), - Description: String(description || ""), - ColorDiffuse: { - r: 0.713239133, - g: 0.713239133, - b: 0.713239133, - }, - Grid: true, - Locked: false, - SidewaysCard: false, - DeckIDs: deck_ids, - CustomDeck: { - "1": { - FaceURL: String(face_url), - BackURL: String(back_url), - NumWidth: num_width, - NumHeight: num_height, - } - }, - ContainedObjects: cards, - }; -} - -function makeSavedObjectJSON(objects, save_name) { - return { - SaveName: String(save_name || ""), - GameMode: "", - Date: "", - Table: "", - Sky: "", - Note: "", - Rules: "", - PlayerTurn: "", - ObjectStates: objects, - }; -} - // Hack to override the default return value of 1 function copyCount(copies_list, name) { const entries = copies_list.getListEntries().map(function (x) { @@ -201,7 +117,7 @@ function run() { let copies = copyCount(copies_list, card.baseName); for (let ii = 0; ii < copies; ii++) { - card_jsons.push(makeCardJSON(100 + index, component.getName())); + card_jsons.push(TTSJson.makeCardJSON(100 + index, component.getName())); } // export front face @@ -222,8 +138,8 @@ function run() { println("End of Row ", row); } - const deck_json = makeDeckJSON('TODO', 'TODO', columns, rows, card_jsons); - const saved_object = makeSavedObjectJSON([deck_json], member.getName()); + const deck_json = TTSJson.makeDeckJSON('TODO', 'TODO', columns, rows, card_jsons); + const saved_object = TTSJson.makeSavedObjectJSON([deck_json], member.getName()); println("Writing output files"); const json_file = new File(member.file, member.getName() + '.json'); diff --git a/resources/TTSJson.js b/resources/TTSJson.js new file mode 100644 index 0000000..a6e3a5d --- /dev/null +++ b/resources/TTSJson.js @@ -0,0 +1,88 @@ +// Helper functions for Tabletop Simulator JSON output + +exports.makeCardJSON = function makeCardJSON(card_id, nickname, description) { + return { + Name: "Card", + Transform: { + posX: 0, + posY: 0, + posZ: 0, + rotX: 0, + rotY: 0, + rotZ: 0, + scaleX: 1.0, + scaleY: 1.0, + scaleZ: 1.0, + }, + Nickname: String(nickname), + CardID: card_id, + Description: String(description || ""), + ColorDiffuse: { + r: 0.713235259, + g: 0.713235259, + b: 0.713235259, + }, + Locked: false, + Grid: true, + Snap: true, + Autoraise: true, + Sticky: true, + Tooltip: true, + SidewaysCard: false, + }; +}; + +exports.makeDeckJSON = function makeDeckJSON( + face_url, back_url, num_width, num_height, cards, nickname, description) { + const deck_ids = cards.map(function (card) { + return card.CardID; + }); + return { + Name: "DeckCustom", + Transform: { + posX: 0, + posY: 0, + posZ: 0, + rotX: 0, + rotY: 0.0, + rotZ: 0.0, + scaleX: 1.0, + scaleY: 1.0, + scaleZ: 1.0, + }, + Nickname: String(nickname || ""), + Description: String(description || ""), + ColorDiffuse: { + r: 0.713239133, + g: 0.713239133, + b: 0.713239133, + }, + Grid: true, + Locked: false, + SidewaysCard: false, + DeckIDs: deck_ids, + CustomDeck: { + "1": { + FaceURL: String(face_url), + BackURL: String(back_url), + NumWidth: num_width, + NumHeight: num_height, + } + }, + ContainedObjects: cards, + }; +}; + +exports.makeSavedObjectJSON = function makeSavedObjectJSON(objects, save_name) { + return { + SaveName: String(save_name || ""), + GameMode: "", + Date: "", + Table: "", + Sky: "", + Note: "", + Rules: "", + PlayerTurn: "", + ObjectStates: objects, + }; +};