koishi-plugin-mcdle 0.1.3 → 0.1.4

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 +52 -11
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -15608,22 +15608,38 @@ var Config = import_koishi.Schema.object({
15608
15608
  allowRepeatedGuesses: import_koishi.Schema.boolean().default(false).description("允许重复猜测已猜过的词语(防止撤回时历史不可见)"),
15609
15609
  disableImages: import_koishi.Schema.boolean().default(false).description("不发送图片,全部改用文本(解决网络问题导致的图片下载失败)")
15610
15610
  });
15611
- var FORMAT_VERSION = 1;
15611
+ var FORMAT_VERSION = 2;
15612
+ var guessesField = {
15613
+ type: "text",
15614
+ initial: [],
15615
+ dump(value) {
15616
+ return JSON.stringify(Array.isArray(value) ? value : []);
15617
+ },
15618
+ load(value) {
15619
+ if (Array.isArray(value)) return value;
15620
+ if (!value) return [];
15621
+ try {
15622
+ const parsed = JSON.parse(value);
15623
+ return Array.isArray(parsed) ? parsed : [];
15624
+ } catch {
15625
+ return [];
15626
+ }
15627
+ }
15628
+ };
15612
15629
  function apply(ctx, cfg) {
15613
15630
  ctx.model.extend(
15614
15631
  "mcdle",
15615
15632
  {
15616
15633
  channelId: "string",
15617
15634
  answer: { type: "json", initial: null },
15618
- guesses: { type: "list", initial: [] },
15635
+ guesses: guessesField,
15619
15636
  historyChineseTitles: { type: "list", initial: [] },
15620
15637
  guessedChineseTitles: { type: "list", initial: [] },
15621
15638
  dailyPlayedToday: { type: "unsigned", initial: 0 },
15622
15639
  gameEnded: { type: "boolean", initial: true },
15623
15640
  lastGameStartTime: { type: "timestamp", initial: /* @__PURE__ */ new Date(0) },
15624
15641
  gameMode: { type: "string", initial: null },
15625
- // 猜测记录的写入格式:旧版本留下的进行中一局无法用现在的图片牌面渲染,
15626
- // 靠这一列把它们认出来(老行迁移后为 0/null)
15642
+ // 猜测记录的写入格式:靠这一列识别需要重建或回退的旧局面。
15627
15643
  formatVersion: { type: "unsigned", initial: 0 }
15628
15644
  },
15629
15645
  {
@@ -15916,16 +15932,31 @@ ${words.join(" ")}`).join("\n\n")
15916
15932
  const now = /* @__PURE__ */ new Date();
15917
15933
  await resetDailyIfNeeded(session, record, now);
15918
15934
  if (!record.gameEnded && record.formatVersion !== FORMAT_VERSION) {
15919
- if (record.guesses.length) {
15935
+ if (record.guessedChineseTitles.length) {
15936
+ const restored = restoreGuessHistory(record);
15937
+ if (restored) {
15938
+ await ctx.database.set(
15939
+ "mcdle",
15940
+ { channelId: session.channelId },
15941
+ { guesses: restored, formatVersion: FORMAT_VERSION }
15942
+ );
15943
+ record.guesses = restored;
15944
+ record.formatVersion = FORMAT_VERSION;
15945
+ } else {
15946
+ await rollbackLegacyGame(session, record, guess, now);
15947
+ return;
15948
+ }
15949
+ } else if (record.guesses.length) {
15920
15950
  await rollbackLegacyGame(session, record, guess, now);
15921
15951
  return;
15952
+ } else {
15953
+ await ctx.database.set(
15954
+ "mcdle",
15955
+ { channelId: session.channelId },
15956
+ { formatVersion: FORMAT_VERSION }
15957
+ );
15958
+ record.formatVersion = FORMAT_VERSION;
15922
15959
  }
15923
- await ctx.database.set(
15924
- "mcdle",
15925
- { channelId: session.channelId },
15926
- { formatVersion: FORMAT_VERSION }
15927
- );
15928
- record.formatVersion = FORMAT_VERSION;
15929
15960
  }
15930
15961
  if (record.gameEnded) {
15931
15962
  await startNewGame(session, record, guess, now);
@@ -15934,6 +15965,16 @@ ${words.join(" ")}`).join("\n\n")
15934
15965
  }
15935
15966
  }
15936
15967
  __name(c, "c");
15968
+ function restoreGuessHistory(record) {
15969
+ const mode = record.gameMode;
15970
+ if (!mode || !MODES[mode] || !record.answer) return null;
15971
+ const entries = record.guessedChineseTitles.map(
15972
+ (title) => POOLS[mode].find((entry) => entry.chinese_title === title)
15973
+ );
15974
+ if (entries.some((entry) => !entry)) return null;
15975
+ return entries.map((entry) => compareData(entry, record.answer));
15976
+ }
15977
+ __name(restoreGuessHistory, "restoreGuessHistory");
15937
15978
  async function rollbackLegacyGame(session, record, guess, now) {
15938
15979
  const answerTitle = record.answer?.chinese_title;
15939
15980
  const history = answerTitle ? record.historyChineseTitles.filter((title) => title !== answerTitle) : record.historyChineseTitles;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-mcdle",
3
3
  "description": "Koishi 的 Minecraft 猜词游戏插件。",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [