added loyalty for planeswalkers, fixed bug when height was set to

constant
This commit is contained in:
Lumen Keyes 2024-07-16 11:05:23 -06:00
parent 02903b57da
commit 78bad5b043
3 changed files with 709 additions and 709 deletions

1376
output.pdf

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
//TODO: add loyalty for planeswalkers
//TODO: print mana cost beside each name for dual-faced cards
//TODO: consider eliminating the TextCard struct
//TODO: add some kind of "update" command to support pulling new oracle data
@ -34,9 +33,10 @@ const Card = struct {
cmc: f32 = 0, //float
type_line: []const u8 = "", //string
oracle_text: []const u8 = "", //string
power: []const u8 = "", //coerced to string
toughness: []const u8 = "", //coerced to string
power: ?[]const u8 = null, //coerced to string
toughness: ?[]const u8 = null, //coerced to string
card_faces: ?[]Card = null, //array of cards
loyalty: ?[]const u8 = null, //coerced to string
};
const TextCard = struct {
@ -97,7 +97,6 @@ pub fn main() !void {
} else {
return error.ExpectedArgument;
}
//TODO (FIXME): passing "true" currently causes the program to hang and then crash
if(res.args.constant) |choice| {
constantHeight = std.mem.eql(u8, choice, "true");
}
@ -142,7 +141,6 @@ pub fn main() !void {
for (allPrinted.items) |printLine| {
print("{s}", .{printLine});
}
// std.debug.print("{s}", .{allPrinted.items});
rowToPrint.clearAndFree();
}
var page = c.pdf_append_page(pdf_doc);
@ -182,23 +180,25 @@ fn card(
}
try fullUnformattedText.appendSlice(try std.mem.concat(allocator, u8, &[_][]const u8{
cardObj.oracle_text,
if (cardObj.power.len > 0) " (" else "",
cardObj.power,
if (cardObj.power.len > 0) "/" else "",
cardObj.toughness,
if (cardObj.power.len > 0) ") " else "",
if (cardObj.power) |_| " (" else "",
cardObj.power orelse "",
if (cardObj.power) |_| "/" else "",
cardObj.toughness orelse "",
if (cardObj.power) |_| ") " else "",
if(cardObj.loyalty) |_| "[" else "",
cardObj.loyalty orelse "",
if(cardObj.loyalty) |_| "]" else "",
}));
if (cardObj.card_faces) |faces| {
for (faces, 0..) |face, idx| {
const faceText = (try card(face, allocator, true)).lines;
try fullUnformattedText.appendSlice(std.mem.trim(u8, try std.mem.join(allocator, " ", faceText), "\n"));
if (idx == 0) try fullUnformattedText.appendSlice(" // ");
if (idx == 0) try fullUnformattedText.appendSlice("// ");
}
}
var line = std.ArrayList(u8).init(allocator);
// var word = std.ArrayList(u8).init(allocator);
var wordIterator = std.mem.splitAny(u8, fullUnformattedText.items, "\n ");
while (wordIterator.next()) |word| {
if (line.items.len + word.len + 1 < cardWidth) {
@ -214,19 +214,18 @@ fn card(
} else {
try cardText.append(try line.toOwnedSlice());
}
while (wrongCardHeight(cardText.items.len)) {
if(!isFace and constantHeight) {
const actualHeight: usize = cardText.items.len;
assert(actualHeight <= cardHeight);
const diff = cardHeight - actualHeight;
try cardText.appendNTimes(" " ** (cardWidth - 2), diff);
} else if(!isFace) {
try cardText.append(" " ** (cardWidth - 2));
}
try cardText.append(" " ** (cardWidth - 2));
assert(cardText.items.len <= cardHeight);
return TextCard{ .lines = try cardText.toOwnedSlice() };
}
fn wrongCardHeight(length: usize) bool {
print("{d}\n", .{length});
return (constantHeight and length < cardHeight) or length < minCardHeight;
}
const linesList = std.MultiArrayList(cardRow);
const cardRow = struct {
first: []const u8 = spacer,
@ -263,6 +262,7 @@ const cardRow = struct {
}
const rowHeight = lines.items(.first).len;
while (pageHeight - (allPrinted.items.len % pageHeight) <= rowHeight) {
assert(rowHeight <= pageHeight);
try allPrinted.append(fullWidthSpacer);
}
for (lines.items(.first), 0..) |_, idx| {

Binary file not shown.