Add bolding for plusses
This commit is contained in:
parent
0e9661f146
commit
a5979647fc
@ -66,16 +66,31 @@ const pieceDef = <T extends Piece["type"], M extends PieceMeasure>(
|
||||
const textPiece = pieceDef({
|
||||
type: "text",
|
||||
measure(context, piece) {
|
||||
context.save();
|
||||
const fontInfo = parseFont(context.font);
|
||||
if (piece.isBold) {
|
||||
fontInfo.weight = "bold";
|
||||
}
|
||||
if (piece.isItalic) {
|
||||
fontInfo.style = "italic";
|
||||
}
|
||||
const font = stringifyFont(fontInfo);
|
||||
context.font = font;
|
||||
const metrics = context.measureText(piece.text);
|
||||
context.restore();
|
||||
return {
|
||||
type: "content",
|
||||
width: metrics.width,
|
||||
ascent: metrics.fontBoundingBoxAscent,
|
||||
descent: metrics.fontBoundingBoxDescent,
|
||||
font,
|
||||
};
|
||||
},
|
||||
render(context, piece, x, y) {
|
||||
render(context, piece, x, y, measure) {
|
||||
context.save();
|
||||
context.font = measure.font;
|
||||
context.fillText(piece.text, x, y);
|
||||
context.restore();
|
||||
},
|
||||
});
|
||||
|
||||
@ -100,8 +115,8 @@ const breakPiece = pieceDef({
|
||||
return {
|
||||
type: "break",
|
||||
width: 0,
|
||||
ascent: metrics.fontBoundingBoxAscent,
|
||||
descent: metrics.fontBoundingBoxDescent,
|
||||
ascent: metrics.fontBoundingBoxAscent / 3,
|
||||
descent: metrics.fontBoundingBoxDescent / 3,
|
||||
};
|
||||
},
|
||||
render() {},
|
||||
@ -310,6 +325,23 @@ export const parse = (text: string): Piece[] => {
|
||||
const end = text.slice(i).match(/\$\d*/)![0].length;
|
||||
pieces.push({ type: "coin", text: text.slice(i + 1, i + end) });
|
||||
i += end - 1;
|
||||
} else if (char === "+") {
|
||||
const match = text.slice(i).match(/\+\d* \S+/);
|
||||
if (match) {
|
||||
const end = match[0].length;
|
||||
pieces.push({
|
||||
type: "text",
|
||||
isBold: true,
|
||||
text: text.slice(i, i + end),
|
||||
});
|
||||
i += end - 1;
|
||||
} else {
|
||||
pieces.push({
|
||||
type: "text",
|
||||
isBold: true,
|
||||
text: "+",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const end = text.slice(i).match(/[^$ \n]+/)![0].length;
|
||||
pieces.push({ type: "text", text: text.slice(i, i + end) });
|
||||
|
@ -159,8 +159,8 @@ const drawStandardCard = async (
|
||||
context,
|
||||
parse(card.description),
|
||||
w / 2,
|
||||
1520,
|
||||
1100
|
||||
1490,
|
||||
1000
|
||||
);
|
||||
// Draw the types
|
||||
let size = 65;
|
||||
|
@ -8,7 +8,8 @@ import {
|
||||
export const sampleCard1: DominionCard = {
|
||||
orientation: "card",
|
||||
title: "Title",
|
||||
description: "Hello, world.",
|
||||
description:
|
||||
"+1 Action\n\nReveal the top card of your deck. If it's an Action card, put it into your hand.",
|
||||
types: [TYPE_ACTION, TYPE_REACTION],
|
||||
image: "https://wiki.dominionstrategy.com/images/7/76/AdventurerArt.jpg",
|
||||
artist: "Dall-E",
|
||||
|
Loading…
x
Reference in New Issue
Block a user