@lingfan-engine/editor 0.0.0-stage → 0.1.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.
- package/LICENSE +201 -0
- package/package.json +39 -3
- package/src/chapters/build.ts +180 -0
- package/src/chapters/index.ts +34 -0
- package/src/chapters/types.ts +71 -0
- package/src/contracts/diagnostics.ts +62 -0
- package/src/contracts/editing.ts +26 -0
- package/src/contracts/forms.ts +69 -0
- package/src/contracts/index.ts +22 -0
- package/src/contracts/texts.ts +204 -0
- package/src/diagnostics/analyze.ts +161 -0
- package/src/diagnostics/grouping.ts +164 -0
- package/src/diagnostics/index.ts +35 -0
- package/src/diagnostics/message.ts +60 -0
- package/src/diagnostics/refs.ts +123 -0
- package/src/diagnostics/symbols.ts +221 -0
- package/src/editing/columnGrouping.ts +331 -0
- package/src/editing/graphConnect.ts +88 -0
- package/src/editing/index.ts +72 -0
- package/src/editing/pointers.ts +291 -0
- package/src/editing/saveNormalization.ts +58 -0
- package/src/editing/session.ts +134 -0
- package/src/editing/storyOps.ts +268 -0
- package/src/editing/tsSourceGuard.ts +40 -0
- package/src/element/drag.ts +22 -0
- package/src/element/dragCreate.ts +60 -0
- package/src/element/index.ts +11 -0
- package/src/i18n/coverage.ts +191 -0
- package/src/i18n/extract.ts +38 -0
- package/src/i18n/index.ts +47 -0
- package/src/i18n/reconcile.ts +71 -0
- package/src/i18n/skeleton.ts +112 -0
- package/src/i18n/storyKeys.ts +27 -0
- package/src/i18n/surfaces.ts +54 -0
- package/src/i18n/table.ts +235 -0
- package/src/index.ts +342 -0
- package/src/layout/index.ts +14 -0
- package/src/layout/steps.ts +378 -0
- package/src/schema/catalog.ts +300 -0
- package/src/schema/elementForms.ts +307 -0
- package/src/schema/elementPalette.ts +100 -0
- package/src/schema/forms.ts +196 -0
- package/src/schema/index.ts +55 -0
- package/src/schema/opSchemas/commands.ts +374 -0
- package/src/schema/opSchemas/fragments.ts +24 -0
- package/src/schema/opSchemas/index.ts +16 -0
- package/src/schema/opSchemas/map.ts +134 -0
- package/src/schema/opSchemas/types.ts +42 -0
- package/src/schema/opSchemas/validate.ts +184 -0
- package/src/schema/surface.ts +101 -0
- package/src/schema/validation.ts +92 -0
- package/src/schema/walk.ts +167 -0
- package/src/script/expr/audit/index.ts +8 -0
- package/src/script/expr/audit/parser.ts +370 -0
- package/src/script/expr/audit/token.ts +23 -0
- package/src/script/expr/build.ts +203 -0
- package/src/script/expr/index.ts +17 -0
- package/src/script/expr/registry.ts +130 -0
- package/src/script/index.ts +168 -0
- package/src/script/vocabulary-gen.ts +202 -0
- package/src/script/vocabulary.g.ts +175 -0
- package/src/script/words/audio.ts +114 -0
- package/src/script/words/cells.ts +78 -0
- package/src/script/words/compile-time.ts +27 -0
- package/src/script/words/composite.ts +125 -0
- package/src/script/words/elements.ts +202 -0
- package/src/script/words/extension.ts +25 -0
- package/src/script/words/flow.ts +391 -0
- package/src/script/words/index.ts +23 -0
- package/src/script/words/interaction.ts +44 -0
- package/src/script/words/minigame.ts +66 -0
- package/src/script/words/narrative.ts +261 -0
- package/src/script/words/save.ts +54 -0
- package/src/script/words/vars.ts +155 -0
- package/src/script/words/video.ts +80 -0
- package/src/shared/guards.ts +19 -0
- package/src/shared/index.ts +6 -0
- package/src/shared/pointer.ts +23 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright (c) 2026 MoFeng-02
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingfan-engine/editor",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "灵泛叙事作者层:op schema 单一事实源 + 词函数子语言 + 编辑期诊断 + 故事树纯映射器——只读写故事 JSON,不碰运行时与平台",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"!src/**/*.test.ts",
|
|
12
|
+
"!src/script/generate-vocabulary.ts"
|
|
13
|
+
],
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@lingfan-engine/core": "^0.1.2",
|
|
17
|
+
"zod": "^4.6.5"
|
|
18
|
+
},
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/MoFeng-02/LingFan.Engine.git",
|
|
23
|
+
"directory": "packages/editor"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/MoFeng-02/LingFan.Engine#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/MoFeng-02/LingFan.Engine/issues"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"narrative",
|
|
31
|
+
"editor",
|
|
32
|
+
"schema",
|
|
33
|
+
"story",
|
|
34
|
+
"typescript"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22.12.0"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
6
42
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 故事章节树 · 判据与装配实现(可测,无 IO / 无 Vue)。
|
|
3
|
+
*
|
|
4
|
+
* 域出口 `./index.ts` 只做转发(类型见 `./types.ts`);实现集中在本文件。
|
|
5
|
+
* 设计约定(分组只看 type、任意深度、0 层平铺退化)见出口文件头注。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
isReplayableColumn,
|
|
10
|
+
STORIES_DIR,
|
|
11
|
+
type StoryColumn,
|
|
12
|
+
} from "@lingfan-engine/core";
|
|
13
|
+
import type {
|
|
14
|
+
ChapterDir,
|
|
15
|
+
ChapterGroup,
|
|
16
|
+
ChapterIndex,
|
|
17
|
+
ChapterInput,
|
|
18
|
+
ChapterNode,
|
|
19
|
+
} from "./types.ts";
|
|
20
|
+
|
|
21
|
+
/** 故事文件的容器根(剥掉它,剩下的目录链才是「作者的章节编排」;由引擎 SSOT 常量派生) */
|
|
22
|
+
const STORIES_ROOT = `${STORIES_DIR}/`;
|
|
23
|
+
|
|
24
|
+
/** 剥掉 `Stories/` 前缀(**容器根不算章节**——否则 `Stories/start.json` 的章节名会变成「Stories」) */
|
|
25
|
+
function insideStories(path: string): string {
|
|
26
|
+
return path.startsWith(STORIES_ROOT) ? path.slice(STORIES_ROOT.length) : path;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 章节目录键(不依赖 `ResourceNode`,直接吃路径集——便于纯测)
|
|
30
|
+
*
|
|
31
|
+
* **只取 `Stories/` 之下的目录**(`Stories/start.json` ⇒ `""` ⇒ 平铺,
|
|
32
|
+
* 因为「深一层」只是把文件分组,**不是编排章节**;只有 `Stories/a/b.story` 才是)。
|
|
33
|
+
* 容器根 `Stories/` 本身**不算章节**——否则章节名全变成 "Stories"。
|
|
34
|
+
*/
|
|
35
|
+
export function chapterDirOf(path: string): string {
|
|
36
|
+
const inner = insideStories(path);
|
|
37
|
+
const idx = inner.lastIndexOf("/");
|
|
38
|
+
return idx < 0 ? "" : inner.slice(0, idx + 1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 章节显示名:**优先取目录名**(作者的分章意图),0 层平铺时退回文件名去后缀 */
|
|
42
|
+
export function chapterLabelOf(path: string): string {
|
|
43
|
+
const inner = insideStories(path);
|
|
44
|
+
const file = inner.slice(inner.lastIndexOf("/") + 1);
|
|
45
|
+
const dot = file.indexOf(".");
|
|
46
|
+
const name = dot < 0 ? file : file.slice(0, dot);
|
|
47
|
+
const dir = chapterDirOf(path);
|
|
48
|
+
const dirName =
|
|
49
|
+
dir
|
|
50
|
+
.slice(0, dir.length - 1)
|
|
51
|
+
.split("/")
|
|
52
|
+
.pop() ?? "";
|
|
53
|
+
// 目录名与文件名同前缀时(如 chapter1/chapter1.story)**取目录名**——
|
|
54
|
+
// 目录才是「章节」,文件名只是文件。
|
|
55
|
+
return dirName !== "" ? dirName : name;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 章节所属分组(**单一判定点**:直接用引擎的 `isReplayableColumn`,不另写一份) */
|
|
59
|
+
export function chapterGroupOf(
|
|
60
|
+
column: Pick<StoryColumn, "type">,
|
|
61
|
+
): ChapterGroup {
|
|
62
|
+
return isReplayableColumn(column) ? "story" : "ui";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 场景类型的**徽标文案**(单一事实源:列侧栏 / 章节树共用,组件不得自写映射)。
|
|
67
|
+
*
|
|
68
|
+
* - `"menu"` → 「菜单」;`"ui"` → 「界面」
|
|
69
|
+
* - 缺省(`undefined`)与 `"game"` → `null`(**game 是常态不标**——满屏「剧情」徽标是噪音)
|
|
70
|
+
*/
|
|
71
|
+
export function sceneTypeBadgeOf(
|
|
72
|
+
type: StoryColumn["type"],
|
|
73
|
+
): "菜单" | "界面" | null {
|
|
74
|
+
if (type === "menu") return "菜单";
|
|
75
|
+
if (type === "ui") return "界面";
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 命令条数(flow 看 commands、scene 看 entry;缺省 0) */
|
|
80
|
+
function commandCountOf(column: StoryColumn): number {
|
|
81
|
+
if (column.kind === "scene") return (column.entry ?? []).length;
|
|
82
|
+
return (column.commands ?? []).length;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 按组归并目录(`dirs` 的**分组版本**;同一目录在两个组各出一份,children 不交叉) */
|
|
86
|
+
function dirsOfGroup(
|
|
87
|
+
nodes: readonly ChapterNode[],
|
|
88
|
+
group: ChapterGroup,
|
|
89
|
+
): ChapterDir[] {
|
|
90
|
+
const byDir = new Map<string, ChapterNode[]>();
|
|
91
|
+
for (const node of nodes) {
|
|
92
|
+
if (node.group !== group) continue; // ← 关键:只收本组的节点
|
|
93
|
+
const dir = chapterDirOf(node.path);
|
|
94
|
+
if (dir === "") continue; // 0 层平铺:不进目录分组
|
|
95
|
+
const bucket = byDir.get(dir);
|
|
96
|
+
if (bucket === undefined) byDir.set(dir, [node]);
|
|
97
|
+
else bucket.push(node);
|
|
98
|
+
}
|
|
99
|
+
return [...byDir.entries()]
|
|
100
|
+
.map(([path, children]) => ({
|
|
101
|
+
label:
|
|
102
|
+
path
|
|
103
|
+
.slice(0, path.length - 1)
|
|
104
|
+
.split("/")
|
|
105
|
+
.pop() ?? path,
|
|
106
|
+
path,
|
|
107
|
+
children: [...children].sort((a, b) =>
|
|
108
|
+
a.path < b.path ? -1 : a.path > b.path ? 1 : 0,
|
|
109
|
+
),
|
|
110
|
+
}))
|
|
111
|
+
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 构建章节目录。
|
|
116
|
+
*
|
|
117
|
+
* **分组只看 `type`,绝不看目录名** —— 作者可能把剧情放进 `system/`、
|
|
118
|
+
* 把菜单放进 `chapter1/`。按目录分组会把它们错分。
|
|
119
|
+
* **目录只表达「作者的编排意图」,类型才表达「运行语义」。**
|
|
120
|
+
*/
|
|
121
|
+
export function buildChapterIndex(
|
|
122
|
+
inputs: readonly ChapterInput[],
|
|
123
|
+
): ChapterIndex {
|
|
124
|
+
const nodes: ChapterNode[] = inputs.map(({ path, column }) => ({
|
|
125
|
+
id: column.id,
|
|
126
|
+
label: chapterLabelOf(path),
|
|
127
|
+
group: chapterGroupOf(column),
|
|
128
|
+
type: column.type,
|
|
129
|
+
path,
|
|
130
|
+
commandCount: commandCountOf(column),
|
|
131
|
+
}));
|
|
132
|
+
const byCodeUnit = (a: ChapterNode, b: ChapterNode): number =>
|
|
133
|
+
a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
|
134
|
+
const story = nodes.filter((n) => n.group === "story").sort(byCodeUnit);
|
|
135
|
+
const ui = nodes.filter((n) => n.group === "ui").sort(byCodeUnit);
|
|
136
|
+
|
|
137
|
+
// 目录分组:按 `chapterDirOf` 归并(**任意深度**:目录路径原样做键)
|
|
138
|
+
const dirs = new Map<string, ChapterNode[]>();
|
|
139
|
+
for (const node of nodes) {
|
|
140
|
+
const dir = chapterDirOf(node.path);
|
|
141
|
+
// 0 层平铺:路径不含 `/` ⇒ dir 为空串 ⇒ **不进目录分组**(退化为平铺列表)
|
|
142
|
+
if (dir === "") continue;
|
|
143
|
+
const bucket = dirs.get(dir);
|
|
144
|
+
if (bucket === undefined) dirs.set(dir, [node]);
|
|
145
|
+
else bucket.push(node);
|
|
146
|
+
}
|
|
147
|
+
const dirNodes: ChapterDir[] = [...dirs.entries()]
|
|
148
|
+
.map(([path, children]) => ({
|
|
149
|
+
label:
|
|
150
|
+
path
|
|
151
|
+
.slice(0, path.length - 1)
|
|
152
|
+
.split("/")
|
|
153
|
+
.pop() ?? path,
|
|
154
|
+
path,
|
|
155
|
+
children: [...children].sort(byCodeUnit),
|
|
156
|
+
}))
|
|
157
|
+
// 排序键用**完整路径**而非显示名——两个不同路径可能同名(同层不同章),
|
|
158
|
+
// 用显示名排会抖动(两边都叫 chapter1 时顺序不定)
|
|
159
|
+
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
story,
|
|
163
|
+
ui,
|
|
164
|
+
// `dirs` = **全局目录清单**(不分 type;保留给「按目录浏览」这类不分组的视图)
|
|
165
|
+
dirs: dirNodes,
|
|
166
|
+
// 面板**按组展示** ⇒ 用分组版(否则界面组的目录会混进剧情节点)
|
|
167
|
+
storyDirs: dirsOfGroup(nodes, "story"),
|
|
168
|
+
uiDirs: dirsOfGroup(nodes, "ui"),
|
|
169
|
+
flat: dirNodes.length === 0,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** 汇总文案(面板/状态栏用;**不逐条罗列**) */
|
|
174
|
+
export function chapterSummaryText(index: ChapterIndex): string {
|
|
175
|
+
if (index.story.length === 0 && index.ui.length === 0) return "无场景";
|
|
176
|
+
const parts: string[] = [];
|
|
177
|
+
if (index.story.length > 0) parts.push(`${index.story.length} 个剧情`);
|
|
178
|
+
if (index.ui.length > 0) parts.push(`${index.ui.length} 个界面`);
|
|
179
|
+
return parts.join(" · ");
|
|
180
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 故事章节树 · **纯判据**(可测,无 IO / 无 Vue)。
|
|
3
|
+
*
|
|
4
|
+
* 存在理由:左栏原按「资源种类」平铺,但工程实践揭示了**另一个骨架**——
|
|
5
|
+
* `Stories/` 与 `Lang/` 常**按章节分目录**
|
|
6
|
+
* (`chapter1/chapter1.story`、`Lang/en-US/chapter1/chapter1.json`),
|
|
7
|
+
* 且 `Lang/` 有**三种布局并存**(en 平铺 / en-US 子目录分类 / ja 单文件)。
|
|
8
|
+
* ⇒ **内容骨架是「章节」,不是文件**;文件怎么摆是**作者的自由**。
|
|
9
|
+
*
|
|
10
|
+
* **任意深度递归,不写死「一级 = 章节」**:常见工程恰好只到 1 层
|
|
11
|
+
* (`Stories/chapter1/chapter1.story`),也有 0 层平铺
|
|
12
|
+
* (`Stories/start.json`);而 `Lang/en-US/system/about.json` 已到 2 层
|
|
13
|
+
* ⇒ 按层数写死会错。
|
|
14
|
+
* 0 层平铺工程退化为「无章节分组的全平铺列表」,**不报错**。
|
|
15
|
+
*
|
|
16
|
+
* 域出口:本文件**只做转发**(类型声明见 `./types`、判据与装配实现见 `./build`)。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
buildChapterIndex,
|
|
21
|
+
chapterDirOf,
|
|
22
|
+
chapterGroupOf,
|
|
23
|
+
chapterLabelOf,
|
|
24
|
+
chapterSummaryText,
|
|
25
|
+
sceneTypeBadgeOf,
|
|
26
|
+
} from "./build.ts";
|
|
27
|
+
|
|
28
|
+
export type {
|
|
29
|
+
ChapterDir,
|
|
30
|
+
ChapterGroup,
|
|
31
|
+
ChapterIndex,
|
|
32
|
+
ChapterInput,
|
|
33
|
+
ChapterNode,
|
|
34
|
+
} from "./types.ts";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 故事章节树 · **类型声明**(叶子模块:只声明形状,不 import 任何兄弟模块)。
|
|
3
|
+
*
|
|
4
|
+
* 类型放叶子:出口 `./index.ts` 与实现 `./build.ts` 都要用这些形状,
|
|
5
|
+
* 声明在两者任一侧都会让对方反向依赖。
|
|
6
|
+
*
|
|
7
|
+
* 语义与设计约定见出口 `./index.ts` 头注。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { StoryColumn } from "@lingfan-engine/core";
|
|
11
|
+
|
|
12
|
+
/** 章节树分组:剧情(可回溯)/ 界面(不参与历史与存档) */
|
|
13
|
+
export type ChapterGroup = "story" | "ui";
|
|
14
|
+
|
|
15
|
+
/** 一个章节(= 一个故事场景;**章节名取自所在目录链,不取自文件名**) */
|
|
16
|
+
export interface ChapterNode {
|
|
17
|
+
/** 章节标识(= 列 id,全局唯一) */
|
|
18
|
+
readonly id: string;
|
|
19
|
+
/** 章节显示名(取自路径末级目录;0 层平铺时取文件名去后缀) */
|
|
20
|
+
readonly label: string;
|
|
21
|
+
/** 该章节的场景所属分组(由 `type` 决定,**不按目录猜**) */
|
|
22
|
+
readonly group: ChapterGroup;
|
|
23
|
+
/**
|
|
24
|
+
* 原始场景类型(列的 `type` 字段原样透传;`undefined` = 缺省 game)。
|
|
25
|
+
* 分组判定只吃 `group`;要**精确到 菜单/界面** 的展示走 `sceneTypeBadgeOf(node.type)`
|
|
26
|
+
* (`group=ui` 只说明「不可回溯」,不说明是哪一种)。
|
|
27
|
+
*/
|
|
28
|
+
readonly type: StoryColumn["type"];
|
|
29
|
+
/** 章节在文件树中的位置(逻辑路径,用于联动资源树选中) */
|
|
30
|
+
readonly path: string;
|
|
31
|
+
/** 章节内命令条数(展示用;0 = 未知) */
|
|
32
|
+
readonly commandCount: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 目录分组(**任意深度**:目录即章节组,叶子才是故事) */
|
|
36
|
+
export interface ChapterDir {
|
|
37
|
+
/** 目录名(单层展示名;完整路径在 `path`) */
|
|
38
|
+
readonly label: string;
|
|
39
|
+
/** 目录逻辑路径(末尾带 `/`) */
|
|
40
|
+
readonly path: string;
|
|
41
|
+
readonly children: readonly ChapterNode[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 组装入参:路径 + 列(两者按 `id` 关联) */
|
|
45
|
+
export interface ChapterInput {
|
|
46
|
+
/** 故事文件的逻辑路径(如 `Stories/chapter1/chapter1.story`) */
|
|
47
|
+
readonly path: string;
|
|
48
|
+
readonly column: StoryColumn;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ChapterIndex {
|
|
52
|
+
/** 剧情组(可回溯)——排序:路径码元序(确定性) */
|
|
53
|
+
readonly story: readonly ChapterNode[];
|
|
54
|
+
/** 界面组(menu/ui) */
|
|
55
|
+
readonly ui: readonly ChapterNode[];
|
|
56
|
+
/** 目录分组(**只含子目录**;0 层平铺工程为空数组) */
|
|
57
|
+
readonly dirs: readonly ChapterDir[];
|
|
58
|
+
/**
|
|
59
|
+
* **按组过滤的目录**(剧情组)。
|
|
60
|
+
*
|
|
61
|
+
* 为何要拆:目录是**作者的编排**,`type` 是**运行语义**——两者**正交**,
|
|
62
|
+
* 一个目录里可能既有剧情又有界面(如 `system/` 里放 `about`(menu) + `sandbox`(game))。
|
|
63
|
+
* 而面板先按 type 分组展示(剧情 / 界面),故目录要**跟着组走**:
|
|
64
|
+
* 若直接用全局 `dirs`,界面组的目录里会混进剧情节点。
|
|
65
|
+
*/
|
|
66
|
+
readonly storyDirs: readonly ChapterDir[];
|
|
67
|
+
/** 按组过滤的目录(界面组) */
|
|
68
|
+
readonly uiDirs: readonly ChapterDir[];
|
|
69
|
+
/** 是否为**平铺工程**(无任何子目录分组)—— UI 据此决定要不要显示「章节」标题 */
|
|
70
|
+
readonly flat: boolean;
|
|
71
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 诊断契约:编辑期诊断统一形态,pointer = RFC 6901 JSON Pointer(指向 Story 树)。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { EditorTexts } from "./texts.ts";
|
|
6
|
+
|
|
7
|
+
export type DiagnosticSeverity = "error" | "warning";
|
|
8
|
+
|
|
9
|
+
export interface Diagnostic {
|
|
10
|
+
/** 诊断码:unknown-op / unknown-field / missing-required / invalid-value / duplicate-column / missing-target / unknown-function / undefined-variable / missing-resource / missing-entry / invalid-structure / unused-translation / missing-translation / invalid-element / unimplemented-element-attr */
|
|
11
|
+
code: string;
|
|
12
|
+
severity: DiagnosticSeverity;
|
|
13
|
+
message: string;
|
|
14
|
+
/** RFC 6901 JSON Pointer,指向 Story 树内位置(如 /columns/0/commands/3/text) */
|
|
15
|
+
pointer: string;
|
|
16
|
+
/** 涉及的 op(结构诊断时附带) */
|
|
17
|
+
op?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 符号索引:columnId / defines 键 / 变量 / 函数 / 跳转目标 / 资源引用 / 可翻译原文 */
|
|
21
|
+
export interface SymbolIndex {
|
|
22
|
+
/** columnId → 首个同名列的指针(重复列另见 duplicateColumns) */
|
|
23
|
+
columnPointers: Map<string, string>;
|
|
24
|
+
duplicateColumns: { id: string; pointer: string }[];
|
|
25
|
+
entry: string;
|
|
26
|
+
/** 变量定义键 → 首个定义处指针(含 defines / set / define / let / local / array / dict / random.var / 循环变量 / input.store) */
|
|
27
|
+
definedKeys: Map<string, string>;
|
|
28
|
+
/** 函数名 → 参数与定义处(func op) */
|
|
29
|
+
functions: Map<string, { params: string[]; pointer: string }>;
|
|
30
|
+
/** 跳转/调用目标引用(jump/menu/navigate → column;call → function) */
|
|
31
|
+
targets: {
|
|
32
|
+
pointer: string;
|
|
33
|
+
target: string;
|
|
34
|
+
/**
|
|
35
|
+
* 目标种类:
|
|
36
|
+
* - `column`:只能指向列(jump / menu 选项)
|
|
37
|
+
* - `function`:只能指向 func(无)
|
|
38
|
+
* - `callable`:**两者皆可**(`call` —— 语义是「func 或 label」)
|
|
39
|
+
*/
|
|
40
|
+
kind: "column" | "function" | "callable";
|
|
41
|
+
}[];
|
|
42
|
+
/** 资源逻辑路径引用(resource kind 字段 + say.voice) */
|
|
43
|
+
resources: { pointer: string; path: string }[];
|
|
44
|
+
/** 表达式/插值中的变量引用(undefined-variable 诊断与 `_` 豁免的输入) */
|
|
45
|
+
variableRefs: {
|
|
46
|
+
pointer: string;
|
|
47
|
+
name: string;
|
|
48
|
+
kind: "expression" | "interpolation";
|
|
49
|
+
}[];
|
|
50
|
+
/** 可翻译原文集合(say.text/speaker、menu.prompt、menu.options[].text、input.prompt、notify.text、元素 text——走运行期 Translate;character.screen 仅编辑器比对面,运行期不翻) */
|
|
51
|
+
originals: Set<string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** analyzeStory 可选供给侧数据:缺省时对应诊断族跳过(不误报) */
|
|
55
|
+
export interface AnalyzeOptions {
|
|
56
|
+
/** 资源根内实际文件集合(相对 Resources/ 的逻辑路径)→ 资源路径缺失诊断 */
|
|
57
|
+
resourceFiles?: ReadonlySet<string>;
|
|
58
|
+
/** overlay 译文键集合(Lang/{lang} 合并后)→ 未使用翻译键诊断(翻译缺口检查器) */
|
|
59
|
+
overlayKeys?: ReadonlySet<string>;
|
|
60
|
+
/** 集中文案表注入(缺省 defaultEditorTexts,即编辑器的既有文案) */
|
|
61
|
+
texts?: Partial<EditorTexts>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 编辑核心契约:故事树纯映射器(只读写故事 JSON,不碰运行时/Rust)+
|
|
3
|
+
* 统一 undo(所有视图共享,一次提交 = 一个 undo 单元)。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Story } from "@lingfan-engine/core";
|
|
7
|
+
|
|
8
|
+
/** 一次编辑提交(一个 undo 单元):before/after 以不可变结构共享 */
|
|
9
|
+
export interface UndoEntry {
|
|
10
|
+
label: string;
|
|
11
|
+
before: Story;
|
|
12
|
+
after: Story;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** 编辑器会话观察者:任何视图提交后收到新故事树(一处改动全视图同步) */
|
|
16
|
+
export type StoryListener = (story: Story) => void;
|
|
17
|
+
|
|
18
|
+
/** 命令容器(两类列) */
|
|
19
|
+
export type ContainerField = "commands" | "entry" | "elements";
|
|
20
|
+
|
|
21
|
+
/** 列的命令容器元数据:flow → commands;scene → entry(入口命令)与 elements(元素) */
|
|
22
|
+
export interface ContainerInfo {
|
|
23
|
+
columnId: string;
|
|
24
|
+
columnPointer: string;
|
|
25
|
+
kind: "scene" | "flow";
|
|
26
|
+
}
|