58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { readFileSync } from "fs";
|
|
import { ECard } from "./encoded";
|
|
import { MDCard, getCardData } from "./mtgdesign";
|
|
|
|
function capitalize(str: string): string {
|
|
return str.toUpperCase().substr(0, 1) + str.substr(1);
|
|
}
|
|
|
|
interface CardInfo {
|
|
set: string;
|
|
total: number;
|
|
num: number;
|
|
}
|
|
|
|
function convertCard(data: ECard, info: CardInfo): MDCard {
|
|
const centered = false; // Center if not much text
|
|
let power = "";
|
|
let toughness = "";
|
|
if (data.pt) {
|
|
[power, toughness] = data.pt.split("/");
|
|
}
|
|
return {
|
|
"card-number": `${info.num}`,
|
|
"card-total": `${info.total}`,
|
|
"card-set": `${info.set}`,
|
|
language: "EN",
|
|
"card-title": data.name,
|
|
"mana-cost": data.cost ? data.cost : "",
|
|
"super-type": data.supertypes
|
|
? data.supertypes.map(capitalize).join(" ")
|
|
: "",
|
|
type: capitalize(data.types[0]),
|
|
"sub-type": data.subtypes ? data.subtypes.map(capitalize).join(" ") : "",
|
|
"text-size": "38",
|
|
rarity: data.rarity.toUpperCase()[0],
|
|
power,
|
|
toughness,
|
|
loyalty: data.loyalty ? data.loyalty : "",
|
|
centered,
|
|
"rules-text": data.text.replace(/@/gi, "~"),
|
|
"flavor-text": ""
|
|
};
|
|
}
|
|
|
|
export function readCardFile(input): ECard[] {
|
|
const lines = readFileSync(input)
|
|
.toString()
|
|
.split("\n");
|
|
return lines
|
|
.filter(x => x.trim().length > 0)
|
|
.map(line => JSON.parse(line.trim()));
|
|
}
|
|
|
|
export function toURL(data: ECard, info: CardInfo): string {
|
|
const mdcard = convertCard(data, info);
|
|
return getCardData(mdcard);
|
|
}
|