2022-01-03 13:10:48 -05:00
|
|
|
useLibrary("threads");
|
2021-09-16 14:05:40 -04:00
|
|
|
|
2022-06-05 20:29:25 -04:00
|
|
|
const Card = require("ttsdeck/Card.js");
|
2021-09-29 18:05:58 -04:00
|
|
|
|
2021-09-30 02:35:13 -04:00
|
|
|
const TTS_CARDS_PER_IMAGE = 69;
|
|
|
|
const TTS_MAX_ROWS = 7;
|
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
function TTSDeckPage(image_format, image_resolution, page_num, cards) {
|
|
|
|
this.image_format = image_format;
|
|
|
|
this.image_resolution = image_resolution;
|
|
|
|
this.page_num = page_num;
|
|
|
|
this.cards = cards;
|
2021-09-17 17:04:17 -04:00
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
this.rows = Math.min(Math.ceil(Math.sqrt(cards.length)), TTS_MAX_ROWS);
|
|
|
|
this.columns = Math.ceil(cards.length / this.rows);
|
|
|
|
this.deck_image = null;
|
|
|
|
this.card_jsons = [];
|
2021-09-18 01:26:15 -04:00
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
this.face_url = String(
|
|
|
|
Card.getImageFile(cards[0].member.parent, image_format, this.page_num)
|
|
|
|
.toPath()
|
|
|
|
.toUri()
|
|
|
|
);
|
|
|
|
this.back_url = String(
|
|
|
|
Card.getImageFile(cards[0].member.parent, image_format, "back")
|
|
|
|
.toPath()
|
|
|
|
.toUri()
|
2022-01-03 13:10:48 -05:00
|
|
|
);
|
|
|
|
}
|
2022-01-01 22:22:51 -05:00
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
TTSDeckPage.prototype.build = function build(busy_props) {
|
2021-09-29 18:12:09 -04:00
|
|
|
let deck_graphics;
|
|
|
|
|
2021-09-30 02:35:13 -04:00
|
|
|
for (let row = 0; row < this.rows; row++) {
|
2022-01-03 13:10:48 -05:00
|
|
|
for (
|
|
|
|
let col = 0;
|
2022-01-06 14:50:13 -05:00
|
|
|
col < this.columns && row * this.columns + col < this.cards.length;
|
2022-01-03 13:10:48 -05:00
|
|
|
col++
|
|
|
|
) {
|
2022-01-06 14:50:13 -05:00
|
|
|
if (busy_props.cancelled) return this;
|
|
|
|
|
2021-09-30 02:35:13 -04:00
|
|
|
let index = row * this.columns + col;
|
2022-01-06 14:50:13 -05:00
|
|
|
let card = this.cards[index];
|
2022-01-03 13:07:09 -05:00
|
|
|
busy_props.status = "Processing Card " + card.member;
|
2022-01-06 14:50:13 -05:00
|
|
|
busy_props.currentProgress =
|
|
|
|
(this.page_num - 1) * TTS_CARDS_PER_IMAGE + index;
|
2021-09-29 18:12:09 -04:00
|
|
|
|
|
|
|
try {
|
2022-01-06 14:50:13 -05:00
|
|
|
let copies = card.copyCount();
|
2021-09-29 18:12:09 -04:00
|
|
|
|
|
|
|
for (let ii = 0; ii < copies; ii++) {
|
2022-01-06 14:50:13 -05:00
|
|
|
this.card_jsons.push(card.makeJSON(this.page_num * 100 + index));
|
2021-09-29 18:12:09 -04:00
|
|
|
}
|
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
let card_image = card.makeImage(
|
|
|
|
this.image_format,
|
|
|
|
this.image_resolution
|
|
|
|
);
|
2021-09-29 18:12:09 -04:00
|
|
|
|
2021-09-30 02:35:13 -04:00
|
|
|
if (!this.deck_image) {
|
|
|
|
this.deck_image = ImageUtils.create(
|
2022-01-03 13:10:48 -05:00
|
|
|
card_image.width * this.columns,
|
|
|
|
card_image.height * this.rows,
|
|
|
|
false
|
|
|
|
);
|
2021-09-30 02:35:13 -04:00
|
|
|
deck_graphics = this.deck_image.createGraphics();
|
2021-09-29 18:12:09 -04:00
|
|
|
}
|
|
|
|
|
2022-01-03 13:10:48 -05:00
|
|
|
deck_graphics.drawImage(
|
|
|
|
card_image,
|
|
|
|
col * card_image.width,
|
|
|
|
row * card_image.height,
|
|
|
|
null
|
|
|
|
);
|
2021-09-29 18:12:09 -04:00
|
|
|
} catch (ex) {
|
2022-01-03 13:10:48 -05:00
|
|
|
Thread.invokeLater(() =>
|
|
|
|
alert("Error while processing " + card + ": " + ex, true)
|
|
|
|
);
|
2021-09-29 18:12:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
println("End of Row ", row);
|
|
|
|
}
|
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
return this;
|
|
|
|
};
|
2021-09-30 02:35:13 -04:00
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
function TTSDeck(image_format, image_resolution, cards) {
|
|
|
|
this.image_format = image_format;
|
|
|
|
this.image_resolution = image_resolution;
|
|
|
|
this.cards = cards;
|
2021-09-29 18:12:09 -04:00
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
this.pages = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
TTSDeck.prototype.build = function build(busy_props) {
|
2021-09-30 03:00:32 -04:00
|
|
|
busy_props.title = "Processing Cards";
|
2022-01-06 14:50:13 -05:00
|
|
|
busy_props.maximumProgress = this.cards.length;
|
2021-09-30 03:00:32 -04:00
|
|
|
|
2022-01-03 13:10:48 -05:00
|
|
|
for (
|
|
|
|
let page_num = 0;
|
2022-01-06 14:50:13 -05:00
|
|
|
page_num * TTS_CARDS_PER_IMAGE < this.cards.length;
|
2022-01-03 13:10:48 -05:00
|
|
|
page_num++
|
|
|
|
) {
|
2022-01-06 14:50:13 -05:00
|
|
|
if (busy_props.cancelled) return this;
|
|
|
|
|
|
|
|
let page_cards = this.cards.slice(
|
2022-01-03 13:10:48 -05:00
|
|
|
page_num * TTS_CARDS_PER_IMAGE,
|
|
|
|
(page_num + 1) * TTS_CARDS_PER_IMAGE
|
|
|
|
);
|
2021-09-30 02:35:13 -04:00
|
|
|
printf("Making page %d, with %d cards:\n", page_num + 1, page_cards.length);
|
2022-01-06 14:50:13 -05:00
|
|
|
this.pages.push(
|
2022-01-03 13:10:48 -05:00
|
|
|
new TTSDeckPage(
|
2022-01-06 14:50:13 -05:00
|
|
|
this.image_format,
|
|
|
|
this.image_resolution,
|
2022-01-03 13:10:48 -05:00
|
|
|
page_num + 1,
|
2022-01-06 14:50:13 -05:00
|
|
|
page_cards
|
|
|
|
).build(busy_props)
|
2022-01-03 13:10:48 -05:00
|
|
|
);
|
2021-09-30 02:35:13 -04:00
|
|
|
}
|
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
TTSDeck.prototype.getImages = function getImages() {
|
|
|
|
return this.pages.map((page) => page.deck_image);
|
|
|
|
};
|
|
|
|
|
|
|
|
TTSDeck.prototype.makeJSON = function makeJSON(nickname, description) {
|
|
|
|
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,
|
2021-09-16 14:05:40 -04:00
|
|
|
},
|
2022-06-05 21:36:47 -04:00
|
|
|
Nickname: nickname || "",
|
|
|
|
Description: description || "",
|
2022-01-06 14:50:13 -05:00
|
|
|
ColorDiffuse: {
|
|
|
|
r: 0.713239133,
|
|
|
|
g: 0.713239133,
|
|
|
|
b: 0.713239133,
|
2022-01-03 13:10:48 -05:00
|
|
|
},
|
2022-01-06 14:50:13 -05:00
|
|
|
Grid: true,
|
|
|
|
Locked: false,
|
|
|
|
SidewaysCard: false,
|
|
|
|
DeckIDs: this.pages
|
|
|
|
.map((page) => page.card_jsons.map((card) => card.CardID))
|
|
|
|
.reduce((acc, val) => acc.concat(val), []),
|
|
|
|
CustomDeck: this.pages.reduce((acc, page, index) => {
|
|
|
|
acc[String(index + 1)] = {
|
2022-06-05 21:36:47 -04:00
|
|
|
FaceURL: page.face_url,
|
|
|
|
BackURL: page.back_url,
|
2022-01-06 14:50:13 -05:00
|
|
|
NumWidth: page.columns,
|
|
|
|
NumHeight: page.rows,
|
|
|
|
BackIsHidden: true,
|
|
|
|
};
|
|
|
|
return acc;
|
|
|
|
}, {}),
|
|
|
|
ContainedObjects: this.pages
|
|
|
|
.map((page) => page.card_jsons)
|
|
|
|
.reduce((acc, val) => acc.concat(val), []),
|
|
|
|
};
|
|
|
|
};
|
2021-09-16 14:05:40 -04:00
|
|
|
|
2022-01-06 14:50:13 -05:00
|
|
|
module.exports = {
|
|
|
|
TTSDeckPage: TTSDeckPage,
|
|
|
|
TTSDeck: TTSDeck,
|
|
|
|
};
|