@cloud411716/fancy-webnovel 1.0.46 → 3.0.0
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.
- package/client.js +369 -0
- package/cordis.patch.yml +4 -13
- package/docs/douyin-plugin.md +118 -0
- package/docs/material-library/README.md +404 -0
- package/docs/material-library/import.js +437 -0
- package/docs/material-library/prompt.md +370 -0
- package/docs/material-library/queries.surql +94 -0
- package/docs/material-library/sample.jsonl +14 -0
- package/docs/material-library/schema.surql +46 -0
- package/docs/mcp-profile.example.yml +24 -0
- package/docs/story-graph-design.md +602 -0
- package/docs/story-graph-validation.md +81 -0
- package/docs/workspace-mcp.md +284 -0
- package/index.js +26 -38
- package/lib/atomic-write.js +109 -0
- package/lib/chapter-order.js +100 -0
- package/lib/chinese-num.js +111 -0
- package/lib/confirmation.js +80 -0
- package/lib/db-init.js +123 -0
- package/lib/deployed-state.js +141 -0
- package/lib/direction-labels.js +265 -0
- package/lib/error-codes.js +104 -0
- package/lib/infra.js +594 -0
- package/lib/llm-wiki.js +109 -0
- package/lib/material-db.js +149 -0
- package/lib/path-guard.js +150 -0
- package/lib/projects.js +400 -0
- package/lib/scraper-utils.js +305 -0
- package/lib/surreal-server.js +338 -0
- package/lib/topic-decision.js +860 -0
- package/lib/topic-fields.js +251 -0
- package/lib/topic-schema.js +225 -0
- package/lib/workspace.js +501 -0
- package/package.json +62 -5
- package/plugins/fancy-analyze/analyze-definitions.md +519 -0
- package/plugins/fancy-analyze/command-input.js +65 -0
- package/plugins/fancy-analyze/index.js +2024 -0
- package/plugins/fancy-analyze/ingest-coverage.js +107 -0
- package/plugins/fancy-analyze/schema-analyze.md +627 -0
- package/plugins/fancy-analyze/schema-write.md +178 -0
- package/plugins/fancy-analyze/scripts/append-summary-chapter.js +612 -0
- package/plugins/fancy-analyze/scripts/split_source.js +292 -0
- package/plugins/fancy-analyze/summary-progress.js +495 -0
- package/plugins/fancy-analyze/templates.js +1179 -0
- package/plugins/fancy-bootstrap/index.js +313 -0
- package/plugins/fancy-bootstrap/scripts/init.js +177 -0
- package/plugins/fancy-bootstrap/scripts/path-utils.js +21 -0
- package/plugins/fancy-bootstrap/templates.js +71 -0
- package/plugins/fancy-db/index.js +172 -0
- package/plugins/fancy-douyin/deploy.js +134 -0
- package/plugins/fancy-douyin/index.js +551 -0
- package/plugins/fancy-douyin/prompts/01-analysis-prompt.md +84 -0
- package/plugins/fancy-douyin/scripts/crawl-note.cjs +194 -0
- package/plugins/fancy-douyin/scripts/lib.cjs +197 -0
- package/plugins/fancy-douyin/scripts/scan-account.cjs +128 -0
- package/plugins/fancy-douyin/scripts/start-chrome.cjs +203 -0
- package/plugins/fancy-douyin/state.js +197 -0
- package/plugins/fancy-douyin/templates.js +127 -0
- package/plugins/fancy-export/exporter.js +805 -0
- package/plugins/fancy-export/index.js +63 -0
- package/plugins/fancy-import/import-core.js +1118 -0
- package/plugins/fancy-import/import-driver.js +604 -0
- package/plugins/fancy-import/index.js +738 -0
- package/plugins/fancy-import/prompts/01-import-prompt.md +131 -0
- package/plugins/fancy-import/templates.js +58 -0
- package/plugins/fancy-material/exporter.js +153 -0
- package/plugins/fancy-material/genres.js +256 -0
- package/plugins/fancy-material/index.js +835 -0
- package/plugins/fancy-material/inventory.js +143 -0
- package/plugins/fancy-material/kinds.js +313 -0
- package/plugins/fancy-material/queue.js +55 -0
- package/plugins/fancy-material/scripts/query.js +254 -0
- package/plugins/fancy-material/templates.js +258 -0
- package/plugins/fancy-material/tool-deploy.js +138 -0
- package/plugins/fancy-material/validate.js +149 -0
- package/plugins/fancy-project/index.js +133 -0
- package/plugins/fancy-scan/existing-block.js +100 -0
- package/plugins/fancy-scan/index.js +708 -0
- package/plugins/fancy-scan/prompts/01-analysis-prompt.md +302 -0
- package/plugins/fancy-scan/scripts/append-block.js +725 -0
- package/plugins/fancy-scan/scripts/report-validate.js +824 -0
- package/plugins/fancy-scan/scripts/run-scan.js +667 -0
- package/plugins/fancy-scan/scripts/scrapers/fanqie-rank-scraper.js +923 -0
- package/plugins/fancy-scan/scripts/scrapers/jjwxc-rank-scraper.js +469 -0
- package/plugins/fancy-scan/scripts/scrapers/qimao-rank-scraper.js +629 -0
- package/plugins/fancy-scan/templates/blocks.js +155 -0
- package/plugins/fancy-scan/templates/platforms.js +372 -0
- package/plugins/fancy-scan/templates/report-schema.js +90 -0
- package/plugins/fancy-scan/templates.js +694 -0
- package/plugins/fancy-scan/tool-deploy.js +335 -0
- package/plugins/fancy-scan/wait-turn.js +46 -0
- package/plugins/fancy-story-builder/db/README.md +106 -0
- package/plugins/fancy-story-builder/db/client.js +228 -0
- package/plugins/fancy-story-builder/db/commands.js +145 -0
- package/plugins/fancy-story-builder/db/ids.js +39 -0
- package/plugins/fancy-story-builder/db/import.js +798 -0
- package/plugins/fancy-story-builder/db/project.js +299 -0
- package/plugins/fancy-story-builder/db/query.js +361 -0
- package/plugins/fancy-story-builder/db/schema.js +417 -0
- package/plugins/fancy-story-builder/db/stage-sync.js +238 -0
- package/plugins/fancy-story-builder/deploy-manifest.js +239 -0
- package/plugins/fancy-story-builder/deslop-driver.js +821 -0
- package/plugins/fancy-story-builder/flesh-output.js +168 -0
- package/plugins/fancy-story-builder/index.js +6861 -0
- package/plugins/fancy-story-builder/patch-driver.js +390 -0
- package/plugins/fancy-story-builder/prompts/01-skeleton-prompt.md +563 -0
- package/plugins/fancy-story-builder/prompts/02-flesh-prompt.md +602 -0
- package/plugins/fancy-story-builder/prompts/03-rhythm-prompt.md +539 -0
- package/plugins/fancy-story-builder/prompts/04-writing-prompt.md +225 -0
- package/plugins/fancy-story-builder/prompts/05-deslop-prompt.md +96 -0
- package/plugins/fancy-story-builder/purpose-template.md +83 -0
- package/plugins/fancy-story-builder/references/formulas-rhythm.json +302 -0
- package/plugins/fancy-story-builder/references/formulas-skeleton.json +402 -0
- package/plugins/fancy-story-builder/references/genre-profiles.json +3514 -0
- package/plugins/fancy-story-builder/references/glossary.md +594 -0
- package/plugins/fancy-story-builder/references/index.md +581 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/00-index.md +174 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/01-scene.md +150 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/02-chapter-workflow.md +99 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/03-opening-chapter.md +104 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/04-dialogue-mastery.md +274 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/05-genre-formulas.md +432 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/06-tone-ensemble.md +259 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/07-ledger-audit.md +222 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/08-diagnosis-revision.md +205 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/09-reading-power.md +135 -0
- package/plugins/fancy-story-builder/references//345/206/231/344/275/234/346/214/207/345/257/274/10-deslop.md +129 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/00-index.md +98 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/01-upgrade-rhythm.md +300 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/02-arc-rhythm.md +168 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/03-highpoint-hooks.md +189 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/04-satisfaction.md +226 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/05-foreshadow-density.md +195 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/06-chapter-outline.md +226 -0
- package/plugins/fancy-story-builder/references//350/212/202/345/245/217/346/214/207/345/257/274/07-audit.md +181 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/00-index.md +100 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/01-character.md +243 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/02-worldbuilding.md +245 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/03-relations.md +185 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/04-emotion-methods.md +286 -0
- package/plugins/fancy-story-builder/references//350/241/200/350/202/211/346/214/207/345/257/274/05-audit.md +187 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/00-index.md +91 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/01-positioning.md +209 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/02-packaging.md +135 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/03-entities.md +305 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/04-conflict.md +328 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/05-quota.md +187 -0
- package/plugins/fancy-story-builder/references//351/252/250/346/236/266/346/214/207/345/257/274/06-audit.md +160 -0
- package/plugins/fancy-story-builder/rhythm-output.js +140 -0
- package/plugins/fancy-story-builder/schema-setting.json +1100 -0
- package/plugins/fancy-story-builder/schema-setting.md +232 -0
- package/plugins/fancy-story-builder/scripts/ai-patterns.js +619 -0
- package/plugins/fancy-story-builder/scripts/brief-validate.js +164 -0
- package/plugins/fancy-story-builder/scripts/check-guide-compliance.js +289 -0
- package/plugins/fancy-story-builder/scripts/content-quality.js +416 -0
- package/plugins/fancy-story-builder/scripts/deslop-validate.js +143 -0
- package/plugins/fancy-story-builder/scripts/error-classes.js +112 -0
- package/plugins/fancy-story-builder/scripts/flesh-validate.js +1312 -0
- package/plugins/fancy-story-builder/scripts/formula-engine.js +112 -0
- package/plugins/fancy-story-builder/scripts/graph-utils.js +1484 -0
- package/plugins/fancy-story-builder/scripts/label-coverage.js +171 -0
- package/plugins/fancy-story-builder/scripts/prompt-drift-check.js +441 -0
- package/plugins/fancy-story-builder/scripts/reading-power.js +298 -0
- package/plugins/fancy-story-builder/scripts/reference-log.js +110 -0
- package/plugins/fancy-story-builder/scripts/rhythm-validate.js +1312 -0
- package/plugins/fancy-story-builder/scripts/schema-pages.js +2668 -0
- package/plugins/fancy-story-builder/scripts/semantic-lint.js +381 -0
- package/plugins/fancy-story-builder/scripts/skeleton-quota.js +145 -0
- package/plugins/fancy-story-builder/scripts/skeleton-validate.js +1973 -0
- package/plugins/fancy-story-builder/scripts/stage-batches.js +1405 -0
- package/plugins/fancy-story-builder/scripts/stage-contract.js +429 -0
- package/plugins/fancy-story-builder/scripts/story-artifacts.js +933 -0
- package/plugins/fancy-story-builder/scripts/upstream-query.js +198 -0
- package/plugins/fancy-story-builder/scripts/v2/baseline.js +112 -0
- package/plugins/fancy-story-builder/scripts/v2/cast.js +517 -0
- package/plugins/fancy-story-builder/scripts/v2/context.js +434 -0
- package/plugins/fancy-story-builder/scripts/v2/contracts.js +493 -0
- package/plugins/fancy-story-builder/scripts/v2/core.js +419 -0
- package/plugins/fancy-story-builder/scripts/v2/engine.js +1068 -0
- package/plugins/fancy-story-builder/scripts/v2/export-markdown.js +794 -0
- package/plugins/fancy-story-builder/scripts/v2/genre.js +195 -0
- package/plugins/fancy-story-builder/scripts/v2/knowledge.js +321 -0
- package/plugins/fancy-story-builder/scripts/v2/macro.js +409 -0
- package/plugins/fancy-story-builder/scripts/v2/manifest.js +538 -0
- package/plugins/fancy-story-builder/scripts/v2/migrate.js +137 -0
- package/plugins/fancy-story-builder/scripts/v2/prompts.js +1335 -0
- package/plugins/fancy-story-builder/scripts/v2/rhythm.js +618 -0
- package/plugins/fancy-story-builder/scripts/v2/scale.js +843 -0
- package/plugins/fancy-story-builder/scripts/v2/snapshot.js +121 -0
- package/plugins/fancy-story-builder/scripts/v2/stages.js +273 -0
- package/plugins/fancy-story-builder/scripts/v2/writing.js +216 -0
- package/plugins/fancy-story-builder/scripts/writing-rules.js +167 -0
- package/plugins/fancy-story-builder/scripts/writing-validate.js +682 -0
- package/plugins/fancy-story-builder/skeleton-output.js +199 -0
- package/plugins/fancy-story-builder/stage-driver.js +1049 -0
- package/plugins/fancy-story-builder/storydb/README.md +271 -0
- package/plugins/fancy-story-builder/storydb/cli.js +458 -0
- package/plugins/fancy-story-builder/storydb/client.js +351 -0
- package/plugins/fancy-story-builder/storydb/compile.js +452 -0
- package/plugins/fancy-story-builder/storydb/context.js +288 -0
- package/plugins/fancy-story-builder/storydb/definitions.js +699 -0
- package/plugins/fancy-story-builder/storydb/driver.js +106 -0
- package/plugins/fancy-story-builder/storydb/dsh-tools.js +313 -0
- package/plugins/fancy-story-builder/storydb/export.js +175 -0
- package/plugins/fancy-story-builder/storydb/ids.js +31 -0
- package/plugins/fancy-story-builder/storydb/impact.js +170 -0
- package/plugins/fancy-story-builder/storydb/import.js +559 -0
- package/plugins/fancy-story-builder/storydb/mcp.js +99 -0
- package/plugins/fancy-story-builder/storydb/prompts.js +952 -0
- package/plugins/fancy-story-builder/storydb/stage-command.js +379 -0
- package/plugins/fancy-story-builder/storydb/stage.js +426 -0
- package/plugins/fancy-story-builder/storydb/store.js +891 -0
- package/plugins/fancy-story-builder/storydb/tools.js +592 -0
- package/plugins/fancy-story-builder/storydb/validation.js +183 -0
- package/plugins/fancy-story-builder/templates/v2/10-scale/scale-template.json +144 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/emotion-template.json +15 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/endings-template.json +16 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/lines-template.json +28 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/roles-template.json +10 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/story-template.json +19 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/volumes-template.json +24 -0
- package/plugins/fancy-story-builder/templates/v2/20-macro/world-template.json +24 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/characters-template.json +49 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/climaxes-template.json +14 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/conflicts-template.json +30 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/factions-template.json +18 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/foreshadows-template.json +29 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/information-template.json +29 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/items-template.json +13 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/locations-template.json +12 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/payoffs-template.json +16 -0
- package/plugins/fancy-story-builder/templates/v2/30-cast/relations-template.json +44 -0
- package/plugins/fancy-story-builder/templates/v2/40-rhythm/chapter-map-template.json +81 -0
- package/plugins/fancy-story-builder/templates/v2/40-rhythm/outline-template.json +162 -0
- package/plugins/fancy-story-builder/templates/v2/50-writing/ledger-template.json +46 -0
- package/plugins/fancy-story-builder/templates/v2/60-deslop/report-template.json +10 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//346/227/266/345/272/217/346/230/240/345/260/204/346/250/241/346/235/277.json +427 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//347/253/240/350/212/202/347/273/206/347/272/262/346/250/241/346/235/277.json +34 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//347/253/240/350/212/202/350/247/204/345/210/222/346/250/241/346/235/277.json +24 -0
- package/plugins/fancy-story-builder/templates//350/212/202/345/245/217//350/212/202/345/245/217/345/217/202/346/225/260/346/250/241/346/235/277.json +27 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//344/270/226/347/225/214/350/247/202/350/247/204/345/210/231/346/250/241/346/235/277.json +168 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/205/263/351/224/256/351/201/223/345/205/267/346/250/241/346/235/277.json +184 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/205/266/344/273/226/345/256/236/344/275/223/346/250/241/346/235/277.json +62 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/206/262/347/252/201/346/250/241/346/235/277.json +131 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/211/247/346/203/205/346/250/241/346/235/277.json +85 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/212/277/345/212/233/346/250/241/346/235/277.json +103 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//345/234/260/347/202/271/346/250/241/346/235/277.json +68 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//347/273/223/345/261/200/346/250/241/346/235/277.json +142 -0
- package/plugins/fancy-story-builder/templates//350/241/200/350/202/211//350/247/222/350/211/262/346/250/241/346/235/277.json +292 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/205/263/347/263/273/346/250/241/346/235/277.json +266 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/256/236/344/275/223/346/250/241/346/235/277.json +336 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//345/261/202/347/272/247/346/250/241/346/235/277.json +65 -0
- package/plugins/fancy-story-builder/templates//351/252/250/346/236/266//346/241/206/346/236/266/346/250/241/346/235/277.json +308 -0
- package/plugins/fancy-story-builder/templates.js +1446 -0
- package/plugins/fancy-story-builder/wiki-references.js +540 -0
- package/plugins/fancy-story-builder/writing-driver.js +1388 -0
- package/plugins/fancy-topic/index.js +1057 -0
- package/plugins/fancy-topic/prompts/01-exploration-prompt.md +115 -0
- package/plugins/fancy-topic/scripts/save-suggestion.js +219 -0
- package/plugins/fancy-topic/scripts/select-topic.js +317 -0
- package/plugins/fancy-topic/templates.js +476 -0
- package/plugins/fancy-topic/tool-deploy.js +200 -0
- package/commands/bootstrap/index.js +0 -164
- package/commands/bootstrap/init-project.js +0 -121
- package/commands/scan/index.js +0 -283
- package/commands/scan/platforms/fanqie.js +0 -146
- package/commands/scan/platforms/jinjiang.js +0 -143
- package/commands/scan/platforms/qidian.js +0 -102
- package/commands/scan/platforms/qimao.js +0 -127
- package/commands/scan/scraper.js +0 -195
- package/infra.js +0 -160
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2/macro.js —— 20-macro:先定世界、故事、卷/幕、主支线、结局、情绪曲线、角色功能位。
|
|
3
|
+
*
|
|
4
|
+
* 宏观阶段只允许 ROLE-* 功能位,不允许具体人物姓名。
|
|
5
|
+
* 具体人物、势力、地点、道具、冲突、伏笔、爽点、关系、信息差全部留到 30-cast。
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
asArray,
|
|
9
|
+
indexById,
|
|
10
|
+
v2Error,
|
|
11
|
+
} from './core.js';
|
|
12
|
+
|
|
13
|
+
export const MACRO_FILES = ['world.json', 'story.json', 'volumes.json', 'lines.json', 'endings.json', 'emotion.json', 'roles.json'];
|
|
14
|
+
|
|
15
|
+
const ROLE_FUNCTION_TO_QUOTA = {
|
|
16
|
+
'主角': 'protagonist',
|
|
17
|
+
'核心配角': 'core_supporting',
|
|
18
|
+
'贯穿级核心配角': 'core_supporting',
|
|
19
|
+
'卷级配角': 'volume_supporting',
|
|
20
|
+
'卷级重要配角': 'volume_supporting',
|
|
21
|
+
'核心反派': 'core_antagonist',
|
|
22
|
+
'贯穿级核心反派': 'core_antagonist',
|
|
23
|
+
'卷级反派': 'volume_antagonist',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const WORLD_CATEGORY = {
|
|
27
|
+
'核心': 'core',
|
|
28
|
+
'信息': 'information',
|
|
29
|
+
'社会': 'social',
|
|
30
|
+
core: 'core',
|
|
31
|
+
information: 'information',
|
|
32
|
+
social: 'social',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function requireString(errors, obj, path, field, contract) {
|
|
36
|
+
const value = obj && obj[field];
|
|
37
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
38
|
+
errors.push(v2Error('MACRO_REQUIRED_FIELD', {
|
|
39
|
+
path: path + '.' + field,
|
|
40
|
+
message: '缺少必填文本字段',
|
|
41
|
+
actual: value,
|
|
42
|
+
contract,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function validateLocationRef(errors, value, volumes, acts, path, contract) {
|
|
48
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
49
|
+
errors.push(v2Error('MACRO_REF', { path, message: '缺少卷/幕引用', contract }));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const [volume, act] = value.split('/');
|
|
53
|
+
if (!volume || !volumes.has(volume)) {
|
|
54
|
+
errors.push(v2Error('MACRO_REF', { path, message: '引用了不存在的卷:' + value, contract }));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (act && !acts.has(volume + '/' + act) && !acts.has(act)) {
|
|
58
|
+
errors.push(v2Error('MACRO_REF', { path, message: '引用了不存在的幕:' + value, contract }));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function validateMacro(macro, scale, opts = {}) {
|
|
63
|
+
const errors = [];
|
|
64
|
+
const warnings = [];
|
|
65
|
+
const docs = macro || {};
|
|
66
|
+
const world = docs.world || {};
|
|
67
|
+
const story = docs.story || {};
|
|
68
|
+
const volumesDoc = docs.volumes || {};
|
|
69
|
+
const lines = docs.lines || {};
|
|
70
|
+
const endings = docs.endings || {};
|
|
71
|
+
const emotion = docs.emotion || {};
|
|
72
|
+
const rolesDoc = docs.roles || {};
|
|
73
|
+
|
|
74
|
+
const scaleVolumes = asArray(scale && scale.structure && scale.structure.volumes);
|
|
75
|
+
const scaleActs = asArray(scale && scale.structure && scale.structure.acts);
|
|
76
|
+
const quotas = (scale && scale.quotas) || {};
|
|
77
|
+
const volumeIds = new Set(scaleVolumes.map((v) => v.volume_id || v.id).filter(Boolean));
|
|
78
|
+
const actIds = new Set(scaleActs.map((a) => a.act_id).filter(Boolean));
|
|
79
|
+
const actByVolume = new Map();
|
|
80
|
+
for (const a of scaleActs) {
|
|
81
|
+
if (!actByVolume.has(a.volume_id)) actByVolume.set(a.volume_id, []);
|
|
82
|
+
actByVolume.get(a.volume_id).push(a);
|
|
83
|
+
}
|
|
84
|
+
const validVolumeAct = new Set();
|
|
85
|
+
for (const a of scaleActs) validVolumeAct.add(a.volume_id + '/' + a.act_id);
|
|
86
|
+
|
|
87
|
+
// ---- world ----
|
|
88
|
+
requireString(errors, world, 'world', 'premise', '20-macro/README.md#world');
|
|
89
|
+
requireString(errors, world, 'world', 'tone', '20-macro/README.md#world');
|
|
90
|
+
const theme = world.theme;
|
|
91
|
+
if (!(typeof theme === 'string' && theme.trim()) && !(Array.isArray(theme) && theme.length)) {
|
|
92
|
+
errors.push(v2Error('MACRO_REQUIRED_FIELD', { path: 'world.theme', message: '缺少主题', contract: '20-macro/README.md#world' }));
|
|
93
|
+
}
|
|
94
|
+
const worldRules = asArray(world.world_rules);
|
|
95
|
+
const ruleIds = new Set();
|
|
96
|
+
const ruleCounts = { core: 0, information: 0, social: 0 };
|
|
97
|
+
for (let i = 0; i < worldRules.length; i += 1) {
|
|
98
|
+
const r = worldRules[i] || {};
|
|
99
|
+
if (!r.id) errors.push(v2Error('MACRO_WORLD_RULE_ID', { path: 'world.world_rules[' + i + '].id', message: '缺少规则 ID', contract: '20-macro/README.md#world' }));
|
|
100
|
+
else if (ruleIds.has(r.id)) errors.push(v2Error('MACRO_WORLD_RULE_ID_DUP', { path: 'world.world_rules[' + i + '].id', message: '规则 ID 重复:' + r.id, contract: '20-macro/README.md#world' }));
|
|
101
|
+
else ruleIds.add(r.id);
|
|
102
|
+
for (const f of ['name', 'content', 'scope', 'cost', 'impact']) {
|
|
103
|
+
requireString(errors, r, 'world.world_rules[' + i + ']', f, '20-macro/README.md#world');
|
|
104
|
+
}
|
|
105
|
+
const cat = WORLD_CATEGORY[r.category] || WORLD_CATEGORY[r.kind] || 'core';
|
|
106
|
+
ruleCounts[cat] += 1;
|
|
107
|
+
}
|
|
108
|
+
const expectedRules = quotas.world_rules || {};
|
|
109
|
+
for (const [cat, expected] of Object.entries(expectedRules)) {
|
|
110
|
+
if (ruleCounts[cat] !== Number(expected)) {
|
|
111
|
+
errors.push(v2Error('MACRO_WORLD_RULE_QUOTA', {
|
|
112
|
+
path: 'world.world_rules',
|
|
113
|
+
message: '世界规则数量与 scale.quotas.world_rules 不一致:' + cat,
|
|
114
|
+
expected: Number(expected), actual: ruleCounts[cat],
|
|
115
|
+
contract: '20-macro/README.md#world',
|
|
116
|
+
reference: '10-scale/scale.json#quotas.world_rules.' + cat,
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ---- story ----
|
|
122
|
+
requireString(errors, story, 'story', 'core_question', '20-macro/README.md#story');
|
|
123
|
+
requireString(errors, story, 'story', 'core_conflict', '20-macro/README.md#story');
|
|
124
|
+
const structure = story.structure || {};
|
|
125
|
+
const storyActs = asArray(structure.acts);
|
|
126
|
+
if (!storyActs.length) {
|
|
127
|
+
errors.push(v2Error('MACRO_STORY_ACTS', { path: 'story.structure.acts', message: '故事结构必须覆盖每一幕', contract: '20-macro/README.md#story' }));
|
|
128
|
+
}
|
|
129
|
+
const storyActIds = new Set();
|
|
130
|
+
for (let i = 0; i < storyActs.length; i += 1) {
|
|
131
|
+
const a = storyActs[i] || {};
|
|
132
|
+
if (!a.act_id) errors.push(v2Error('MACRO_STORY_ACT_ID', { path: 'story.structure.acts[' + i + '].act_id', message: '缺少 act_id', contract: '20-macro/README.md#story' }));
|
|
133
|
+
else if (!actIds.has(a.act_id)) errors.push(v2Error('MACRO_STORY_ACT_REF', { path: 'story.structure.acts[' + i + '].act_id', message: '引用了 scale 中不存在的幕:' + a.act_id, contract: '20-macro/README.md#story' }));
|
|
134
|
+
else storyActIds.add(a.act_id);
|
|
135
|
+
for (const f of ['goal', 'turn', 'end_state']) requireString(errors, a, 'story.structure.acts[' + i + ']', f, '20-macro/README.md#story');
|
|
136
|
+
}
|
|
137
|
+
for (const id of actIds) {
|
|
138
|
+
if (!storyActIds.has(id)) {
|
|
139
|
+
errors.push(v2Error('MACRO_STORY_ACT_GAP', {
|
|
140
|
+
path: 'story.structure.acts', message: '故事结构没有覆盖幕:' + id,
|
|
141
|
+
contract: '20-macro/README.md#story', reference: '10-scale/scale.json#structure.acts',
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
requireString(errors, structure, 'story.structure', 'climax', '20-macro/README.md#story');
|
|
146
|
+
requireString(errors, structure, 'story.structure', 'resolution', '20-macro/README.md#story');
|
|
147
|
+
|
|
148
|
+
// ---- volumes ----
|
|
149
|
+
const volumes = asArray(volumesDoc.volumes);
|
|
150
|
+
if (volumes.length !== scaleVolumes.length) {
|
|
151
|
+
errors.push(v2Error('MACRO_VOLUME_COUNT', {
|
|
152
|
+
path: 'volumes.volumes',
|
|
153
|
+
message: '卷纲数量必须等于 scale.structure.volume_count',
|
|
154
|
+
expected: scaleVolumes.length, actual: volumes.length,
|
|
155
|
+
contract: '20-macro/README.md#volumes',
|
|
156
|
+
reference: '10-scale/scale.json#structure.volume_count',
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
const volumeById = indexById(volumes);
|
|
160
|
+
let expectedStart = 1;
|
|
161
|
+
for (let i = 0; i < scaleVolumes.length; i += 1) {
|
|
162
|
+
const sv = scaleVolumes[i];
|
|
163
|
+
const id = sv.volume_id || sv.id;
|
|
164
|
+
const v = volumeById.get(id);
|
|
165
|
+
if (!v) {
|
|
166
|
+
errors.push(v2Error('MACRO_VOLUME_MISSING', {
|
|
167
|
+
path: 'volumes.volumes', message: '缺少卷:' + id,
|
|
168
|
+
contract: '20-macro/README.md#volumes', reference: '10-scale/scale.json#structure.volumes',
|
|
169
|
+
}));
|
|
170
|
+
expectedStart += Number(sv.chapters || 0);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (Number(v.chapter_start) !== Number(sv.chapter_start) || Number(v.chapter_end) !== Number(sv.chapter_end)) {
|
|
174
|
+
errors.push(v2Error('MACRO_VOLUME_RANGE', {
|
|
175
|
+
path: 'volumes.volumes[' + i + ']',
|
|
176
|
+
message: '卷章节区间必须与 scale 一致',
|
|
177
|
+
expected: sv.chapter_start + '-' + sv.chapter_end,
|
|
178
|
+
actual: v.chapter_start + '-' + v.chapter_end,
|
|
179
|
+
contract: '20-macro/README.md#volumes',
|
|
180
|
+
reference: '10-scale/scale.json#structure.volumes',
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
requireString(errors, v, 'volumes.volumes[' + i + ']', 'title', '20-macro/README.md#volumes');
|
|
184
|
+
requireString(errors, v, 'volumes.volumes[' + i + ']', 'goal', '20-macro/README.md#volumes');
|
|
185
|
+
requireString(errors, v, 'volumes.volumes[' + i + ']', 'core_conflict', '20-macro/README.md#volumes');
|
|
186
|
+
requireString(errors, v, 'volumes.volumes[' + i + ']', 'emotional_arc', '20-macro/README.md#volumes');
|
|
187
|
+
requireString(errors, v, 'volumes.volumes[' + i + ']', 'ending_hook', '20-macro/README.md#volumes');
|
|
188
|
+
const vActs = asArray(v.acts);
|
|
189
|
+
const expectedActs = asArray(sv.acts);
|
|
190
|
+
if (vActs.length !== expectedActs.length) {
|
|
191
|
+
errors.push(v2Error('MACRO_ACT_COUNT', {
|
|
192
|
+
path: 'volumes.volumes[' + i + '].acts',
|
|
193
|
+
message: '幕纲数量必须与本卷 scale 幕数一致',
|
|
194
|
+
expected: expectedActs.length, actual: vActs.length,
|
|
195
|
+
contract: '20-macro/README.md#volumes',
|
|
196
|
+
reference: '10-scale/scale.json#structure.volumes',
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
const vActIds = new Set();
|
|
200
|
+
for (let j = 0; j < expectedActs.length; j += 1) {
|
|
201
|
+
const sa = expectedActs[j];
|
|
202
|
+
const a = vActs[j] || {};
|
|
203
|
+
if (a.act_id && a.act_id !== sa.act_id) {
|
|
204
|
+
errors.push(v2Error('MACRO_ACT_ID', {
|
|
205
|
+
path: 'volumes.volumes[' + i + '].acts[' + j + '].act_id',
|
|
206
|
+
message: '幕 ID 必须与 scale 一致',
|
|
207
|
+
expected: sa.act_id, actual: a.act_id,
|
|
208
|
+
contract: '20-macro/README.md#volumes',
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
if (a.act_id) vActIds.add(a.act_id);
|
|
212
|
+
if (Number(a.chapter_start) !== Number(sa.chapter_start) || Number(a.chapter_end) !== Number(sa.chapter_end)) {
|
|
213
|
+
errors.push(v2Error('MACRO_ACT_RANGE', {
|
|
214
|
+
path: 'volumes.volumes[' + i + '].acts[' + j + ']',
|
|
215
|
+
message: '幕章节区间必须与 scale 一致',
|
|
216
|
+
expected: sa.chapter_start + '-' + sa.chapter_end,
|
|
217
|
+
actual: a.chapter_start + '-' + a.chapter_end,
|
|
218
|
+
contract: '20-macro/README.md#volumes',
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
for (const f of ['goal', 'climax']) requireString(errors, a, 'volumes.volumes[' + i + '].acts[' + j + ']', f, '20-macro/README.md#volumes');
|
|
222
|
+
}
|
|
223
|
+
for (const sa of expectedActs) {
|
|
224
|
+
if (sa.act_id && !vActIds.has(sa.act_id)) {
|
|
225
|
+
errors.push(v2Error('MACRO_ACT_MISSING', { path: 'volumes.volumes[' + i + '].acts', message: '缺少幕:' + sa.act_id, contract: '20-macro/README.md#volumes' }));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
expectedStart = Number(sv.chapter_end) + 1;
|
|
229
|
+
}
|
|
230
|
+
if (Number(scale && scale.capacity && scale.capacity.target_chapters) && expectedStart !== Number(scale.capacity.target_chapters) + 1) {
|
|
231
|
+
errors.push(v2Error('MACRO_VOLUME_GAP', { path: 'volumes.volumes', message: '卷纲没有连续覆盖全部章节', expected: Number(scale.capacity.target_chapters), actual: expectedStart - 1, contract: '20-macro/README.md#volumes' }));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ---- lines ----
|
|
235
|
+
const mainLine = lines.main_line || {};
|
|
236
|
+
if (!mainLine.id) errors.push(v2Error('MACRO_MAIN_LINE', { path: 'lines.main_line.id', message: '缺少主线 ID', contract: '20-macro/README.md#lines' }));
|
|
237
|
+
requireString(errors, mainLine, 'lines.main_line', 'name', '20-macro/README.md#lines');
|
|
238
|
+
const nodes = asArray(mainLine.nodes);
|
|
239
|
+
const nodeIds = new Set();
|
|
240
|
+
const nodeVolumes = new Set();
|
|
241
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
242
|
+
const n = nodes[i] || {};
|
|
243
|
+
if (!n.id) errors.push(v2Error('MACRO_MAIN_NODE_ID', { path: 'lines.main_line.nodes[' + i + '].id', message: '缺少主线节点 ID', contract: '20-macro/README.md#lines' }));
|
|
244
|
+
else if (nodeIds.has(n.id)) errors.push(v2Error('MACRO_MAIN_NODE_ID_DUP', { path: 'lines.main_line.nodes[' + i + '].id', message: '主线节点 ID 重复:' + n.id, contract: '20-macro/README.md#lines' }));
|
|
245
|
+
else nodeIds.add(n.id);
|
|
246
|
+
if (!volumeIds.has(n.volume)) {
|
|
247
|
+
errors.push(v2Error('MACRO_MAIN_NODE_VOLUME', { path: 'lines.main_line.nodes[' + i + '].volume', message: '主线节点引用了不存在的卷:' + n.volume, contract: '20-macro/README.md#lines' }));
|
|
248
|
+
} else {
|
|
249
|
+
nodeVolumes.add(n.volume);
|
|
250
|
+
}
|
|
251
|
+
if (n.act && !actIds.has(n.act)) {
|
|
252
|
+
errors.push(v2Error('MACRO_MAIN_NODE_ACT', { path: 'lines.main_line.nodes[' + i + '].act', message: '主线节点引用了不存在的幕:' + n.act, contract: '20-macro/README.md#lines' }));
|
|
253
|
+
}
|
|
254
|
+
for (const f of ['goal', 'turn']) requireString(errors, n, 'lines.main_line.nodes[' + i + ']', f, '20-macro/README.md#lines');
|
|
255
|
+
}
|
|
256
|
+
for (const id of volumeIds) {
|
|
257
|
+
if (!nodeVolumes.has(id)) {
|
|
258
|
+
errors.push(v2Error('MACRO_MAIN_LINE_GAP', {
|
|
259
|
+
path: 'lines.main_line.nodes', message: '主线没有覆盖卷:' + id,
|
|
260
|
+
contract: '20-macro/README.md#lines', reference: '10-scale/scale.json#structure.volumes',
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (quotas.main_lines !== undefined && Number(quotas.main_lines) !== 1) {
|
|
265
|
+
warnings.push(v2Error('MACRO_MAIN_LINE_COUNT', { path: 'lines.main_line', message: '2.0 目前只支持 1 条主线', severity: 'warning', contract: '20-macro/README.md#lines' }));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const branches = asArray(lines.branches);
|
|
269
|
+
const expectedBranches = Number(quotas.branches || 0);
|
|
270
|
+
if (branches.length !== expectedBranches) {
|
|
271
|
+
errors.push(v2Error('MACRO_BRANCH_COUNT', {
|
|
272
|
+
path: 'lines.branches', message: '支线数量必须等于 scale.quotas.branches',
|
|
273
|
+
expected: expectedBranches, actual: branches.length,
|
|
274
|
+
contract: '20-macro/README.md#lines', reference: '10-scale/scale.json#quotas.branches',
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
const branchIds = new Set();
|
|
278
|
+
for (let i = 0; i < branches.length; i += 1) {
|
|
279
|
+
const b = branches[i] || {};
|
|
280
|
+
if (!b.id) errors.push(v2Error('MACRO_BRANCH_ID', { path: 'lines.branches[' + i + '].id', message: '缺少支线 ID', contract: '20-macro/README.md#lines' }));
|
|
281
|
+
else if (branchIds.has(b.id)) errors.push(v2Error('MACRO_BRANCH_ID_DUP', { path: 'lines.branches[' + i + '].id', message: '支线 ID 重复:' + b.id, contract: '20-macro/README.md#lines' }));
|
|
282
|
+
else branchIds.add(b.id);
|
|
283
|
+
requireString(errors, b, 'lines.branches[' + i + ']', 'name', '20-macro/README.md#lines');
|
|
284
|
+
requireString(errors, b, 'lines.branches[' + i + ']', 'goal', '20-macro/README.md#lines');
|
|
285
|
+
for (const field of ['start', 'turning', 'resolution']) {
|
|
286
|
+
validateLocationRef(errors, b[field], volumeIds, validVolumeAct, 'lines.branches[' + i + '].' + field, '20-macro/README.md#lines');
|
|
287
|
+
}
|
|
288
|
+
const interweaves = asArray(b.interweaves);
|
|
289
|
+
for (const nid of interweaves) {
|
|
290
|
+
if (!nodeIds.has(nid)) {
|
|
291
|
+
errors.push(v2Error('MACRO_BRANCH_INTERWEAVE', { path: 'lines.branches[' + i + '].interweaves', message: '支线交织了不存在的主线节点:' + nid, contract: '20-macro/README.md#lines' }));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ---- endings ----
|
|
297
|
+
const endingRows = asArray(endings.endings);
|
|
298
|
+
const expectedEndings = Number(quotas.endings || 0);
|
|
299
|
+
if (endingRows.length !== expectedEndings) {
|
|
300
|
+
errors.push(v2Error('MACRO_ENDING_COUNT', {
|
|
301
|
+
path: 'endings.endings', message: '结局数量必须等于 scale.quotas.endings',
|
|
302
|
+
expected: expectedEndings, actual: endingRows.length,
|
|
303
|
+
contract: '20-macro/README.md#endings', reference: '10-scale/scale.json#quotas.endings',
|
|
304
|
+
}));
|
|
305
|
+
}
|
|
306
|
+
const endingIds = new Set();
|
|
307
|
+
let bookLevel = 0;
|
|
308
|
+
for (let i = 0; i < endingRows.length; i += 1) {
|
|
309
|
+
const e = endingRows[i] || {};
|
|
310
|
+
if (!e.id) errors.push(v2Error('MACRO_ENDING_ID', { path: 'endings.endings[' + i + '].id', message: '缺少结局 ID', contract: '20-macro/README.md#endings' }));
|
|
311
|
+
else if (endingIds.has(e.id)) errors.push(v2Error('MACRO_ENDING_ID_DUP', { path: 'endings.endings[' + i + '].id', message: '结局 ID 重复:' + e.id, contract: '20-macro/README.md#endings' }));
|
|
312
|
+
else endingIds.add(e.id);
|
|
313
|
+
requireString(errors, e, 'endings.endings[' + i + ']', 'direction', '20-macro/README.md#endings');
|
|
314
|
+
if (e.level === '全书级') bookLevel += 1;
|
|
315
|
+
for (const fs of asArray(e.required_foreshadow_recovery)) {
|
|
316
|
+
if (!/^FS\d{3,}$/.test(String(fs))) {
|
|
317
|
+
errors.push(v2Error('MACRO_ENDING_FORESHADOW_REF', { path: 'endings.endings[' + i + '].required_foreshadow_recovery', message: '伏笔 ID 格式应为 FS001:' + fs, contract: '20-macro/README.md#endings' }));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (bookLevel !== 1) {
|
|
322
|
+
errors.push(v2Error('MACRO_ENDING_BOOK_LEVEL', {
|
|
323
|
+
path: 'endings.endings', message: '必须恰好有 1 个 level=全书级 的结局',
|
|
324
|
+
expected: 1, actual: bookLevel,
|
|
325
|
+
contract: '20-macro/README.md#endings',
|
|
326
|
+
}));
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ---- emotion ----
|
|
330
|
+
const curve = asArray(emotion.volumes);
|
|
331
|
+
const curveIds = new Set(curve.map((x) => x && x.volume_id).filter(Boolean));
|
|
332
|
+
for (const id of volumeIds) {
|
|
333
|
+
if (!curveIds.has(id)) {
|
|
334
|
+
errors.push(v2Error('MACRO_EMOTION_GAP', {
|
|
335
|
+
path: 'emotion.volumes', message: '全局情绪曲线缺少卷:' + id,
|
|
336
|
+
contract: '20-macro/README.md#emotion', reference: '10-scale/scale.json#structure.volumes',
|
|
337
|
+
}));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
for (let i = 0; i < curve.length; i += 1) {
|
|
341
|
+
const row = curve[i] || {};
|
|
342
|
+
if (row.volume_id && !volumeIds.has(row.volume_id)) {
|
|
343
|
+
errors.push(v2Error('MACRO_EMOTION_REF', { path: 'emotion.volumes[' + i + '].volume_id', message: '情绪曲线引用了不存在的卷:' + row.volume_id, contract: '20-macro/README.md#emotion' }));
|
|
344
|
+
}
|
|
345
|
+
requireString(errors, row, 'emotion.volumes[' + i + ']', 'arc', '20-macro/README.md#emotion');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// ---- roles ----
|
|
349
|
+
const roles = asArray(rolesDoc.roles);
|
|
350
|
+
const expectedRoleCounts = {
|
|
351
|
+
protagonist: Number((quotas.characters && quotas.characters.protagonist) || 0),
|
|
352
|
+
core_supporting: Number((quotas.characters && quotas.characters.core_supporting) || 0),
|
|
353
|
+
volume_supporting: Number((quotas.characters && quotas.characters.volume_supporting) || 0),
|
|
354
|
+
core_antagonist: Number((quotas.characters && quotas.characters.core_antagonist) || 0),
|
|
355
|
+
volume_antagonist: Number((quotas.characters && quotas.characters.volume_antagonist) || 0),
|
|
356
|
+
};
|
|
357
|
+
const expectedTotal = Object.values(expectedRoleCounts).reduce((a, b) => a + b, 0);
|
|
358
|
+
if (roles.length !== expectedTotal) {
|
|
359
|
+
errors.push(v2Error('MACRO_ROLE_COUNT', {
|
|
360
|
+
path: 'roles.roles', message: '角色功能位数量必须等于人物配额总和',
|
|
361
|
+
expected: expectedTotal, actual: roles.length,
|
|
362
|
+
contract: '20-macro/README.md#roles', reference: '10-scale/scale.json#quotas.characters',
|
|
363
|
+
}));
|
|
364
|
+
}
|
|
365
|
+
const roleIds = new Set();
|
|
366
|
+
const roleCounts = { protagonist: 0, core_supporting: 0, volume_supporting: 0, core_antagonist: 0, volume_antagonist: 0 };
|
|
367
|
+
for (let i = 0; i < roles.length; i += 1) {
|
|
368
|
+
const r = roles[i] || {};
|
|
369
|
+
if (!r.role_id) {
|
|
370
|
+
errors.push(v2Error('MACRO_ROLE_ID', { path: 'roles.roles[' + i + '].role_id', message: '缺少 role_id', contract: '20-macro/README.md#roles' }));
|
|
371
|
+
} else if (!/^ROLE-[A-Z0-9-]+$/.test(r.role_id)) {
|
|
372
|
+
errors.push(v2Error('MACRO_ROLE_ID', { path: 'roles.roles[' + i + '].role_id', message: 'role_id 必须形如 ROLE-PROTAGONIST', actual: r.role_id, contract: '20-macro/README.md#roles' }));
|
|
373
|
+
} else if (roleIds.has(r.role_id)) {
|
|
374
|
+
errors.push(v2Error('MACRO_ROLE_ID_DUP', { path: 'roles.roles[' + i + '].role_id', message: 'role_id 重复:' + r.role_id, contract: '20-macro/README.md#roles' }));
|
|
375
|
+
} else {
|
|
376
|
+
roleIds.add(r.role_id);
|
|
377
|
+
}
|
|
378
|
+
const key = ROLE_FUNCTION_TO_QUOTA[r.function];
|
|
379
|
+
if (!key) {
|
|
380
|
+
errors.push(v2Error('MACRO_ROLE_FUNCTION', {
|
|
381
|
+
path: 'roles.roles[' + i + '].function', message: '未知角色功能:' + r.function,
|
|
382
|
+
expected: Object.keys(ROLE_FUNCTION_TO_QUOTA).join(' / '),
|
|
383
|
+
contract: '20-macro/README.md#roles',
|
|
384
|
+
}));
|
|
385
|
+
} else {
|
|
386
|
+
roleCounts[key] += 1;
|
|
387
|
+
}
|
|
388
|
+
for (const f of ['arc_question', 'macro_goal']) requireString(errors, r, 'roles.roles[' + i + ']', f, '20-macro/README.md#roles');
|
|
389
|
+
}
|
|
390
|
+
for (const [key, expected] of Object.entries(expectedRoleCounts)) {
|
|
391
|
+
if (roleCounts[key] !== expected) {
|
|
392
|
+
errors.push(v2Error('MACRO_ROLE_QUOTA', {
|
|
393
|
+
path: 'roles.roles', message: '角色功能位数量与人物配额不一致:' + key,
|
|
394
|
+
expected, actual: roleCounts[key],
|
|
395
|
+
contract: '20-macro/README.md#roles', reference: '10-scale/scale.json#quotas.characters.' + key,
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return { ok: errors.length === 0, errors, warnings, data: docs };
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export function macroRoleMap(rolesDoc) {
|
|
404
|
+
const map = new Map();
|
|
405
|
+
for (const r of asArray(rolesDoc && rolesDoc.roles)) {
|
|
406
|
+
if (r && r.role_id) map.set(r.role_id, r);
|
|
407
|
+
}
|
|
408
|
+
return map;
|
|
409
|
+
}
|