@nimbus2d/core 0.0.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/dist/index.mjs +18433 -0
- package/package.json +39 -0
- package/src/base/EventEmitter.js +187 -0
- package/src/base/Subsystem.js +183 -0
- package/src/base/index.js +6 -0
- package/src/core/Application/AppState.js +27 -0
- package/src/core/Application/Application.js +480 -0
- package/src/core/Application/DefaultConfig.js +63 -0
- package/src/core/Application/index.js +7 -0
- package/src/core/AssetManager/AssetManager.js +711 -0
- package/src/core/AssetManager/AssetTypes.js +108 -0
- package/src/core/AssetManager/adapters/IResourceAdapter.js +50 -0
- package/src/core/AssetManager/adapters/PixiAdapter.js +90 -0
- package/src/core/AssetManager/core/RefCounter.js +167 -0
- package/src/core/AssetManager/core/ResourceCache.js +281 -0
- package/src/core/AssetManager/core/ResourceEntry.js +191 -0
- package/src/core/AssetManager/core/ResourceEventBus.js +127 -0
- package/src/core/AssetManager/handlers/IResourceHandler.js +45 -0
- package/src/core/AssetManager/index.js +26 -0
- package/src/core/AssetManager/plugins/IResourcePlugin.js +56 -0
- package/src/core/Camera/Camera.js +534 -0
- package/src/core/Camera/CameraTypes.js +59 -0
- package/src/core/Camera/index.js +13 -0
- package/src/core/ConfigSystem/ConfigLayer.js +230 -0
- package/src/core/ConfigSystem/ConfigLayerType.js +31 -0
- package/src/core/ConfigSystem/ConfigMerger.js +50 -0
- package/src/core/ConfigSystem/ConfigPath.js +96 -0
- package/src/core/ConfigSystem/ConfigSystem.js +378 -0
- package/src/core/ConfigSystem/ConfigTypes.js +29 -0
- package/src/core/ConfigSystem/ConfigWatcher.js +84 -0
- package/src/core/ConfigSystem/index.js +19 -0
- package/src/core/EventBus/EventBus.js +797 -0
- package/src/core/EventBus/Interceptor.js +26 -0
- package/src/core/EventBus/PerformanceStats.js +105 -0
- package/src/core/EventBus/index.js +7 -0
- package/src/core/Lifecycle/Lifecycle.js +265 -0
- package/src/core/Lifecycle/LifecycleState.js +31 -0
- package/src/core/Lifecycle/index.js +6 -0
- package/src/core/Logger/ConsoleHandler.js +55 -0
- package/src/core/Logger/LogHandler.js +34 -0
- package/src/core/Logger/LogLevel.js +38 -0
- package/src/core/Logger/Logger.js +234 -0
- package/src/core/Logger/index.js +8 -0
- package/src/core/PluginSystem/Plugin.js +156 -0
- package/src/core/PluginSystem/PluginEntry.js +102 -0
- package/src/core/PluginSystem/PluginState.js +30 -0
- package/src/core/PluginSystem/PluginSystem.js +530 -0
- package/src/core/PluginSystem/index.js +8 -0
- package/src/core/PoolManager/DefaultConfig.js +19 -0
- package/src/core/PoolManager/ObjectPool.js +326 -0
- package/src/core/PoolManager/PoolManager.js +253 -0
- package/src/core/PoolManager/PoolTypes.js +92 -0
- package/src/core/PoolManager/index.js +15 -0
- package/src/core/SceneManager/FadeTransition.js +64 -0
- package/src/core/SceneManager/MaskTransition.js +234 -0
- package/src/core/SceneManager/Scene.js +221 -0
- package/src/core/SceneManager/SceneManager.js +658 -0
- package/src/core/SceneManager/SceneState.js +29 -0
- package/src/core/SceneManager/SlideTransition.js +113 -0
- package/src/core/SceneManager/Transition.js +102 -0
- package/src/core/SceneManager/ZoomTransition.js +119 -0
- package/src/core/SceneManager/index.js +12 -0
- package/src/core/SpriteGPULayer/SpriteGPULayer.js +321 -0
- package/src/core/SpriteGPULayer/SpriteGPULayerTypes.js +49 -0
- package/src/core/SpriteGPULayer/index.js +11 -0
- package/src/core/Timeline/Clip.js +101 -0
- package/src/core/Timeline/DefaultConfig.js +41 -0
- package/src/core/Timeline/Easing.js +176 -0
- package/src/core/Timeline/Timeline.js +458 -0
- package/src/core/Timeline/TimelineTypes.js +89 -0
- package/src/core/Timeline/Track.js +202 -0
- package/src/core/Timeline/index.js +22 -0
- package/src/errors/ConfigError.js +47 -0
- package/src/errors/LifecycleError.js +58 -0
- package/src/errors/NimbusError.js +43 -0
- package/src/errors/PluginError.js +138 -0
- package/src/errors/ResourceError.js +166 -0
- package/src/errors/SceneError.js +124 -0
- package/src/errors/SubsystemError.js +68 -0
- package/src/errors/index.js +53 -0
- package/src/index.js +86 -0
- package/src/types/index.js +141 -0
- package/src/utils/MemoryChecker.js +374 -0
- package/src/utils/Validator.js +60 -0
- package/src/utils/index.js +84 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Nimbus2D - Track 属性轨道
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// 职责:
|
|
5
|
+
// 1. 绑定目标对象 + 属性路径(支持 'position.x' 多级路径)
|
|
6
|
+
// 2. 管理多个 Clip(按 startTime 排序)
|
|
7
|
+
// 3. evaluate(time) 找到当前时间所在的 Clip 并应用属性值
|
|
8
|
+
// 4. 提供 endTime getter 返回轨道总时长
|
|
9
|
+
// 5. 提供 addClip/removeClip/clearClips 管理 Clip
|
|
10
|
+
//
|
|
11
|
+
// 设计决策:
|
|
12
|
+
// - 不继承任何类:Track 是绑定 + 管理的中间层
|
|
13
|
+
// - 属性路径解析:构造时拆分 '.' 一次,避免每帧 split
|
|
14
|
+
// - addClip 后排序:保证 evaluate 时按时间顺序查找(首命中即应用)
|
|
15
|
+
// - evaluate 只应用第一个匹配的 Clip(同时间不叠加),避免属性冲突
|
|
16
|
+
// - 属性设置 try-catch:目标对象被销毁或属性不可写时避免崩溃
|
|
17
|
+
// - destroy 时清空所有引用:避免内存泄漏
|
|
18
|
+
// - 销毁幂等:通过 _isDestroyed 标志避免重复销毁
|
|
19
|
+
//
|
|
20
|
+
// 四期新增(任务 1.6/4.3):Timeline 动画引擎的属性轨道
|
|
21
|
+
// ============================================================================
|
|
22
|
+
|
|
23
|
+
import { Clip } from './Clip.js'
|
|
24
|
+
import { TimelineError } from './TimelineTypes.js'
|
|
25
|
+
|
|
26
|
+
class Track {
|
|
27
|
+
/**
|
|
28
|
+
* 创建属性轨道
|
|
29
|
+
* @param {Object} target - 目标对象(必须非 null/undefined)
|
|
30
|
+
* @param {string} propertyPath - 属性路径(如 'position.x'、'alpha')
|
|
31
|
+
* @throws {TimelineError} 参数校验失败
|
|
32
|
+
*/
|
|
33
|
+
constructor(target, propertyPath) {
|
|
34
|
+
// 校验 target
|
|
35
|
+
if (target === null || target === undefined) {
|
|
36
|
+
throw new TimelineError('Track.target 不可为 null/undefined', 'TRACK_INVALID_TARGET')
|
|
37
|
+
}
|
|
38
|
+
// 校验 propertyPath
|
|
39
|
+
if (typeof propertyPath !== 'string' || propertyPath.length === 0) {
|
|
40
|
+
throw new TimelineError('Track.propertyPath 必须为非空字符串', 'TRACK_INVALID_PATH')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @type {Object} 目标对象 */
|
|
44
|
+
this._target = target
|
|
45
|
+
|
|
46
|
+
/** @type {string} 原始属性路径(保留用于调试) */
|
|
47
|
+
this._propertyPath = propertyPath
|
|
48
|
+
|
|
49
|
+
/** @type {string[]} 属性路径分段(如 ['position', 'x']) */
|
|
50
|
+
this._propertyParts = propertyPath.split('.')
|
|
51
|
+
|
|
52
|
+
/** @type {Clip[]} 动画片段列表(按 startTime 升序) */
|
|
53
|
+
this._clips = []
|
|
54
|
+
|
|
55
|
+
/** @type {boolean} 是否已销毁 */
|
|
56
|
+
this._isDestroyed = false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// --------------------------------------------------------------------------
|
|
60
|
+
// Clip 管理
|
|
61
|
+
// --------------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 添加动画片段
|
|
65
|
+
* @param {Clip} clip - 动画片段
|
|
66
|
+
* @returns {Track} this(链式)
|
|
67
|
+
* @throws {TimelineError} clip 不是 Clip 实例
|
|
68
|
+
*/
|
|
69
|
+
addClip(clip) {
|
|
70
|
+
if (this._isDestroyed) return this
|
|
71
|
+
if (!(clip instanceof Clip)) {
|
|
72
|
+
throw new TimelineError('addClip 参数必须是 Clip 实例', 'TRACK_INVALID_CLIP')
|
|
73
|
+
}
|
|
74
|
+
this._clips.push(clip)
|
|
75
|
+
// 按 startTime 升序排序,保证 evaluate 时首命中即正确片段
|
|
76
|
+
this._clips.sort((a, b) => a.startTime - b.startTime)
|
|
77
|
+
return this
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 移除动画片段
|
|
82
|
+
* @param {Clip} clip - 动画片段
|
|
83
|
+
* @returns {boolean} 是否移除成功
|
|
84
|
+
*/
|
|
85
|
+
removeClip(clip) {
|
|
86
|
+
if (this._isDestroyed) return false
|
|
87
|
+
const index = this._clips.indexOf(clip)
|
|
88
|
+
if (index === -1) return false
|
|
89
|
+
this._clips.splice(index, 1)
|
|
90
|
+
return true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 清空所有动画片段
|
|
95
|
+
*/
|
|
96
|
+
clearClips() {
|
|
97
|
+
if (this._isDestroyed) return
|
|
98
|
+
this._clips.length = 0
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 获取片段数量
|
|
103
|
+
* @returns {number}
|
|
104
|
+
*/
|
|
105
|
+
get clipCount() {
|
|
106
|
+
return this._clips.length
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 获取轨道结束时间(所有 Clip 中最晚的 endTime)
|
|
111
|
+
* @returns {number}
|
|
112
|
+
*/
|
|
113
|
+
get endTime() {
|
|
114
|
+
if (this._clips.length === 0) return 0
|
|
115
|
+
let max = 0
|
|
116
|
+
for (const clip of this._clips) {
|
|
117
|
+
const end = clip.endTime
|
|
118
|
+
if (end > max) max = end
|
|
119
|
+
}
|
|
120
|
+
return max
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// --------------------------------------------------------------------------
|
|
124
|
+
// 评估
|
|
125
|
+
// --------------------------------------------------------------------------
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 评估轨道在指定时间的值并应用到目标属性
|
|
129
|
+
* @param {number} time - 当前时间(秒)
|
|
130
|
+
*/
|
|
131
|
+
evaluate(time) {
|
|
132
|
+
// 已销毁或无片段:不应用
|
|
133
|
+
if (this._isDestroyed || this._clips.length === 0) return
|
|
134
|
+
// 校验 time 是否为有效数字(防御 NaN/非数字输入导致不必要的循环遍历)
|
|
135
|
+
// NaN 时所有 clip 的比较都会返回 false,循环无意义,提前返回提升性能
|
|
136
|
+
if (typeof time !== 'number' || Number.isNaN(time)) return
|
|
137
|
+
|
|
138
|
+
// 查找当前时间所在的 Clip(首个 startTime <= time < endTime 的 Clip)
|
|
139
|
+
for (const clip of this._clips) {
|
|
140
|
+
if (time >= clip.startTime && time < clip.endTime) {
|
|
141
|
+
// 计算本地进度
|
|
142
|
+
const localTime = time - clip.startTime
|
|
143
|
+
const progress = localTime / clip.duration
|
|
144
|
+
// 应用缓动插值
|
|
145
|
+
const value = clip.evaluate(progress)
|
|
146
|
+
// 写入目标属性
|
|
147
|
+
this._setPropertyValue(value)
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 边界处理:time 超过最后一个 Clip 的 endTime 时,应用最终值
|
|
153
|
+
// 场景:seek(duration) 或 _complete() 时 time = duration = 最后一个 Clip 的 endTime
|
|
154
|
+
// 此时半开区间 [startTime, endTime) 不匹配,需要显式应用最终值
|
|
155
|
+
// 确保动画结束后目标属性保持最终值(而非上一帧的中间值)
|
|
156
|
+
const lastClip = this._clips[this._clips.length - 1]
|
|
157
|
+
if (time >= lastClip.endTime) {
|
|
158
|
+
this._setPropertyValue(lastClip.to)
|
|
159
|
+
}
|
|
160
|
+
// 其他情况(time 在 Clip 间隔中):不修改属性,保持上一帧值
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 设置目标属性值(带属性路径解析)
|
|
165
|
+
* @param {*} value - 值
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
_setPropertyValue(value) {
|
|
169
|
+
try {
|
|
170
|
+
let obj = this._target
|
|
171
|
+
// 遍历到倒数第二级
|
|
172
|
+
for (let i = 0; i < this._propertyParts.length - 1; i++) {
|
|
173
|
+
obj = obj[this._propertyParts[i]]
|
|
174
|
+
// 中间属性为 null/undefined:无法继续访问,直接返回
|
|
175
|
+
if (obj === null || obj === undefined) return
|
|
176
|
+
}
|
|
177
|
+
// 设置最后一级属性
|
|
178
|
+
const lastKey = this._propertyParts[this._propertyParts.length - 1]
|
|
179
|
+
obj[lastKey] = value
|
|
180
|
+
} catch (e) {
|
|
181
|
+
// 目标对象被销毁或属性不可写:忽略,避免崩溃
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// --------------------------------------------------------------------------
|
|
186
|
+
// 销毁
|
|
187
|
+
// --------------------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 销毁轨道(幂等,可重复调用)
|
|
191
|
+
* 清空所有 Clip 引用 + 目标对象引用,避免内存泄漏
|
|
192
|
+
*/
|
|
193
|
+
destroy() {
|
|
194
|
+
if (this._isDestroyed) return
|
|
195
|
+
this._isDestroyed = true
|
|
196
|
+
this._clips.length = 0
|
|
197
|
+
this._target = null
|
|
198
|
+
this._propertyParts.length = 0
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { Track }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Nimbus2D - Timeline 模块统一导出
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// 导出 Timeline 动画引擎的公开 API:
|
|
5
|
+
// - Timeline:时间线主类
|
|
6
|
+
// - Track:属性轨道
|
|
7
|
+
// - Clip:动画片段
|
|
8
|
+
// - Easing:缓动函数库
|
|
9
|
+
// - BUILTIN_EASINGS:内置缓动函数表(只读)
|
|
10
|
+
// - TimelineEventType/TimelineState:枚举
|
|
11
|
+
// - TimelineError:错误类
|
|
12
|
+
// - TimelineDefaultConfig:默认配置
|
|
13
|
+
//
|
|
14
|
+
// 四期新增(任务 1.6/4.5):Timeline 模块入口
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
export { Timeline } from './Timeline.js'
|
|
18
|
+
export { Track } from './Track.js'
|
|
19
|
+
export { Clip } from './Clip.js'
|
|
20
|
+
export { Easing, BUILTIN_EASINGS } from './Easing.js'
|
|
21
|
+
export { TimelineEventType, TimelineState, TimelineError } from './TimelineTypes.js'
|
|
22
|
+
export { TimelineDefaultConfig } from './DefaultConfig.js'
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Nimbus2D - 配置系统错误类
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// 包含 ConfigError 和 ConfigPathError
|
|
5
|
+
// ============================================================================
|
|
6
|
+
|
|
7
|
+
import { NimbusError } from './NimbusError.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 配置系统错误基类
|
|
11
|
+
* @extends NimbusError
|
|
12
|
+
*/
|
|
13
|
+
class ConfigError extends NimbusError {
|
|
14
|
+
/**
|
|
15
|
+
* 构造函数
|
|
16
|
+
* @param {string} message - 错误消息
|
|
17
|
+
* @param {string} [code='CONFIG_ERROR'] - 错误码
|
|
18
|
+
* @param {Error|null} [cause=null] - 原始错误
|
|
19
|
+
*/
|
|
20
|
+
constructor(message, code = 'CONFIG_ERROR', cause = null) {
|
|
21
|
+
super(message, code, 'ConfigSystem', cause)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 配置路径错误
|
|
27
|
+
* 配置路径无效或不存在时抛出
|
|
28
|
+
* @extends ConfigError
|
|
29
|
+
*/
|
|
30
|
+
class ConfigPathError extends ConfigError {
|
|
31
|
+
/**
|
|
32
|
+
* 构造函数
|
|
33
|
+
* @param {string} path - 无效的配置路径
|
|
34
|
+
*/
|
|
35
|
+
constructor(path) {
|
|
36
|
+
super(`配置路径无效:${path}`, 'CONFIG_PATH_ERROR')
|
|
37
|
+
/** @type {string} 无效的配置路径 */
|
|
38
|
+
this._path = path
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @type {string} 无效的配置路径 */
|
|
42
|
+
get path() {
|
|
43
|
+
return this._path
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { ConfigError, ConfigPathError }
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Nimbus2D - 生命周期错误类
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// 包含 LifecycleError 和 LifecycleStateError
|
|
5
|
+
// ============================================================================
|
|
6
|
+
|
|
7
|
+
import { NimbusError } from './NimbusError.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 生命周期错误基类
|
|
11
|
+
* @extends NimbusError
|
|
12
|
+
*/
|
|
13
|
+
class LifecycleError extends NimbusError {
|
|
14
|
+
/**
|
|
15
|
+
* 构造函数
|
|
16
|
+
* @param {string} message - 错误消息
|
|
17
|
+
* @param {string} [code='LIFECYCLE_ERROR'] - 错误码
|
|
18
|
+
* @param {Error|null} [cause=null] - 原始错误
|
|
19
|
+
*/
|
|
20
|
+
constructor(message, code = 'LIFECYCLE_ERROR', cause = null) {
|
|
21
|
+
super(message, code, 'Lifecycle', cause)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 生命周期状态错误
|
|
27
|
+
* Lifecycle 状态转换不合法时抛出
|
|
28
|
+
* @extends LifecycleError
|
|
29
|
+
*/
|
|
30
|
+
class LifecycleStateError extends LifecycleError {
|
|
31
|
+
/**
|
|
32
|
+
* 构造函数
|
|
33
|
+
* @param {string} currentState - 当前状态
|
|
34
|
+
* @param {string[]} expectedStates - 期望状态列表
|
|
35
|
+
*/
|
|
36
|
+
constructor(currentState, expectedStates) {
|
|
37
|
+
super(
|
|
38
|
+
`生命周期状态错误:当前 ${currentState},期望 ${expectedStates.join(' 或 ')}`,
|
|
39
|
+
'LIFECYCLE_STATE'
|
|
40
|
+
)
|
|
41
|
+
/** @type {string} 当前状态 */
|
|
42
|
+
this._currentState = currentState
|
|
43
|
+
/** @type {string[]} 期望状态列表 */
|
|
44
|
+
this._expectedStates = expectedStates
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @type {string} 当前状态 */
|
|
48
|
+
get currentState() {
|
|
49
|
+
return this._currentState
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @type {string[]} 期望状态列表 */
|
|
53
|
+
get expectedStates() {
|
|
54
|
+
return this._expectedStates
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { LifecycleError, LifecycleStateError }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Nimbus2D - 错误基类
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// 所有 Nimbus2D 错误的基类,附加 code、module、cause 字段
|
|
5
|
+
//
|
|
6
|
+
// 设计决策:
|
|
7
|
+
// - 不重写 Error.name(文档 §11.5),使用专属 getter 获取模块信息
|
|
8
|
+
// - 构造函数使用位置参数:constructor(message, code, module, cause)
|
|
9
|
+
// - code 默认 'NIMBUS_ERROR',module 默认 'unknown'
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Nimbus2D 错误基类
|
|
14
|
+
* @extends Error
|
|
15
|
+
*/
|
|
16
|
+
class NimbusError extends Error {
|
|
17
|
+
/**
|
|
18
|
+
* 构造函数
|
|
19
|
+
* @param {string} message - 错误信息
|
|
20
|
+
* @param {string} [code='NIMBUS_ERROR'] - 错误码
|
|
21
|
+
* @param {string} [module='unknown'] - 所属模块名
|
|
22
|
+
* @param {Error|null} [cause=null] - 原始错误
|
|
23
|
+
*/
|
|
24
|
+
constructor(message, code = 'NIMBUS_ERROR', module = 'unknown', cause = null) {
|
|
25
|
+
super(message)
|
|
26
|
+
/** @type {string} 错误码 */
|
|
27
|
+
this.code = code
|
|
28
|
+
/** @type {string} 所属模块名 */
|
|
29
|
+
this.module = module
|
|
30
|
+
/** @type {Error|null} 原始错误 */
|
|
31
|
+
this.cause = cause
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 转换为字符串(含错误码和模块信息)
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
toString() {
|
|
39
|
+
return `[${this.module}:${this.code}] ${this.message}`
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { NimbusError }
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Nimbus2D - 插件系统错误类
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// 包含 PluginError、PluginNotFoundError、PluginDuplicateError、
|
|
5
|
+
// PluginDependencyError、PluginStateError
|
|
6
|
+
// 注意:使用 pluginName getter(不重写 Error.name)
|
|
7
|
+
// ============================================================================
|
|
8
|
+
|
|
9
|
+
import { NimbusError } from './NimbusError.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 插件系统错误基类
|
|
13
|
+
* @extends NimbusError
|
|
14
|
+
*/
|
|
15
|
+
class PluginError extends NimbusError {
|
|
16
|
+
/**
|
|
17
|
+
* 构造函数
|
|
18
|
+
* @param {string} message - 错误消息
|
|
19
|
+
* @param {string} [code='PLUGIN_ERROR'] - 错误码
|
|
20
|
+
* @param {Error|null} [cause=null] - 原始错误
|
|
21
|
+
*/
|
|
22
|
+
constructor(message, code = 'PLUGIN_ERROR', cause = null) {
|
|
23
|
+
super(message, code, 'PluginSystem', cause)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 插件未找到错误
|
|
29
|
+
* @extends PluginError
|
|
30
|
+
*/
|
|
31
|
+
class PluginNotFoundError extends PluginError {
|
|
32
|
+
/**
|
|
33
|
+
* 构造函数
|
|
34
|
+
* @param {string} pluginName - 插件名称
|
|
35
|
+
*/
|
|
36
|
+
constructor(pluginName) {
|
|
37
|
+
super(`插件未找到:${pluginName}`, 'PLUGIN_NOT_FOUND')
|
|
38
|
+
/** @type {string} 插件名称 */
|
|
39
|
+
this._pluginName = pluginName
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @type {string} 插件名称 */
|
|
43
|
+
get pluginName() {
|
|
44
|
+
return this._pluginName
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 插件重复注册错误
|
|
50
|
+
* @extends PluginError
|
|
51
|
+
*/
|
|
52
|
+
class PluginDuplicateError extends PluginError {
|
|
53
|
+
/**
|
|
54
|
+
* 构造函数
|
|
55
|
+
* @param {string} pluginName - 插件名称
|
|
56
|
+
*/
|
|
57
|
+
constructor(pluginName) {
|
|
58
|
+
super(`插件重复注册:${pluginName}`, 'PLUGIN_DUPLICATE')
|
|
59
|
+
/** @type {string} 插件名称 */
|
|
60
|
+
this._pluginName = pluginName
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @type {string} 插件名称 */
|
|
64
|
+
get pluginName() {
|
|
65
|
+
return this._pluginName
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 插件依赖未满足错误
|
|
71
|
+
* @extends PluginError
|
|
72
|
+
*/
|
|
73
|
+
class PluginDependencyError extends PluginError {
|
|
74
|
+
/**
|
|
75
|
+
* 构造函数
|
|
76
|
+
* @param {string} pluginName - 插件名称
|
|
77
|
+
* @param {string} reason - 依赖未满足原因
|
|
78
|
+
*/
|
|
79
|
+
constructor(pluginName, reason) {
|
|
80
|
+
super(`插件 ${pluginName} 依赖未满足:${reason}`, 'PLUGIN_DEPENDENCY')
|
|
81
|
+
/** @type {string} 插件名称 */
|
|
82
|
+
this._pluginName = pluginName
|
|
83
|
+
/** @type {string} 依赖未满足原因 */
|
|
84
|
+
this._reason = reason
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @type {string} 插件名称 */
|
|
88
|
+
get pluginName() {
|
|
89
|
+
return this._pluginName
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @type {string} 依赖未满足原因 */
|
|
93
|
+
get reason() {
|
|
94
|
+
return this._reason
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 插件状态错误
|
|
100
|
+
* @extends PluginError
|
|
101
|
+
*/
|
|
102
|
+
class PluginStateError extends PluginError {
|
|
103
|
+
/**
|
|
104
|
+
* 构造函数
|
|
105
|
+
* @param {string} pluginName - 插件名称
|
|
106
|
+
* @param {string} currentState - 当前状态
|
|
107
|
+
* @param {string} expectedState - 期望状态
|
|
108
|
+
*/
|
|
109
|
+
constructor(pluginName, currentState, expectedState) {
|
|
110
|
+
super(
|
|
111
|
+
`插件 ${pluginName} 状态错误:当前 ${currentState},期望 ${expectedState}`,
|
|
112
|
+
'PLUGIN_STATE'
|
|
113
|
+
)
|
|
114
|
+
/** @type {string} 插件名称 */
|
|
115
|
+
this._pluginName = pluginName
|
|
116
|
+
/** @type {string} 当前状态 */
|
|
117
|
+
this._currentState = currentState
|
|
118
|
+
/** @type {string} 期望状态 */
|
|
119
|
+
this._expectedState = expectedState
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** @type {string} 插件名称 */
|
|
123
|
+
get pluginName() {
|
|
124
|
+
return this._pluginName
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** @type {string} 当前状态 */
|
|
128
|
+
get currentState() {
|
|
129
|
+
return this._currentState
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** @type {string} 期望状态 */
|
|
133
|
+
get expectedState() {
|
|
134
|
+
return this._expectedState
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { PluginError, PluginNotFoundError, PluginDuplicateError, PluginDependencyError, PluginStateError }
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Nimbus2D - 资源系统错误类
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// 包含 ResourceError、ResourceNotFoundError、ResourceDuplicateError、
|
|
5
|
+
// ResourceStateError、ResourceLoadError、AdapterError、ResourceDestroyedError
|
|
6
|
+
// ============================================================================
|
|
7
|
+
|
|
8
|
+
import { NimbusError } from './NimbusError.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 资源系统错误基类
|
|
12
|
+
* @extends NimbusError
|
|
13
|
+
*/
|
|
14
|
+
class ResourceError extends NimbusError {
|
|
15
|
+
/**
|
|
16
|
+
* 构造函数
|
|
17
|
+
* @param {string} message - 错误消息
|
|
18
|
+
* @param {string} [code='RESOURCE_ERROR'] - 错误码
|
|
19
|
+
* @param {Error|null} [cause=null] - 原始错误
|
|
20
|
+
*/
|
|
21
|
+
constructor(message, code = 'RESOURCE_ERROR', cause = null) {
|
|
22
|
+
super(message, code, 'AssetManager', cause)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 资源未找到错误
|
|
28
|
+
* @extends ResourceError
|
|
29
|
+
*/
|
|
30
|
+
class ResourceNotFoundError extends ResourceError {
|
|
31
|
+
/**
|
|
32
|
+
* 构造函数
|
|
33
|
+
* @param {string} resourceId - 资源 ID
|
|
34
|
+
*/
|
|
35
|
+
constructor(resourceId) {
|
|
36
|
+
super(`资源未找到:${resourceId}`, 'RESOURCE_NOT_FOUND')
|
|
37
|
+
/** @type {string} 资源 ID */
|
|
38
|
+
this._resourceId = resourceId
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @type {string} 资源 ID */
|
|
42
|
+
get resourceId() {
|
|
43
|
+
return this._resourceId
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 资源重复注册错误
|
|
49
|
+
* @extends ResourceError
|
|
50
|
+
*/
|
|
51
|
+
class ResourceDuplicateError extends ResourceError {
|
|
52
|
+
/**
|
|
53
|
+
* 构造函数
|
|
54
|
+
* @param {string} resourceId - 资源 ID
|
|
55
|
+
*/
|
|
56
|
+
constructor(resourceId) {
|
|
57
|
+
super(`资源重复注册:${resourceId}`, 'RESOURCE_DUPLICATE')
|
|
58
|
+
/** @type {string} 资源 ID */
|
|
59
|
+
this._resourceId = resourceId
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @type {string} 资源 ID */
|
|
63
|
+
get resourceId() {
|
|
64
|
+
return this._resourceId
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 资源状态错误
|
|
70
|
+
* @extends ResourceError
|
|
71
|
+
*/
|
|
72
|
+
class ResourceStateError extends ResourceError {
|
|
73
|
+
/**
|
|
74
|
+
* 构造函数
|
|
75
|
+
* @param {string} resourceId - 资源 ID
|
|
76
|
+
* @param {string} currentState - 当前状态
|
|
77
|
+
* @param {string} expectedState - 期望状态
|
|
78
|
+
*/
|
|
79
|
+
constructor(resourceId, currentState, expectedState) {
|
|
80
|
+
super(
|
|
81
|
+
`资源 ${resourceId} 状态错误:当前 ${currentState},期望 ${expectedState}`,
|
|
82
|
+
'RESOURCE_STATE'
|
|
83
|
+
)
|
|
84
|
+
/** @type {string} 资源 ID */
|
|
85
|
+
this._resourceId = resourceId
|
|
86
|
+
/** @type {string} 当前状态 */
|
|
87
|
+
this._currentState = currentState
|
|
88
|
+
/** @type {string} 期望状态 */
|
|
89
|
+
this._expectedState = expectedState
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @type {string} 资源 ID */
|
|
93
|
+
get resourceId() {
|
|
94
|
+
return this._resourceId
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @type {string} 当前状态 */
|
|
98
|
+
get currentState() {
|
|
99
|
+
return this._currentState
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @type {string} 期望状态 */
|
|
103
|
+
get expectedState() {
|
|
104
|
+
return this._expectedState
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 资源加载失败错误
|
|
110
|
+
* @extends ResourceError
|
|
111
|
+
*/
|
|
112
|
+
class ResourceLoadError extends ResourceError {
|
|
113
|
+
/**
|
|
114
|
+
* 构造函数
|
|
115
|
+
* @param {string} resourceId - 资源 ID
|
|
116
|
+
* @param {Error} cause - 原始错误
|
|
117
|
+
*/
|
|
118
|
+
constructor(resourceId, cause) {
|
|
119
|
+
super(`资源加载失败:${resourceId}`, 'RESOURCE_LOAD', cause)
|
|
120
|
+
/** @type {string} 资源 ID */
|
|
121
|
+
this._resourceId = resourceId
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** @type {string} 资源 ID */
|
|
125
|
+
get resourceId() {
|
|
126
|
+
return this._resourceId
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 适配器错误
|
|
132
|
+
* @extends ResourceError
|
|
133
|
+
*/
|
|
134
|
+
class AdapterError extends ResourceError {
|
|
135
|
+
/**
|
|
136
|
+
* 构造函数
|
|
137
|
+
* @param {string} message - 错误消息
|
|
138
|
+
* @param {Error|null} [cause=null] - 原始错误
|
|
139
|
+
*/
|
|
140
|
+
constructor(message, cause = null) {
|
|
141
|
+
super(message, 'ADAPTER_ERROR', cause)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 资源系统已销毁错误
|
|
147
|
+
* @extends ResourceError
|
|
148
|
+
*/
|
|
149
|
+
class ResourceDestroyedError extends ResourceError {
|
|
150
|
+
/**
|
|
151
|
+
* 构造函数
|
|
152
|
+
*/
|
|
153
|
+
constructor() {
|
|
154
|
+
super('资源系统已销毁', 'RESOURCE_DESTROYED')
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export {
|
|
159
|
+
ResourceError,
|
|
160
|
+
ResourceNotFoundError,
|
|
161
|
+
ResourceDuplicateError,
|
|
162
|
+
ResourceStateError,
|
|
163
|
+
ResourceLoadError,
|
|
164
|
+
AdapterError,
|
|
165
|
+
ResourceDestroyedError
|
|
166
|
+
}
|