@arcadia-eternity/content-sdk 4.3.2 → 4.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/author-reference.mjs +2 -2
- package/dist/cli.mjs +2 -0
- package/dist/effect-build.d.mts +2 -0
- package/dist/effect-build.mjs +46 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +2 -1
- package/dist/pack-project.mjs +1 -0
- package/dist/template/package.json +4 -3
- package/dist/template/skills/arcadia-content-authoring/SKILL.md +1 -1
- package/dist/template/skills/seer2-recreate-pet/SKILL.md +3 -3
- package/dist/template/src/effects/slow.effect.ts +54 -0
- package/package.json +8 -4
- package/dist/template/src/effects.ts +0 -44
|
@@ -77,8 +77,8 @@ export async function authorReference({ topic } = {}) {
|
|
|
77
77
|
return {
|
|
78
78
|
topic,
|
|
79
79
|
title: 'Native TypeScript effects',
|
|
80
|
-
source: '@arcadia-eternity/content-sdk/dist/template/src/effects.ts',
|
|
81
|
-
examples: [{ language: 'typescript', text: await template('src/effects.ts') }],
|
|
80
|
+
source: '@arcadia-eternity/content-sdk/dist/template/src/effects/slow.effect.ts',
|
|
81
|
+
examples: [{ language: 'typescript', text: await template('src/effects/slow.effect.ts') }],
|
|
82
82
|
notes: [
|
|
83
83
|
'Import EffectModuleContext from @arcadia-eternity/content-sdk and use the host-supplied SDK. Importing an effect module must not register global state.',
|
|
84
84
|
'defineCodeEffect uses triggers/apply. ctx.trigger identifies the trigger; ctx.parent is the typed parent context. Use stable namespaced IDs and actual behavior definitions.',
|
package/dist/cli.mjs
CHANGED
|
@@ -39,6 +39,8 @@ async function build() {
|
|
|
39
39
|
await data(true)
|
|
40
40
|
await types()
|
|
41
41
|
await data()
|
|
42
|
+
const { buildEffects } = await import('./effect-build.mjs')
|
|
43
|
+
await buildEffects(process.cwd())
|
|
42
44
|
}
|
|
43
45
|
try {
|
|
44
46
|
if (!command || command === '--help' || command === '-h') console.log(help)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir, rename, realpath, lstat, rm } from 'node:fs/promises'
|
|
2
|
+
import { resolve, relative, isAbsolute, dirname, sep } from 'node:path'
|
|
3
|
+
import { compileEffectModule } from '@arcadia-eternity/pack-loader/effect-build'
|
|
4
|
+
|
|
5
|
+
/** Build closed effect text without evaluating author code. The installed artifact is consumed by environment preparation. */
|
|
6
|
+
export async function buildEffects(root) {
|
|
7
|
+
root = await realpath(root)
|
|
8
|
+
const pkg = JSON.parse(await readFile(resolve(root, 'package.json'), 'utf8'))
|
|
9
|
+
const directory = pkg.arcadia?.effectSources
|
|
10
|
+
if (directory === undefined) return
|
|
11
|
+
if (
|
|
12
|
+
typeof directory !== 'string' ||
|
|
13
|
+
!directory ||
|
|
14
|
+
typeof pkg.arcadia.effectArtifact !== 'string' ||
|
|
15
|
+
pkg.arcadia.effects
|
|
16
|
+
)
|
|
17
|
+
throw new Error('effectSources requires an effectArtifact destination and no effects entry')
|
|
18
|
+
const source = resolve(root, directory),
|
|
19
|
+
destination = resolve(root, pkg.arcadia.effectArtifact)
|
|
20
|
+
for (const path of [source, destination]) {
|
|
21
|
+
const rel = relative(resolve(root), path)
|
|
22
|
+
if (rel === '..' || rel.startsWith('../') || isAbsolute(rel)) throw new Error('Effect path escapes project')
|
|
23
|
+
}
|
|
24
|
+
const canonicalSource = await realpath(source)
|
|
25
|
+
const sourceLocation = relative(root, canonicalSource)
|
|
26
|
+
if (sourceLocation === '..' || sourceLocation.startsWith(`..${sep}`) || isAbsolute(sourceLocation))
|
|
27
|
+
throw new Error('Effect source escapes project')
|
|
28
|
+
let parent = root
|
|
29
|
+
for (const segment of relative(root, dirname(destination)).split(sep).filter(Boolean)) {
|
|
30
|
+
parent = resolve(parent, segment)
|
|
31
|
+
await mkdir(parent, { recursive: true })
|
|
32
|
+
const info = await lstat(parent)
|
|
33
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
34
|
+
throw new Error('Effect output must use regular project directories')
|
|
35
|
+
}
|
|
36
|
+
const artifact = await compileEffectModule(source, root, pkg.name)
|
|
37
|
+
const temporary = `${destination}.${process.pid}.tmp`
|
|
38
|
+
await writeFile(temporary, JSON.stringify(artifact) + '\n', { flag: 'wx' })
|
|
39
|
+
try {
|
|
40
|
+
await rename(temporary, destination)
|
|
41
|
+
} finally {
|
|
42
|
+
await rm(temporary, { force: true })
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { effectDiscoveryPlugin } from '@arcadia-eternity/pack-loader/effect-build'
|
package/dist/index.d.mts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
1
|
export type { CodeEffectModule as EffectModule, CodeEffectModuleContext as EffectModuleContext, EffectSdk, } from '@arcadia-eternity/battle/authoring';
|
|
2
|
+
export { effect, on, loadCodeEffects } from '@arcadia-eternity/battle/effect-loading';
|
|
3
|
+
export type { EffectSource, EffectLoadingContext } from '@arcadia-eternity/battle/effect-loading';
|
|
4
|
+
export * from '@arcadia-eternity/battle/authoring';
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { effect, on, loadCodeEffects } from '@arcadia-eternity/battle/effect-loading';
|
|
2
|
+
export * from '@arcadia-eternity/battle/authoring';
|
package/dist/pack-project.mjs
CHANGED
|
@@ -78,6 +78,7 @@ export async function packBuiltProject(directory = process.cwd(), { cache } = {}
|
|
|
78
78
|
const included = new Set(preview.files.map(file => packagePath(file.path)))
|
|
79
79
|
if (!included.has('package.json')) fail('npm omitted the package manifest')
|
|
80
80
|
const required = manifest.arcadia?.content ? [manifest.arcadia.content] : []
|
|
81
|
+
if (manifest.arcadia?.effectSources) required.push(manifest.arcadia.effectArtifact)
|
|
81
82
|
let presentation
|
|
82
83
|
try {
|
|
83
84
|
presentation = JSON.parse(await readFile(join(root, 'dist/presentation.json'), 'utf8'))
|
|
@@ -25,16 +25,17 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "25.6.0",
|
|
27
27
|
"typescript": "6.0.3",
|
|
28
|
-
"@arcadia-eternity/content-sdk": "4.3.
|
|
28
|
+
"@arcadia-eternity/content-sdk": "4.3.4"
|
|
29
29
|
},
|
|
30
30
|
"arcadia": {
|
|
31
31
|
"formatVersion": 1,
|
|
32
32
|
"projectId": "example-content-pack",
|
|
33
33
|
"namespace": "example-pack",
|
|
34
34
|
"content": "dist/content.json",
|
|
35
|
-
"effects": "dist/effects.js",
|
|
36
35
|
"sdkApi": 2,
|
|
37
|
-
"presentation": "dist/presentation.json"
|
|
36
|
+
"presentation": "dist/presentation.json",
|
|
37
|
+
"effectSources": "src/effects",
|
|
38
|
+
"effectArtifact": "dist/arcadia-effects.json"
|
|
38
39
|
},
|
|
39
40
|
"description": "A runnable Arcadia Eternity user-defined content pack: species, skills, marks and TypeScript effects.",
|
|
40
41
|
"license": "MIT",
|
|
@@ -8,7 +8,7 @@ description: Build or debug an Arcadia Eternity npm content pack with TypeScript
|
|
|
8
8
|
Work in the author's content project. Ask for the desired game behavior when its trigger, target or lifetime is ambiguous. Use the SDK and host version actually available to the project; `arcadia.sdkApi` is an API compatibility version, not an engine build identity.
|
|
9
9
|
|
|
10
10
|
1. Read `package.json` and the actual source layout: `data/species`, `data/skills`, `data/marks`, `src`, `assets`, `locales`, `test` and `arcadia.config.mjs`. Some older projects still use a root `content.json`; follow their manifest rather than assuming it. Do not edit generated `dist` as source. If the host repository is available, consult `docs/guides/npm-content.md` and `docs/guides/effect-sdk.md`. Do not assume SDK packages have been published merely because a version is in a manifest.
|
|
11
|
-
2.
|
|
11
|
+
2. Declare behavior with `@effect` and `@on` in `src/effects/*.effect.ts`; for parameters or bindings use a decorated class with `static create(context)` returning `defineCodeEffect`. The SDK discovers files and builds `effectArtifact`. Use canonical prototypes from the current context. Keep `projectId`, namespace, use IDs and binding keys stable unless a breaking identity change is intended. Cross-package data references require npm dependencies.
|
|
12
12
|
3. Implement parameters with `numberParam`, `booleanParam` or `stringParam` when battle effects must read or modify them. Use the declared source scope and capture/follow semantics; do not require a parameter editing form. Keep per-battle state in engine instances, parameters and bindings rather than module-global mutable variables. Use the battle RNG instead of `Math.random()` for battle decisions.
|
|
13
13
|
4. Build and run the project's own scenario tests against the real engine. For a slow effect cover hit, miss, repeated application, removal and natural expiry; exercise supported waiting-point snapshot restoration if relevant. Preserve meaningful existing assertions and run independent host contract tests when available. The starter's `npm test` covers hit, miss, refresh, removal, natural expiry and restoration at a supported selection waiting point. Fix implementation failures rather than weakening unrelated tests.
|
|
14
14
|
5. Pack with `npm run pack` / `arcadia-content pack`, inspect the actual artifact and validate it in a separate npm installation. The author tool stages `arcadia.effectArtifact` and a closed effect module before its internal `npm pack --ignore-scripts`; plain npm pack does not generate this prebuilt artifact. Validate distributed code packages with prebuilt-only preparation so consumers need no author compilation or development dependencies. Installing, code admission and selecting a server environment are separate steps. Use the local development approval profile only for an explicitly approved local environment. Never treat a content hash, package install or client acknowledgement as permission to run code.
|
|
@@ -30,9 +30,9 @@ description: 根据任务提供的资料,将赛尔号2精灵、技能、特性
|
|
|
30
30
|
|
|
31
31
|
### 独立 SDK 内容包(默认)
|
|
32
32
|
|
|
33
|
-
不要求主仓库存在。读取项目 manifest、安装的 SDK 参考与邻近示例,以 `data/species`、`data/skills`、`data/marks`、`src/effects.ts`、`locales`、`data/presentations`、`data/resources` 和 `test/*.test.mjs` 组织。进化链共享种族文件,效果按精灵或机制分组;以实际 manifest 为准,不凭空创建 base 专用注册文件。
|
|
33
|
+
不要求主仓库存在。读取项目 manifest、安装的 SDK 参考与邻近示例,以 `data/species`、`data/skills`、`data/marks`、`src/effects/*.effect.ts`、`locales`、`data/presentations`、`data/resources` 和 `test/*.test.mjs` 组织。进化链共享种族文件,效果按精灵或机制分组;以实际 manifest 为准,不凭空创建 base 专用注册文件。
|
|
34
34
|
|
|
35
|
-
使用 `
|
|
35
|
+
使用 SDK 的 `@effect` / `@on` 声明普通效果,复杂参数和绑定通过装饰类的 `static create(context)` 返回 `defineCodeEffect`;通过项目 namespace 和显式引用连接数据。复用外部技能、印记或资源须声明运行时 dependencies,开发工具放 devDependencies。不得修改安装的不可变包、node_modules,或为实验重写加载器。
|
|
36
36
|
|
|
37
37
|
测试使用 `@arcadia-eternity/content-sdk/testing` 的 `prepareContentPack` 和标准依赖装配,不限制只能依赖 base。打包使用 `arcadia-content pack` 或项目对应脚本,检查生成预编译效果工件;在独立安装目录通过标准 `prebuilt-only` 准备验证分发产物。安装与执行准入分开,不能因为装包成功就推定允许执行。
|
|
38
38
|
|
|
@@ -57,7 +57,7 @@ description: 根据任务提供的资料,将赛尔号2精灵、技能、特性
|
|
|
57
57
|
修改主仓库 base 时检查两条注册链(独立包使用自己的 manifest/SDK 注册方式):
|
|
58
58
|
|
|
59
59
|
- 数据:种族文件加入 `pack.json`,分组加入 `content-groups.yaml`;只有本次确实实现的进化关系才登记。
|
|
60
|
-
-
|
|
60
|
+
- 效果:基础包专属实现放进 `src/effects/<pet>.effect.ts`,通过 `@effectGroup` 声明并在静态 `build(context)` 中返回效果表;SDK 自动发现、排序和注册,无需修改中央装载表或 `effects.ts`。技能和印记仍通过稳定效果 ID 引用。普通 UGC 使用 SDK 的 `@effect` / `@on` 和 BehaviorUse。
|
|
61
61
|
|
|
62
62
|
这套结构中,一只精灵的完整实现会跨多个文件,不能只复制种族 YAML 和效果 TS 就视为迁移完成。交付时简要列出新增文件、追加到公共表的定义及注册入口;不要新增写死精灵、技能、印记或效果总数的校验;验证引用完整性、加载一致性和实际行为。文件数量不是目标,不为单只精灵另建一套目录结构。精灵展示沿用现有 icon、portrait、battle(`seer2-swf`、source、fallback)、cry 结构。
|
|
63
63
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
effect,
|
|
3
|
+
on,
|
|
4
|
+
defineCodeEffect,
|
|
5
|
+
numberParam,
|
|
6
|
+
targets,
|
|
7
|
+
ops,
|
|
8
|
+
EffectTrigger,
|
|
9
|
+
AddMarkContext,
|
|
10
|
+
type EffectModuleContext,
|
|
11
|
+
type NativeEffectContext,
|
|
12
|
+
} from '@arcadia-eternity/content-sdk'
|
|
13
|
+
|
|
14
|
+
@effect({ id: 'apply-slow', sourceKind: 'skill' })
|
|
15
|
+
export class ApplySlow {
|
|
16
|
+
@on(EffectTrigger.OnHit)
|
|
17
|
+
static apply(context: NativeEffectContext<EffectTrigger.OnHit>, content: EffectModuleContext) {
|
|
18
|
+
if (context.source !== context.parent.skill) return
|
|
19
|
+
const slow = content.marks.get(content.id('slow'))
|
|
20
|
+
if (!slow) throw new Error('Missing slow mark')
|
|
21
|
+
const target = context.parent.actualTarget
|
|
22
|
+
if (target) target.addMark(new AddMarkContext(context, target, slow))
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@effect({ id: 'speed-penalty', sourceKind: 'petMark' })
|
|
27
|
+
export class SpeedPenalty {
|
|
28
|
+
static create({ id }: EffectModuleContext) {
|
|
29
|
+
return defineCodeEffect({
|
|
30
|
+
id: id('speed-penalty'),
|
|
31
|
+
sourceKind: 'petMark',
|
|
32
|
+
build({ effectId }) {
|
|
33
|
+
// This remains a modifiable battle parameter even though there is no editor parameter form.
|
|
34
|
+
const amount = numberParam({ default: -25, tags: [id('slow-amount')] })
|
|
35
|
+
return {
|
|
36
|
+
id: effectId,
|
|
37
|
+
triggers: [EffectTrigger.OnMarkCreated],
|
|
38
|
+
rebindOnOwnerTransfer: true,
|
|
39
|
+
parameters: { amount },
|
|
40
|
+
apply: targets.ownerPet.apply(
|
|
41
|
+
ops.bindAttribute({
|
|
42
|
+
key: 'speed',
|
|
43
|
+
attribute: 'spe',
|
|
44
|
+
operation: 'delta',
|
|
45
|
+
value: amount.follow({ key: 'amount' }),
|
|
46
|
+
lifetime: 'sourceMark',
|
|
47
|
+
missing: 'detach',
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcadia-eternity/content-sdk",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"types": "./dist/environment-rules.d.mts",
|
|
32
32
|
"import": "./dist/environment-rules.mjs",
|
|
33
33
|
"default": "./dist/environment-rules.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./build": {
|
|
36
|
+
"types": "./dist/effect-build.d.mts",
|
|
37
|
+
"import": "./dist/effect-build.mjs"
|
|
34
38
|
}
|
|
35
39
|
},
|
|
36
40
|
"files": [
|
|
@@ -48,9 +52,9 @@
|
|
|
48
52
|
"write-file-atomic": "^8.0.0",
|
|
49
53
|
"yaml": "2.8.4",
|
|
50
54
|
"zod": "3.25.76",
|
|
51
|
-
"@arcadia-eternity/battle": "4.3.
|
|
52
|
-
"@arcadia-eternity/schema": "4.3.
|
|
53
|
-
"@arcadia-eternity/pack-loader": "4.3.
|
|
55
|
+
"@arcadia-eternity/battle": "4.3.4",
|
|
56
|
+
"@arcadia-eternity/schema": "4.3.4",
|
|
57
|
+
"@arcadia-eternity/pack-loader": "4.3.4"
|
|
54
58
|
},
|
|
55
59
|
"repository": {
|
|
56
60
|
"type": "git",
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { EffectModuleContext } from '@arcadia-eternity/content-sdk'
|
|
2
|
-
|
|
3
|
-
/** The host supplies its SDK and canonical prototypes; importing this file registers nothing globally. */
|
|
4
|
-
export function createEffects({ sdk, marks, id }: EffectModuleContext) {
|
|
5
|
-
const { defineCodeEffect, numberParam, targets, ops, EffectTrigger, AddMarkContext } = sdk
|
|
6
|
-
const slow = marks.get(id('slow'))
|
|
7
|
-
if (!slow) throw new Error('Missing slow mark')
|
|
8
|
-
return [
|
|
9
|
-
defineCodeEffect({
|
|
10
|
-
id: id('apply-slow'),
|
|
11
|
-
sourceKind: 'skill',
|
|
12
|
-
triggers: [EffectTrigger.OnHit],
|
|
13
|
-
when: context => context.source === context.parent.skill,
|
|
14
|
-
apply(context) {
|
|
15
|
-
const target = context.parent.actualTarget
|
|
16
|
-
if (target) target.addMark(new AddMarkContext(context, target, slow))
|
|
17
|
-
},
|
|
18
|
-
}),
|
|
19
|
-
defineCodeEffect({
|
|
20
|
-
id: id('speed-penalty'),
|
|
21
|
-
sourceKind: 'petMark',
|
|
22
|
-
build({ effectId }) {
|
|
23
|
-
// This remains a modifiable battle parameter even though there is no editor parameter form.
|
|
24
|
-
const amount = numberParam({ default: -25, tags: [id('slow-amount')] })
|
|
25
|
-
return {
|
|
26
|
-
id: effectId,
|
|
27
|
-
triggers: [EffectTrigger.OnMarkCreated],
|
|
28
|
-
rebindOnOwnerTransfer: true,
|
|
29
|
-
parameters: { amount },
|
|
30
|
-
apply: targets.ownerPet.apply(
|
|
31
|
-
ops.bindAttribute({
|
|
32
|
-
key: 'speed',
|
|
33
|
-
attribute: 'spe',
|
|
34
|
-
operation: 'delta',
|
|
35
|
-
value: amount.follow({ key: 'amount' }),
|
|
36
|
-
lifetime: 'sourceMark',
|
|
37
|
-
missing: 'detach',
|
|
38
|
-
}),
|
|
39
|
-
),
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
]
|
|
44
|
-
}
|