koishi-plugin-xxck-1 0.0.113 → 0.0.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +27 -30
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -85,8 +85,8 @@ async function _warehouse_draw_image(ctx, user_cards, show_name) {
85
85
  const col_width = 320;
86
86
  const col_gap = 10;
87
87
  const row_height = 26;
88
- const title_height = 60;
89
88
  const padding = 15;
89
+ const start_y = 45;
90
90
  const validCards = (user_cards || []).filter((card) => Array.isArray(card) && card.length >= 4);
91
91
  const sortedCards = [...validCards].sort((a, b) => {
92
92
  const starA = a[3] ?? 0;
@@ -96,43 +96,40 @@ async function _warehouse_draw_image(ctx, user_cards, show_name) {
96
96
  if (starB !== starA) {
97
97
  return starB - starA;
98
98
  }
99
- return String(idA).localeCompare(String(idB), void 0, { numeric: true, sensitivity: "base" });
99
+ return String(idA).localeCompare(String(idB), void 0, { numeric: true });
100
100
  });
101
101
  const total_cards = sortedCards.length;
102
102
  const col_count = Math.ceil(total_cards / COL_NUM);
103
103
  const max_rows = Math.min(COL_NUM, Math.max(total_cards, 1));
104
- const img_width = padding + col_count * (col_width + col_gap) - col_gap;
105
- const img_height = title_height + max_rows * row_height + padding * 2;
104
+ const img_width = padding + col_count * (col_width + col_gap);
105
+ const img_height = start_y + max_rows * row_height + padding;
106
106
  const canvas = ctx.canvas.createCanvas(img_width, img_height);
107
+ const buffer = await canvas.toBuffer("image/png");
107
108
  const ctx2d = canvas.getContext("2d");
108
- if (!ctx2d) {
109
- logger.error("[仓库绘图] 获取画布上下文失败");
110
- return null;
111
- }
109
+ if (!ctx2d) return null;
112
110
  ctx2d.textBaseline = "alphabetic";
113
111
  ctx2d.textAlign = "left";
114
112
  ctx2d.fillStyle = "#ffffff";
115
113
  ctx2d.fillRect(0, 0, img_width, img_height);
116
114
  ctx2d.font = "20px Microsoft YaHei";
117
115
  ctx2d.fillStyle = "#000000";
118
- ctx2d.fillText(`用户:${show_name}`, padding, padding + 25);
119
- if (!total_cards) {
120
- ctx2d.fillText("暂无卡片", padding, title_height + padding);
121
- } else {
122
- sortedCards.forEach((card, idx) => {
123
- const [card_level, card_id, card_name, card_star] = card;
124
- const col = Math.floor(idx / COL_NUM);
125
- const row = idx % COL_NUM;
126
- const x = padding + col * (col_width + col_gap);
127
- const y = title_height + row * row_height;
128
- const starText = get_star_symbol(card_star);
129
- const displayText = `[${card_level}] ${card_id} ${card_name} ${starText}`;
130
- ctx2d.fillStyle = STAR_COLOR[card_star];
131
- ctx2d.font = "16px Microsoft YaHei";
132
- ctx2d.fillText(displayText, x, y + 18);
133
- });
116
+ ctx2d.fillText(`用户:${show_name}`, padding, 30);
117
+ if (total_cards === 0) {
118
+ ctx2d.fillText("暂无卡片", padding, start_y);
119
+ return import_koishi.h.image(buffer, "image/png");
134
120
  }
135
- const buffer = await canvas.toBuffer("image/png");
121
+ sortedCards.forEach((card, idx) => {
122
+ const [card_level, card_id, card_name, card_star] = card;
123
+ const col = Math.floor(idx / COL_NUM);
124
+ const row = idx % COL_NUM;
125
+ const x = padding + col * (col_width + col_gap);
126
+ const y = start_y + row * row_height;
127
+ const starText = get_star_symbol(card_star);
128
+ const displayText = `[${card_level}] ${card_id} ${card_name} ${starText}`;
129
+ ctx2d.fillStyle = STAR_COLOR[card_star];
130
+ ctx2d.font = "16px Microsoft YaHei";
131
+ ctx2d.fillText(displayText, x, y + 18);
132
+ });
136
133
  logger.info("仓库图片生成成功 ✅");
137
134
  return import_koishi.h.image(buffer, "image/png");
138
135
  } catch (err) {
@@ -202,11 +199,11 @@ async function _shop_draw_image(ctx, enrichedShopCards, user_disturbance, user_w
202
199
  }
203
200
  __name(_shop_draw_image, "_shop_draw_image");
204
201
  async function _collection_draw_image(ctx, show_name, total_collected, total_all, categoryProgress, categoryCards) {
205
- logger.info("开始绘制收藏图片(修复首个年份错位·终极版)");
202
+ logger.info("开始绘制收藏图片(绝对对齐+带?+支持4字名)");
206
203
  try {
207
204
  if (!ctx.canvas) return null;
208
- const BASE_X = 50;
209
- const CARD_SIZE = 60;
205
+ const BASE_X = 40;
206
+ const CARD_SIZE = 70;
210
207
  const CARD_GAP = 10;
211
208
  const ROW_HEIGHT = CARD_SIZE + CARD_GAP;
212
209
  let totalHeight = 140;
@@ -265,7 +262,7 @@ async function _collection_draw_image(ctx, show_name, total_collected, total_all
265
262
  y += ROW_HEIGHT;
266
263
  }
267
264
  ctx2d.fillStyle = "#fff";
268
- ctx2d.strokeStyle = "#ddd";
265
+ ctx2d.strokeStyle = "#e5e5e5";
269
266
  ctx2d.fillRect(x, y, CARD_SIZE, CARD_SIZE);
270
267
  ctx2d.strokeRect(x, y, CARD_SIZE, CARD_SIZE);
271
268
  ctx2d.textAlign = "center";
@@ -289,7 +286,7 @@ async function _collection_draw_image(ctx, show_name, total_collected, total_all
289
286
  logger.info("收藏图片生成成功 ✅");
290
287
  return import_koishi.h.image(buffer, "image/png");
291
288
  } catch (err) {
292
- logger.error("绘图失败:", err);
289
+ logger.error("收藏绘图失败:", err);
293
290
  return null;
294
291
  }
295
292
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-xxck-1",
3
3
  "description": "自用抽卡",
4
- "version": "0.0.113",
4
+ "version": "0.0.115",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [