prts-terrarchive 0.2.3 → 0.2.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/package.json +1 -1
  2. package/src/index.js +22 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prts-terrarchive",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/index.js CHANGED
@@ -876,11 +876,28 @@ async function modelReadToContract(args = {}, store, enabledGames = ['arknights'
876
876
  record = fallback
877
877
  }
878
878
  if (!record) {
879
- const partLabel = storyPart
880
- ? `的${{ before: '行动前剧情', after: '行动后剧情', story: '纯剧情/幕间' }[storyPart]}` : '剧情'
881
- throw Object.assign(new Error(
882
- `本地资料包中找不到关卡 ${stageCode}${partLabel}`,
883
- ), { code: 'DOCUMENT_NOT_FOUND' })
879
+ // 关卡存在但请求的那部分不存在时,先说清这个关卡究竟有哪几篇;
880
+ // 只有一篇时直接返回那篇并注明,别让调用方对着「找不到」猜。
881
+ const labels = { before: '行动前', after: '行动后', story: '纯剧情/幕间' }
882
+ const available = []
883
+ for (const part of ['before', 'after', 'story']) {
884
+ try {
885
+ const found = await store.getDocumentByStoryStage(stageCode, part)
886
+ if (found) available.push({ part, record: found })
887
+ } catch { /* 该部分不存在 */ }
888
+ }
889
+ if (storyPart && available.length === 1 && available[0].part !== storyPart) {
890
+ record = available[0].record
891
+ notes.push(`关卡定位:${stageCode} 没有${labels[storyPart]},只有${labels[available[0].part]},已返回这一篇。`)
892
+ } else {
893
+ const partLabel = storyPart ? `的${labels[storyPart]}剧情` : '剧情'
894
+ const hint = available.length
895
+ ? `(该关卡现有:${available.map((item) => labels[item.part]).join('、')})`
896
+ : '(资料包内没有这个关卡代号)'
897
+ throw Object.assign(new Error(
898
+ `本地资料包中找不到关卡 ${stageCode}${partLabel}${hint}`,
899
+ ), { code: 'DOCUMENT_NOT_FOUND' })
900
+ }
884
901
  }
885
902
  requireEnabled(record)
886
903
  locator = { document_id: record.record.document.document_id }