Move TTS JSON functions to a separate module

This commit is contained in:
Adam Goldsmith 2021-09-29 18:05:58 -04:00
parent e7f411d5e2
commit b4ab2e0c85
2 changed files with 93 additions and 89 deletions

View File

@ -10,6 +10,8 @@ useLibrary('imageutils');
useLibrary('uilayout'); useLibrary('uilayout');
importClass(arkham.project.CopiesList); importClass(arkham.project.CopiesList);
const TTSJson = require('./TTSJson.js');
// The resolution (in pixels per inch) of the exported images // The resolution (in pixels per inch) of the exported images
const RESOLUTION = 200; const RESOLUTION = 200;
// The extension of the image file format to use, e.g., png, jpg // 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. // Creates a test button during development that calls unload() to clean up.
testProjectScript(); 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 // Hack to override the default return value of 1
function copyCount(copies_list, name) { function copyCount(copies_list, name) {
const entries = copies_list.getListEntries().map(function (x) { const entries = copies_list.getListEntries().map(function (x) {
@ -201,7 +117,7 @@ function run() {
let copies = copyCount(copies_list, card.baseName); let copies = copyCount(copies_list, card.baseName);
for (let ii = 0; ii < copies; ii++) { 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 // export front face
@ -222,8 +138,8 @@ function run() {
println("End of Row ", row); println("End of Row ", row);
} }
const deck_json = makeDeckJSON('TODO', 'TODO', columns, rows, card_jsons); const deck_json = TTSJson.makeDeckJSON('TODO', 'TODO', columns, rows, card_jsons);
const saved_object = makeSavedObjectJSON([deck_json], member.getName()); const saved_object = TTSJson.makeSavedObjectJSON([deck_json], member.getName());
println("Writing output files"); println("Writing output files");
const json_file = new File(member.file, member.getName() + '.json'); const json_file = new File(member.file, member.getName() + '.json');

88
resources/TTSJson.js Normal file
View File

@ -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,
};
};