@arcadia-eternity/content-sdk 4.5.3 → 4.7.1
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/README.md +2 -2
- package/dist/author-api.d.ts +12 -2
- package/dist/author-api.js +11 -2
- package/dist/author-git.d.ts +63 -0
- package/dist/author-git.js +324 -0
- package/dist/author-reference.d.ts +15 -1
- package/dist/author-reference.js +20 -1
- package/dist/cli.js +5 -4
- package/dist/content-query.d.ts +15 -1
- package/dist/content-query.js +53 -11
- package/dist/content-workspace.d.ts +435 -6
- package/dist/content-workspace.js +238 -77
- package/dist/debug-environments.d.ts +393 -33
- package/dist/debug-environments.js +10 -50
- package/dist/demo.js +1 -1
- package/dist/effect-declarations.d.ts +14 -0
- package/dist/effect-declarations.js +103 -0
- package/dist/environment-host-base.d.ts +175 -0
- package/dist/environment-host-base.js +86 -0
- package/dist/environment-member-transfer.d.ts +5 -0
- package/dist/environment-member-transfer.js +95 -0
- package/dist/environment-rules.d.ts +728 -3
- package/dist/environment-rules.js +158 -74
- package/dist/environment-sharing.d.ts +51 -0
- package/dist/environment-sharing.js +321 -0
- package/dist/environment.d.ts +2 -0
- package/dist/environment.js +32 -9
- package/dist/jobs.d.ts +5 -0
- package/dist/jobs.js +59 -10
- package/dist/learnsets.d.ts +47 -0
- package/dist/learnsets.js +124 -0
- package/dist/lib/content.d.ts +1 -1
- package/dist/lib/content.js +26 -2
- package/dist/lib/presentation.js +5 -11
- package/dist/managed-projects.d.ts +6 -0
- package/dist/managed-projects.js +137 -45
- package/dist/managed-sources.d.ts +17 -0
- package/dist/managed-sources.js +28 -10
- package/dist/mcp-contracts.d.ts +405 -12
- package/dist/mcp-contracts.js +3 -1
- package/dist/mcp.js +23 -1
- package/dist/pack-project.d.ts +2 -1
- package/dist/pack-project.js +40 -5
- package/dist/prepared-document.d.ts +476 -0
- package/dist/prepared-document.js +47 -0
- package/dist/preview.js +5 -5
- package/dist/project.d.ts +3 -1
- package/dist/project.js +47 -4
- package/dist/rule-composition.d.ts +290 -0
- package/dist/rule-composition.js +267 -0
- package/dist/template/.github/scripts/release-payload.mjs +91 -0
- package/dist/template/.github/scripts/release-test-npm.mjs +27 -0
- package/dist/template/.github/scripts/verify-release.mjs +138 -0
- package/dist/template/.github/workflows/release-pack.yml +77 -0
- package/dist/template/README.md +15 -2
- package/dist/template/gitignore-template +7 -0
- package/dist/template/npm-lock-template.json +2319 -0
- package/dist/template/package.json +4 -2
- package/dist/template/skills/arcadia-content-authoring/references/tool-workflows.md +1 -1
- package/dist/template/skills/arcadia-content-git/SKILL.md +14 -0
- package/dist/template/skills/arcadia-content-release/SKILL.md +29 -0
- package/dist/template/test/pack.test.mjs +24 -5
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +26 -7
- package/dist/workspace-cli.js +2 -2
- package/dist/workspace-materials.d.ts +4 -1
- package/dist/workspace-materials.js +8 -2
- package/dist/workspace.d.ts +11 -0
- package/dist/workspace.js +191 -31
- package/package.json +16 -4
- package/release-payload.mjs +91 -0
- package/release-test-npm.mjs +27 -0
package/dist/environment.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sha256Hex } from '@arcadia-eternity/const';
|
|
1
2
|
import assert from 'node:assert/strict';
|
|
2
3
|
import { execFile } from 'node:child_process';
|
|
3
4
|
import { mkdir, mkdtemp, readFile, rm, writeFile, cp, symlink } from 'node:fs/promises';
|
|
@@ -7,9 +8,9 @@ import { promisify } from 'node:util';
|
|
|
7
8
|
import { emptyNpmContentHost, parseNpmPackOutput, prepareNpmProject, resolveNpmInvocation, } from '@arcadia-eternity/pack-loader/node';
|
|
8
9
|
import { AuthorWorkspace } from './workspace.js';
|
|
9
10
|
import { ProjectTeams, playersFromTeams } from './project-teams.js';
|
|
10
|
-
import {
|
|
11
|
+
import { gameplayRevision } from '@arcadia-eternity/pack-loader/native';
|
|
11
12
|
import { DebugEnvironments, normalizeEnvironmentDocument } from './debug-environments.js';
|
|
12
|
-
import { assertEnvironmentRequirements,
|
|
13
|
+
import { assertEnvironmentRequirements, defaultRuleDeclaration, prepareRulesForContent, validateEnvironmentRuleDeclaration, } from './environment-rules.js';
|
|
13
14
|
import { siblingModulePath } from './module-path.js';
|
|
14
15
|
import { errorCode } from './types.js';
|
|
15
16
|
const exec = promisify(execFile);
|
|
@@ -23,7 +24,7 @@ async function npm(args, options) {
|
|
|
23
24
|
return exec(invocation.file, invocation.args, options);
|
|
24
25
|
}
|
|
25
26
|
/** Pack and install exactly what a consuming server receives. Approval is limited to this local demo. */
|
|
26
|
-
export async function prepareBattleEnvironment(root = process.cwd(), { offline =
|
|
27
|
+
export async function prepareBattleEnvironment(root = process.cwd(), { offline = !process.env.ARCADIA_TEST_RELEASE_ARCHIVE, cache, environmentId = 'default', sources = {}, lockRoot, } = {}) {
|
|
27
28
|
root = resolve(root);
|
|
28
29
|
const temporary = await mkdtemp(join(tmpdir(), 'arcadia-pack-template-'));
|
|
29
30
|
const manifest = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'));
|
|
@@ -54,7 +55,7 @@ export async function prepareBattleEnvironment(root = process.cwd(), { offline =
|
|
|
54
55
|
}
|
|
55
56
|
: normalizeEnvironmentDocument(selectedDocument);
|
|
56
57
|
assertEnvironmentRequirements(environmentDocument.requires);
|
|
57
|
-
|
|
58
|
+
validateEnvironmentRuleDeclaration(environmentDocument.rules);
|
|
58
59
|
const lockFile = environmentId === 'default' ? undefined : `debug/environments/${environmentId}.package-lock.json`;
|
|
59
60
|
let oldLock;
|
|
60
61
|
if (lockFile) {
|
|
@@ -66,13 +67,26 @@ export async function prepareBattleEnvironment(root = process.cwd(), { offline =
|
|
|
66
67
|
throw error;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
const
|
|
70
|
+
const archive = process.env.ARCADIA_TEST_RELEASE_ARCHIVE;
|
|
71
|
+
if (archive && !/^[a-z0-9][a-z0-9._-]*\.tgz$/.test(archive))
|
|
72
|
+
throw new Error('Invalid release archive filename');
|
|
73
|
+
const result = await npm([
|
|
74
|
+
'pack',
|
|
75
|
+
...(archive ? [join(root, archive)] : []),
|
|
76
|
+
'--json',
|
|
77
|
+
'--ignore-scripts',
|
|
78
|
+
'--pack-destination',
|
|
79
|
+
temporary,
|
|
80
|
+
...cacheArgs,
|
|
81
|
+
], {
|
|
70
82
|
cwd: root,
|
|
71
83
|
});
|
|
72
84
|
const packed = requirePackedInfo(parseNpmPackOutput(String(result.stdout))[0]);
|
|
85
|
+
if (archive && packed.integrity !== process.env.ARCADIA_TEST_RELEASE_INTEGRITY)
|
|
86
|
+
throw new Error('Release archive integrity changed before testing');
|
|
73
87
|
const files = packed.files.map(file => file.path);
|
|
74
88
|
assert.ok(files.includes(manifest.arcadia.content));
|
|
75
|
-
if (manifest.arcadia.effects)
|
|
89
|
+
if (!archive && manifest.arcadia.effects)
|
|
76
90
|
assert.ok(files.includes(manifest.arcadia.effects));
|
|
77
91
|
assert.ok(!files.some(file => /^(?:\.arcadia|\.github|node_modules|test|scripts|debug)\//.test(file)), 'the package must contain content, not a developer workspace');
|
|
78
92
|
const installation = join(temporary, 'server-project');
|
|
@@ -137,7 +151,10 @@ export async function prepareBattleEnvironment(root = process.cwd(), { offline =
|
|
|
137
151
|
], { cwd: installation });
|
|
138
152
|
environment = await prepareNpmProject(installation, emptyNpmContentHost, {
|
|
139
153
|
policy: { profile: 'local-development' },
|
|
140
|
-
});
|
|
154
|
+
}, archive ? { effectPreparation: 'prebuilt-only' } : {});
|
|
155
|
+
if (environmentId === 'default')
|
|
156
|
+
environmentDocument.rules = defaultRuleDeclaration(environment.sandbox.data.ruleSets);
|
|
157
|
+
const { rules: effectiveRules } = prepareRulesForContent(environmentDocument.rules, environment.sandbox.data);
|
|
141
158
|
let environmentLock;
|
|
142
159
|
if (lockFile) {
|
|
143
160
|
const text = await readFile(join(installation, 'package-lock.json'), 'utf8');
|
|
@@ -147,7 +164,7 @@ export async function prepareBattleEnvironment(root = process.cwd(), { offline =
|
|
|
147
164
|
environmentLock = { file: lockFile, version: saved.version };
|
|
148
165
|
}
|
|
149
166
|
else
|
|
150
|
-
environmentLock = { file: lockFile, version:
|
|
167
|
+
environmentLock = { file: lockFile, version: sha256Hex(text) };
|
|
151
168
|
}
|
|
152
169
|
const teamLibrary = await new ProjectTeams(workspace).list();
|
|
153
170
|
function loadTeams(ids) {
|
|
@@ -160,7 +177,12 @@ export async function prepareBattleEnvironment(root = process.cwd(), { offline =
|
|
|
160
177
|
shasum: packed.shasum,
|
|
161
178
|
sdkApi: manifest.arcadia.sdkApi,
|
|
162
179
|
build: environment.build,
|
|
163
|
-
environmentRevision:
|
|
180
|
+
environmentRevision: await gameplayRevision({
|
|
181
|
+
kind: 'native-v4',
|
|
182
|
+
contentRevision: environment.revision,
|
|
183
|
+
coreBuildId: environment.build.coreBuildId,
|
|
184
|
+
registryBuildId: environment.build.registryBuildId,
|
|
185
|
+
}, environment.sandbox.revision, effectiveRules),
|
|
164
186
|
environmentId,
|
|
165
187
|
environmentConfigVersion: selected.version,
|
|
166
188
|
};
|
|
@@ -169,6 +191,7 @@ export async function prepareBattleEnvironment(root = process.cwd(), { offline =
|
|
|
169
191
|
return {
|
|
170
192
|
environment,
|
|
171
193
|
environmentDocument,
|
|
194
|
+
effectiveRules,
|
|
172
195
|
candidate,
|
|
173
196
|
environmentLock,
|
|
174
197
|
sourceRevisions,
|
package/dist/jobs.d.ts
CHANGED
package/dist/jobs.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
-
import {
|
|
3
|
+
import { x as extractTar } from 'tar';
|
|
4
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
5
|
import { cp, mkdir, mkdtemp, rm, symlink, readFile } from 'node:fs/promises';
|
|
5
6
|
import { join, dirname } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
6
8
|
import { tmpdir } from 'node:os';
|
|
7
9
|
import { AuthorWorkspace, WorkspaceError, diagnostic } from './workspace.js';
|
|
8
10
|
import { JobJournal } from './job-journal.js';
|
|
@@ -203,7 +205,7 @@ export class AuthorJobs {
|
|
|
203
205
|
await this.workspace.assertWritable();
|
|
204
206
|
if (this.#closed)
|
|
205
207
|
throw new WorkspaceError('WORKSPACE_CLOSED', '任务宿主已关闭');
|
|
206
|
-
if (!['check', 'test', 'demo', 'preview', 'pack'].includes(kind))
|
|
208
|
+
if (!['check', 'test', 'demo', 'preview', 'pack', 'release'].includes(kind))
|
|
207
209
|
throw new WorkspaceError('TASK_INVALID', '不支持的作者任务');
|
|
208
210
|
if (kind !== 'check' && !this.execute)
|
|
209
211
|
throw new WorkspaceError('EXECUTION_DISABLED', '此会话未启用项目代码执行');
|
|
@@ -285,7 +287,7 @@ export class AuthorJobs {
|
|
|
285
287
|
integer(limit, 1, 100, 'limit');
|
|
286
288
|
if (state !== undefined && !['queued', 'running', ...terminal].includes(state))
|
|
287
289
|
queryError('任务状态无效');
|
|
288
|
-
if (kind !== undefined && !['check', 'test', 'demo', 'preview', 'pack'].includes(kind))
|
|
290
|
+
if (kind !== undefined && !['check', 'test', 'demo', 'preview', 'pack', 'release'].includes(kind))
|
|
289
291
|
queryError('任务类型无效');
|
|
290
292
|
await this.refresh();
|
|
291
293
|
const rows = [...this.#jobs.values()]
|
|
@@ -419,14 +421,45 @@ export class AuthorJobs {
|
|
|
419
421
|
else if (job.kind === 'pack')
|
|
420
422
|
await this.#process([cli, 'pack'], job, signal);
|
|
421
423
|
else {
|
|
422
|
-
|
|
424
|
+
if (job.kind === 'release')
|
|
425
|
+
await this.#process([cli, 'pack', '--release'], job, signal);
|
|
426
|
+
else
|
|
427
|
+
await this.#process([cli, 'build'], job, signal, false, capture);
|
|
423
428
|
if (job.kind === 'demo' || job.kind === 'preview')
|
|
424
429
|
await this.#process([cli, job.kind], job, signal, job.kind === 'preview', capture);
|
|
425
430
|
else {
|
|
426
431
|
const files = (await this.workspace.files()).filter(entry => /^(test|tests)\/.+\.test\.(mjs|js|cjs)$/.test(entry.file));
|
|
427
432
|
if (!files.length)
|
|
428
433
|
throw new WorkspaceError('TESTS_MISSING', '未发现 test/ 或 tests/ 下的 *.test.mjs/js/cjs 场景');
|
|
429
|
-
|
|
434
|
+
const archive = job.kind === 'release' ? job.result : undefined;
|
|
435
|
+
if (job.kind === 'release' &&
|
|
436
|
+
(!archive?.verifiedRelease || typeof archive.filename !== 'string' || typeof archive.integrity !== 'string'))
|
|
437
|
+
throw new WorkspaceError('RELEASE_INVALID', '缺少已验证的发行归档');
|
|
438
|
+
if (archive?.filename) {
|
|
439
|
+
if (!/^[a-z0-9][a-z0-9._-]*\.tgz$/.test(archive.filename))
|
|
440
|
+
throw new WorkspaceError('RELEASE_INVALID', '发行归档名无效');
|
|
441
|
+
capture = await mkdtemp(join(tmpdir(), 'arcadia-release-scenarios-'));
|
|
442
|
+
const file = join(capture, archive.filename);
|
|
443
|
+
await cp(join(this.workspace.root, archive.filename), file);
|
|
444
|
+
const integrity = 'sha512-' +
|
|
445
|
+
createHash('sha512')
|
|
446
|
+
.update(await readFile(file))
|
|
447
|
+
.digest('base64');
|
|
448
|
+
if (integrity !== archive.integrity)
|
|
449
|
+
throw new WorkspaceError('RELEASE_INVALID', '发行归档已改变');
|
|
450
|
+
await extractTar({ file, cwd: capture, strip: 1, strict: true });
|
|
451
|
+
for (const entry of await this.workspace.files()) {
|
|
452
|
+
if (!/^(?:tests?\/|debug\/|arcadia\.config\.mjs$)/.test(entry.file))
|
|
453
|
+
continue;
|
|
454
|
+
const target = join(capture, entry.file);
|
|
455
|
+
await mkdir(dirname(target), { recursive: true });
|
|
456
|
+
await cp(await this.workspace.path(entry.file), target);
|
|
457
|
+
}
|
|
458
|
+
await symlink(join(this.workspace.root, 'node_modules'), join(capture, 'node_modules'), process.platform === 'win32' ? 'junction' : 'dir');
|
|
459
|
+
}
|
|
460
|
+
await this.#process(['--test', '--test-reporter=tap', ...files.map(entry => entry.file)], job, signal, false, capture, archive);
|
|
461
|
+
if (archive)
|
|
462
|
+
job.result = archive;
|
|
430
463
|
}
|
|
431
464
|
}
|
|
432
465
|
}
|
|
@@ -467,7 +500,7 @@ export class AuthorJobs {
|
|
|
467
500
|
this.#notify();
|
|
468
501
|
}
|
|
469
502
|
}
|
|
470
|
-
async #process(args, job, signal, preview = false, capture = undefined) {
|
|
503
|
+
async #process(args, job, signal, preview = false, capture = undefined, release) {
|
|
471
504
|
if (signal.aborted)
|
|
472
505
|
throw new WorkspaceError('TASK_CANCELLED', '任务已取消');
|
|
473
506
|
const phases = {
|
|
@@ -486,6 +519,15 @@ export class AuthorJobs {
|
|
|
486
519
|
...this.env,
|
|
487
520
|
ELECTRON_RUN_AS_NODE: '1',
|
|
488
521
|
ARCADIA_AUTHOR_RESULT: '1',
|
|
522
|
+
...(release
|
|
523
|
+
? {
|
|
524
|
+
ARCADIA_NPM_CLI: fileURLToPath(new URL('../release-test-npm.mjs', import.meta.url)),
|
|
525
|
+
ARCADIA_TEST_BASE_NPM: this.env.ARCADIA_NPM_CLI ?? '',
|
|
526
|
+
ARCADIA_TEST_RELEASE_ROOT: capture,
|
|
527
|
+
ARCADIA_TEST_RELEASE_ARCHIVE: release.filename,
|
|
528
|
+
ARCADIA_TEST_RELEASE_INTEGRITY: release.integrity,
|
|
529
|
+
}
|
|
530
|
+
: {}),
|
|
489
531
|
...(preview ? { ARCADIA_DEBUG_ENVIRONMENT: job.environmentId, ARCADIA_DEBUG_ROOT: this.workspace.root } : {}),
|
|
490
532
|
},
|
|
491
533
|
stdio: ['ignore', 'pipe', 'pipe', ...(preview ? ['ipc'] : [])],
|
|
@@ -513,24 +555,29 @@ export class AuthorJobs {
|
|
|
513
555
|
signal.addEventListener('abort', abort, { once: true });
|
|
514
556
|
if (signal.aborted)
|
|
515
557
|
abort();
|
|
516
|
-
let buffer = '', ready = false;
|
|
558
|
+
let buffer = '', ready = false, testedArchive = false;
|
|
517
559
|
const output = (text) => {
|
|
518
560
|
if (!text)
|
|
519
561
|
return;
|
|
520
562
|
job.outputCursor = outputRange(job).end + text.length;
|
|
521
563
|
job.output = (job.output + text).slice(-outputLimit);
|
|
522
564
|
this.#notify();
|
|
523
|
-
if (!preview || ready)
|
|
565
|
+
if ((!preview || ready) && (!release || testedArchive))
|
|
524
566
|
return;
|
|
525
567
|
buffer += text;
|
|
526
568
|
let newline;
|
|
527
569
|
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
528
|
-
const line = buffer.slice(0, newline);
|
|
570
|
+
const line = buffer.slice(0, newline).replace(/^# /, '');
|
|
529
571
|
buffer = buffer.slice(newline + 1);
|
|
530
572
|
if (!line.startsWith('ARCADIA_RESULT='))
|
|
531
573
|
continue;
|
|
532
574
|
try {
|
|
533
575
|
const result = JSON.parse(line.slice('ARCADIA_RESULT='.length));
|
|
576
|
+
if (release) {
|
|
577
|
+
if (result.candidate?.integrity === release.integrity)
|
|
578
|
+
testedArchive = true;
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
534
581
|
if (!result.preview?.endpoint || signal.aborted)
|
|
535
582
|
continue;
|
|
536
583
|
job.result = result;
|
|
@@ -593,7 +640,9 @@ export class AuthorJobs {
|
|
|
593
640
|
message: match[5],
|
|
594
641
|
});
|
|
595
642
|
}
|
|
596
|
-
if (code === 0 && !signal.aborted)
|
|
643
|
+
if (code === 0 && !signal.aborted && release && !testedArchive)
|
|
644
|
+
reject(new WorkspaceError('RELEASE_TEST_ARCHIVE', '项目场景未验证本次发行归档,请更新测试 SDK 或检查场景的归档来源。'));
|
|
645
|
+
else if (code === 0 && !signal.aborted)
|
|
597
646
|
resolve();
|
|
598
647
|
else
|
|
599
648
|
reject(new WorkspaceError(signal.aborted ? 'TASK_CANCELLED' : 'TASK_FAILED', signal.aborted ? '任务已取消或超过三分钟' : `作者命令失败(${code}),请查看诊断与输出`));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type EnvironmentRules } from '@arcadia-eternity/const';
|
|
2
|
+
export interface LearnsetSpecies {
|
|
3
|
+
id: string;
|
|
4
|
+
learnable_skills: readonly {
|
|
5
|
+
skill_id: string;
|
|
6
|
+
level: number;
|
|
7
|
+
}[];
|
|
8
|
+
enhancementBranches?: readonly string[];
|
|
9
|
+
ability?: readonly (string | {
|
|
10
|
+
id: string;
|
|
11
|
+
})[];
|
|
12
|
+
emblem?: readonly (string | {
|
|
13
|
+
id: string;
|
|
14
|
+
})[];
|
|
15
|
+
inheritance?: {
|
|
16
|
+
skills: string[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
type LearningRules = Pick<EnvironmentRules, 'mechanics' | 'learnsetAdjustments'>;
|
|
20
|
+
type Eligibility = NonNullable<EnvironmentRules['mechanics']>['secondGenerationNatures'];
|
|
21
|
+
export declare function isEligible(species: Pick<LearnsetSpecies, 'id' | 'inheritance'>, selection?: Eligibility): boolean;
|
|
22
|
+
/** Static acquisition sources. Choosing an inherited skill does not create an equipment slot. */
|
|
23
|
+
export declare function resolveLearnset(rules: LearningRules | undefined, species: LearnsetSpecies, level: number): {
|
|
24
|
+
normal: Set<string>;
|
|
25
|
+
inherited: Set<string>;
|
|
26
|
+
eligible: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare function learningIssues(rules: LearningRules | undefined, species: LearnsetSpecies, pet: {
|
|
29
|
+
level: number;
|
|
30
|
+
inheritedSkill?: string;
|
|
31
|
+
skills: string[];
|
|
32
|
+
}): string[];
|
|
33
|
+
/** Called only with the definitions captured for this environment. */
|
|
34
|
+
export declare function validateLearningReferences(rules: LearningRules | undefined, knownSpecies: (id: string) => boolean, knownSkill: (id: string) => boolean, knownStage: (id: string) => boolean): void;
|
|
35
|
+
type NatureLookup = (id: string) => {
|
|
36
|
+
generation: 1 | 2;
|
|
37
|
+
} | undefined;
|
|
38
|
+
export declare function assertNatureChoice(rules: LearningRules | undefined, natureId: string, natureById: NatureLookup, speciesById: () => Pick<LearnsetSpecies, 'id' | 'inheritance'> | undefined): void;
|
|
39
|
+
export type LearningLookups = [
|
|
40
|
+
speciesById: (id: string) => unknown,
|
|
41
|
+
natureById: NatureLookup,
|
|
42
|
+
stageById: (id: string) => unknown,
|
|
43
|
+
skillById?: (id: string) => unknown,
|
|
44
|
+
markById?: (id: string) => unknown
|
|
45
|
+
];
|
|
46
|
+
export declare function assertLearningChoices(rules: LearningRules | undefined, team: readonly unknown[], ...[speciesById, natureById, stageById, skillById, markById]: LearningLookups): void;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { defaultLearnsetLevel, assertSkillSlots, resolveEnvironmentMechanics, } from '@arcadia-eternity/const';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const id = z.string().min(1).max(256);
|
|
4
|
+
export function isEligible(species, selection) {
|
|
5
|
+
return (selection === 'all' ||
|
|
6
|
+
(selection === 'species' && species.inheritance !== undefined) ||
|
|
7
|
+
(Array.isArray(selection) && selection.includes(species.id)));
|
|
8
|
+
}
|
|
9
|
+
/** Static acquisition sources. Choosing an inherited skill does not create an equipment slot. */
|
|
10
|
+
export function resolveLearnset(rules, species, level) {
|
|
11
|
+
const normal = new Set(species.learnable_skills.filter(entry => entry.level <= level).map(entry => entry.skill_id));
|
|
12
|
+
const { inheritance } = resolveEnvironmentMechanics(rules);
|
|
13
|
+
const eligible = isEligible(species, inheritance.eligible);
|
|
14
|
+
const inherited = new Set(species.inheritance?.skills);
|
|
15
|
+
const pool = inheritance.pool;
|
|
16
|
+
if (pool && (pool.mode !== 'fallback' || !inherited.size)) {
|
|
17
|
+
if (pool.mode === 'replace')
|
|
18
|
+
inherited.clear();
|
|
19
|
+
for (const skill of pool.skills)
|
|
20
|
+
inherited.add(skill);
|
|
21
|
+
}
|
|
22
|
+
for (const row of rules?.learnsetAdjustments ?? []) {
|
|
23
|
+
if (row.species !== species.id)
|
|
24
|
+
continue;
|
|
25
|
+
const source = row.source === 'normal' ? normal : inherited;
|
|
26
|
+
if (row.action === 'remove')
|
|
27
|
+
source.delete(row.skill);
|
|
28
|
+
else if ((row.level ?? defaultLearnsetLevel) <= level)
|
|
29
|
+
source.add(row.skill);
|
|
30
|
+
}
|
|
31
|
+
if (!eligible)
|
|
32
|
+
inherited.clear();
|
|
33
|
+
return { normal, inherited, eligible };
|
|
34
|
+
}
|
|
35
|
+
export function learningIssues(rules, species, pet) {
|
|
36
|
+
const { normal, inherited } = resolveLearnset(rules, species, pet.level);
|
|
37
|
+
const issues = [];
|
|
38
|
+
if (pet.inheritedSkill && !inherited.has(pet.inheritedSkill))
|
|
39
|
+
issues.push('该精灵无法遗传 ' + pet.inheritedSkill);
|
|
40
|
+
for (const skill of pet.skills)
|
|
41
|
+
if (!normal.has(skill) && !(pet.inheritedSkill === skill && inherited.has(skill)))
|
|
42
|
+
issues.push('该精灵不能学习 ' + skill);
|
|
43
|
+
return issues;
|
|
44
|
+
}
|
|
45
|
+
/** Called only with the definitions captured for this environment. */
|
|
46
|
+
export function validateLearningReferences(rules, knownSpecies, knownSkill, knownStage) {
|
|
47
|
+
const check = (kind, value, exists) => {
|
|
48
|
+
if (!exists(value))
|
|
49
|
+
throw new Error(`ENVIRONMENT_REFERENCE_MISSING: ${kind} ${value}`);
|
|
50
|
+
};
|
|
51
|
+
const enhancement = rules?.mechanics?.enhancement;
|
|
52
|
+
if (enhancement?.mode === 'active') {
|
|
53
|
+
for (const id of enhancement.stages ?? [])
|
|
54
|
+
check('enhancement', id, knownStage);
|
|
55
|
+
for (const id of enhancement.species ?? [])
|
|
56
|
+
check('species', id, knownSpecies);
|
|
57
|
+
}
|
|
58
|
+
for (const eligible of [rules?.mechanics?.inheritance?.eligible, rules?.mechanics?.secondGenerationNatures])
|
|
59
|
+
if (Array.isArray(eligible))
|
|
60
|
+
for (const id of eligible)
|
|
61
|
+
check('species', id, knownSpecies);
|
|
62
|
+
for (const id of rules?.mechanics?.inheritance?.pool?.skills ?? [])
|
|
63
|
+
check('skill', id, knownSkill);
|
|
64
|
+
for (const row of rules?.learnsetAdjustments ?? []) {
|
|
65
|
+
check('species', row.species, knownSpecies);
|
|
66
|
+
check('skill', row.skill, knownSkill);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function assertNatureChoice(rules, natureId, natureById, speciesById) {
|
|
70
|
+
const nature = natureById(natureId);
|
|
71
|
+
if (!nature)
|
|
72
|
+
throw new Error('缺少性格定义 ' + natureId);
|
|
73
|
+
if (nature.generation === 1)
|
|
74
|
+
return;
|
|
75
|
+
const species = speciesById();
|
|
76
|
+
if (!species || !isEligible(species, resolveEnvironmentMechanics(rules).secondGenerationNatures))
|
|
77
|
+
throw new Error('该精灵不能使用二代性格 ' + natureId);
|
|
78
|
+
}
|
|
79
|
+
const learningSelection = z.object({
|
|
80
|
+
species: id,
|
|
81
|
+
nature: id,
|
|
82
|
+
enhancement: id.optional(),
|
|
83
|
+
level: z.number().int().min(1).max(100),
|
|
84
|
+
evs: z.record(z.string(), z.number()).optional(),
|
|
85
|
+
ability: z.string().optional(),
|
|
86
|
+
emblem: z.string().optional(),
|
|
87
|
+
skills: z.array(id),
|
|
88
|
+
inheritedSkill: id.optional(),
|
|
89
|
+
});
|
|
90
|
+
export function assertLearningChoices(rules, team, ...[speciesById, natureById, stageById, skillById, markById]) {
|
|
91
|
+
for (const input of team) {
|
|
92
|
+
const pet = learningSelection.parse(input);
|
|
93
|
+
if (skillById) {
|
|
94
|
+
for (const id of new Set(pet.inheritedSkill ? [...pet.skills, pet.inheritedSkill] : pet.skills))
|
|
95
|
+
if (!skillById(id))
|
|
96
|
+
throw new Error('缺少技能定义 ' + id);
|
|
97
|
+
}
|
|
98
|
+
assertSkillSlots(rules?.mechanics?.skillSlots, pet.skills, skillById ?? (() => undefined));
|
|
99
|
+
if (pet.evs && Object.values(pet.evs).reduce((sum, value) => sum + value, 0) > 510)
|
|
100
|
+
throw new Error('学习力总和不能超过 510');
|
|
101
|
+
const species = () => speciesById(pet.species);
|
|
102
|
+
assertNatureChoice(rules, pet.nature, natureById, species);
|
|
103
|
+
const definition = species();
|
|
104
|
+
if (!definition || !Array.isArray(definition.learnable_skills))
|
|
105
|
+
throw new Error('缺少物种学习表 ' + pet.species);
|
|
106
|
+
if (pet.enhancement && rules?.mechanics?.enhancement?.mode === 'active') {
|
|
107
|
+
const stage = stageById(pet.enhancement);
|
|
108
|
+
if (!stage)
|
|
109
|
+
throw new Error('缺少强化阶段 ' + pet.enhancement);
|
|
110
|
+
if (!definition.enhancementBranches?.includes(stage.branch))
|
|
111
|
+
throw new Error('该物种不能使用强化阶段 ' + pet.enhancement);
|
|
112
|
+
}
|
|
113
|
+
for (const kind of ['ability', 'emblem']) {
|
|
114
|
+
const selected = pet[kind];
|
|
115
|
+
if (selected && markById && !markById(selected))
|
|
116
|
+
throw new Error('缺少印记定义 ' + selected);
|
|
117
|
+
if (selected && !definition[kind]?.some(mark => (typeof mark === 'string' ? mark : mark.id) === selected))
|
|
118
|
+
throw new Error((kind === 'ability' ? 'Ability' : 'Emblem') + ' ' + selected + ' is not allowed for ' + pet.species);
|
|
119
|
+
}
|
|
120
|
+
const issues = learningIssues(rules, definition, pet);
|
|
121
|
+
if (issues.length)
|
|
122
|
+
throw new Error(issues.join('、'));
|
|
123
|
+
}
|
|
124
|
+
}
|
package/dist/lib/content.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Document } from 'yaml';
|
|
2
|
-
declare const sourceKinds: readonly ["species", "skills", "marks", "behaviors", "presentations", "resources"];
|
|
2
|
+
declare const sourceKinds: readonly ["species", "skills", "marks", "behaviors", "natures", "enhancements", "elements", "parameterGroups", "parameterProfiles", "parameterBindings", "ruleSets", "matchupTables", "presentations", "resources"];
|
|
3
3
|
type SourceKind = (typeof sourceKinds)[number];
|
|
4
4
|
export interface ContentSource {
|
|
5
5
|
kind: SourceKind;
|
package/dist/lib/content.js
CHANGED
|
@@ -3,7 +3,20 @@ import { extname, join, relative } from 'node:path';
|
|
|
3
3
|
import YAML from 'yaml';
|
|
4
4
|
import { isDeepStrictEqual } from 'node:util';
|
|
5
5
|
import { errorCode, errorMessage, isRecord } from '../types.js';
|
|
6
|
-
const contentKinds = [
|
|
6
|
+
const contentKinds = [
|
|
7
|
+
'species',
|
|
8
|
+
'skills',
|
|
9
|
+
'marks',
|
|
10
|
+
'behaviors',
|
|
11
|
+
'natures',
|
|
12
|
+
'enhancements',
|
|
13
|
+
'elements',
|
|
14
|
+
'parameterGroups',
|
|
15
|
+
'parameterProfiles',
|
|
16
|
+
'parameterBindings',
|
|
17
|
+
'ruleSets',
|
|
18
|
+
'matchupTables',
|
|
19
|
+
];
|
|
7
20
|
const sourceKinds = [...contentKinds, 'presentations', 'resources'];
|
|
8
21
|
async function filesIn(directory) {
|
|
9
22
|
let entries;
|
|
@@ -95,7 +108,18 @@ export async function readContentSources(root) {
|
|
|
95
108
|
/** File names and grouping do not enter runtime IDs or record ordering. */
|
|
96
109
|
export function assembleContent(sources) {
|
|
97
110
|
return {
|
|
98
|
-
data: Object.fromEntries(contentKinds
|
|
111
|
+
data: Object.fromEntries(contentKinds
|
|
112
|
+
.filter(kind => ![
|
|
113
|
+
'natures',
|
|
114
|
+
'enhancements',
|
|
115
|
+
'elements',
|
|
116
|
+
'parameterGroups',
|
|
117
|
+
'parameterProfiles',
|
|
118
|
+
'parameterBindings',
|
|
119
|
+
'ruleSets',
|
|
120
|
+
'matchupTables',
|
|
121
|
+
].includes(kind) || sources.some(source => source.kind === kind))
|
|
122
|
+
.map(kind => [
|
|
99
123
|
kind,
|
|
100
124
|
sources
|
|
101
125
|
.filter(source => source.kind === kind)
|
package/dist/lib/presentation.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sha256Hex } from '@arcadia-eternity/const';
|
|
2
|
+
import { isContentLocaleField, contentLocaleCollection } from '@arcadia-eternity/schema';
|
|
2
3
|
import { lstat, readdir, readFile } from 'node:fs/promises';
|
|
3
4
|
import { join, relative, extname } from 'node:path';
|
|
4
5
|
import YAML from 'yaml';
|
|
@@ -158,7 +159,7 @@ export async function buildPresentation(root, sources, { includeLocales = true }
|
|
|
158
159
|
kind: 'file',
|
|
159
160
|
id,
|
|
160
161
|
source: location,
|
|
161
|
-
sha256:
|
|
162
|
+
sha256: sha256Hex(bytes),
|
|
162
163
|
bytes: bytes.length,
|
|
163
164
|
mime,
|
|
164
165
|
...(record.tags ? { tags: record.tags } : {}),
|
|
@@ -217,14 +218,7 @@ export async function buildPresentation(root, sources, { includeLocales = true }
|
|
|
217
218
|
const value = match[3] === 'json' ? JSON.parse(text) : YAML.parse(text, { uniqueKeys: true, merge: true });
|
|
218
219
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
219
220
|
throw new Error(`Expected locale object: ${path}`);
|
|
220
|
-
const records =
|
|
221
|
-
species: 'species',
|
|
222
|
-
skill: 'skills',
|
|
223
|
-
mark: 'marks',
|
|
224
|
-
mark_ability: 'marks',
|
|
225
|
-
mark_emblem: 'marks',
|
|
226
|
-
mark_global: 'marks',
|
|
227
|
-
}[namespace];
|
|
221
|
+
const records = contentLocaleCollection(namespace);
|
|
228
222
|
if (!records)
|
|
229
223
|
throw new Error(`Unsupported content locale namespace: ${path}`);
|
|
230
224
|
const ids = new Set(sources.filter(source => source.kind === records).flatMap(source => source.records.map(record => record.id)));
|
|
@@ -234,7 +228,7 @@ export async function buildPresentation(root, sources, { includeLocales = true }
|
|
|
234
228
|
if (!entry ||
|
|
235
229
|
typeof entry !== 'object' ||
|
|
236
230
|
Array.isArray(entry) ||
|
|
237
|
-
Object.entries(entry).some(([field, text]) => !
|
|
231
|
+
Object.entries(entry).some(([field, text]) => !isContentLocaleField(namespace, field) || typeof text !== 'string'))
|
|
238
232
|
throw new Error(`${path}: Expected name/description strings for ${id}`);
|
|
239
233
|
}
|
|
240
234
|
const target = (locales[canonicalLanguage] ??= {});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ContentWorkspace, EnvironmentInstallation, PrepareEnvironmentInput, StaticPreparer } from './content-workspace.js';
|
|
2
2
|
import type { ManagedSource } from './managed-sources.js';
|
|
3
|
+
import { type UnknownRecord } from './types.js';
|
|
3
4
|
export interface ManagedProjectsOptions {
|
|
4
5
|
bundledPackageRoot?: string;
|
|
5
6
|
registry?: string;
|
|
@@ -22,9 +23,14 @@ export declare class ManagedProjects {
|
|
|
22
23
|
#private;
|
|
23
24
|
readonly root: string;
|
|
24
25
|
constructor(root: string, options?: ManagedProjectsOptions);
|
|
26
|
+
/** Resolve an author lock in isolation from the source tree and its linked development SDK. */
|
|
27
|
+
authorLock(manifest: UnknownRecord, previous?: string): Promise<string>;
|
|
28
|
+
withLocalArchive<T>(file: string, signal: AbortSignal, consume: (archive: string) => Promise<T>): Promise<T>;
|
|
29
|
+
withSourceArchive<T>(source: ManagedSource, signal: AbortSignal, consume: (archive: string, provenance: Record<string, string>) => Promise<T>): Promise<T>;
|
|
25
30
|
prepareEnvironment(workspace: ContentWorkspace, input: {
|
|
26
31
|
onProgress?: PrepareEnvironmentInput['onProgress'];
|
|
27
32
|
environmentId: string;
|
|
33
|
+
seedDirectory?: string;
|
|
28
34
|
expectedRevision: string | null;
|
|
29
35
|
document?: PrepareEnvironmentInput['document'];
|
|
30
36
|
signal?: AbortSignal;
|