koishi-plugin-ciyi 1.2.0 → 1.2.2

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 +39 -30
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -417,30 +417,38 @@ function measureBoard(opts) {
417
417
  return { innerW, innerH, rowH };
418
418
  }
419
419
  function drawBoardTable(ctx, x, y, w, opts, rowH) {
420
- const cols = {
421
- no: s(34),
422
- nb: s(74),
423
- gw: s(90),
424
- rk: s(86),
425
- mt: s(150)
426
- };
420
+ const accentW = s(3);
421
+ const gutter = s(10);
427
422
  const tableW = w - s(44);
428
423
  const cx = x + s(22);
424
+ const usable = Math.max(tableW - gutter, s(1));
425
+ const natural = [32, 72, 88, 72, 72, 148];
426
+ const naturalSum = natural.reduce((a, b) => a + b, 0);
427
+ const scale = usable / naturalSum;
428
+ const cols = {
429
+ no: natural[0] * scale,
430
+ nb: natural[1] * scale,
431
+ gw: natural[2] * scale,
432
+ rk: natural[4] * scale,
433
+ mt: natural[5] * scale
434
+ };
435
+ const bx = cx + gutter;
436
+ const nb0 = bx + cols.no;
437
+ const gw0 = nb0 + cols.nb;
438
+ const nb1 = gw0 + cols.gw;
439
+ const rk0 = nb1 + cols.nb;
440
+ const mt0 = rk0 + cols.rk;
441
+ const noX = bx + s(2);
442
+ const meterBlockW = s(88) + s(9) + textWidth("咫尺", s(12.5));
443
+ const mtX = mt0 + Math.max(0, (cols.mt - meterBlockW) / 2);
429
444
  const headY = y;
430
445
  const fs = s(10.5);
431
- textLeft(ctx, "\u5E8F", cx, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
432
- textCenter(ctx, "\u66F4\u8FD1 \u25C0", cx + cols.no + cols.nb / 2, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
433
- textCenter(ctx, "\u731C\u6D4B", cx + cols.no + cols.nb + cols.gw / 2, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
434
- textCenter(
435
- ctx,
436
- "\u25B6 \u66F4\u8FDC",
437
- cx + cols.no + cols.nb + cols.gw + cols.nb / 2,
438
- headY,
439
- `${fs}px ${FONT_SERIF}`,
440
- C.ink3
441
- );
442
- textRight(ctx, "\u6392\u540D", cx + cols.no + cols.nb + cols.gw + cols.nb + cols.rk, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
443
- textRight(ctx, "\u4EB2\u758F", cx + tableW, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
446
+ textLeft(ctx, "", noX, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
447
+ textCenter(ctx, "更近 ", nb0 + cols.nb / 2, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
448
+ textCenter(ctx, "猜测", gw0 + cols.gw / 2, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
449
+ textCenter(ctx, "▶ 更远", nb1 + cols.nb / 2, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
450
+ textCenter(ctx, "排名", rk0 + cols.rk / 2, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
451
+ textCenter(ctx, "亲疏", mt0 + cols.mt / 2, headY, `${fs}px ${FONT_SERIF}`, C.ink3);
444
452
  let ry = y + s(22);
445
453
  let ordinal = 0;
446
454
  for (const row of opts.rows) {
@@ -448,7 +456,7 @@ function drawBoardTable(ctx, x, y, w, opts, rowH) {
448
456
  ry += s(8);
449
457
  textCenter(
450
458
  ctx,
451
- `\u22EF \u53E6\u6709 ${row.gapBefore} \u8BCD\u672A\u5217 \u22EF`,
459
+ `⋯ 另有 ${row.gapBefore} 词未列 ⋯`,
452
460
  cx + tableW / 2,
453
461
  ry + s(10),
454
462
  `${s(11.5)}px ${FONT_SERIF}`,
@@ -470,7 +478,7 @@ function drawBoardTable(ctx, x, y, w, opts, rowH) {
470
478
  ctx.fillStyle = C.fresh;
471
479
  ctx.fillRect(cx, ry, tableW, rowH);
472
480
  ctx.fillStyle = C.seal;
473
- ctx.fillRect(cx, ry, s(3), rowH);
481
+ ctx.fillRect(cx, ry, accentW, rowH);
474
482
  }
475
483
  ctx.strokeStyle = ordinal === 1 ? C.ruleDark : C.rule;
476
484
  ctx.lineWidth = s(1);
@@ -481,24 +489,25 @@ function drawBoardTable(ctx, x, y, w, opts, rowH) {
481
489
  textLeft(
482
490
  ctx,
483
491
  String(ordinal).padStart(2, "0"),
484
- cx,
492
+ noX,
485
493
  midY,
486
494
  `${s(13)}px ${FONT_NUM}`,
487
495
  C.ink3
488
496
  );
489
- const nbX = cx + cols.no + (cols.nb - gridWidth(history.leftHint, "sm")) / 2;
497
+ const nbX = nb0 + (cols.nb - gridWidth(history.leftHint, "sm")) / 2;
490
498
  drawWordGrid(ctx, nbX, midY - s(13), history.leftHint, "sm", 0);
491
- const gwX = cx + cols.no + cols.nb + (cols.gw - gridWidth(history.guess, "md")) / 2;
499
+ const gwX = gw0 + (cols.gw - gridWidth(history.guess, "md")) / 2;
492
500
  drawWordGrid(ctx, gwX, midY - s(17), history.guess, "md");
493
- const rbX = cx + cols.no + cols.nb + cols.gw + (cols.nb - gridWidth(history.rightHint, "sm")) / 2;
501
+ const rbX = nb1 + (cols.nb - gridWidth(history.rightHint, "sm")) / 2;
494
502
  drawWordGrid(ctx, rbX, midY - s(13), history.rightHint, "sm", 1);
495
- const rkX = cx + cols.no + cols.nb + cols.gw + cols.nb + cols.rk;
496
503
  const rankText = String(history.rank);
497
504
  const rankFont = `700 ${s(21)}px ${FONT_NUM}`;
498
505
  const rankWidth = textWidth(rankText, s(21));
499
- textRight(ctx, "#", rkX - rankWidth - s(3), midY, `${s(13)}px ${FONT_NUM}`, C.ink3);
500
- textRight(ctx, rankText, rkX, midY, rankFont, tier.color);
501
- const mtX = cx + tableW - cols.mt + s(10);
506
+ const hashW = textWidth("#", s(13));
507
+ const rankBlock = hashW + s(3) + rankWidth;
508
+ const rankLeft = rk0 + (cols.rk - rankBlock) / 2;
509
+ textLeft(ctx, "#", rankLeft, midY, `${s(13)}px ${FONT_NUM}`, C.ink3);
510
+ textLeft(ctx, rankText, rankLeft + hashW + s(3), midY, rankFont, tier.color);
502
511
  drawNearBar(ctx, mtX, midY, pct, tier);
503
512
  ry += rowH;
504
513
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ciyi",
3
3
  "description": "Koishi 的词意(猜词游戏)插件。根据词语的含义相似程度,猜测正确的词语。",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [