@mclawnet/agent 0.6.20 → 0.6.22

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.
Files changed (99) hide show
  1. package/cli.js +63 -0
  2. package/dist/__tests__/checkpoint.test.d.ts +2 -0
  3. package/dist/__tests__/checkpoint.test.d.ts.map +1 -0
  4. package/dist/__tests__/fs-handler-decode.test.d.ts +2 -0
  5. package/dist/__tests__/fs-handler-decode.test.d.ts.map +1 -0
  6. package/dist/__tests__/idle-sweeper.test.d.ts +2 -0
  7. package/dist/__tests__/idle-sweeper.test.d.ts.map +1 -0
  8. package/dist/__tests__/mcp-config.test.d.ts +2 -0
  9. package/dist/__tests__/mcp-config.test.d.ts.map +1 -0
  10. package/dist/__tests__/schedule-runtime-spawn.test.d.ts +2 -0
  11. package/dist/__tests__/schedule-runtime-spawn.test.d.ts.map +1 -0
  12. package/dist/__tests__/schedule-runtime.test.d.ts +2 -0
  13. package/dist/__tests__/schedule-runtime.test.d.ts.map +1 -0
  14. package/dist/__tests__/session-limit.test.d.ts +2 -0
  15. package/dist/__tests__/session-limit.test.d.ts.map +1 -0
  16. package/dist/__tests__/swarm-cli-client.test.d.ts +2 -0
  17. package/dist/__tests__/swarm-cli-client.test.d.ts.map +1 -0
  18. package/dist/__tests__/swarm-control-dispatch.test.d.ts +2 -0
  19. package/dist/__tests__/swarm-control-dispatch.test.d.ts.map +1 -0
  20. package/dist/__tests__/swarm-session-bridge.test.d.ts +2 -0
  21. package/dist/__tests__/swarm-session-bridge.test.d.ts.map +1 -0
  22. package/dist/backend-adapter.d.ts +43 -0
  23. package/dist/backend-adapter.d.ts.map +1 -1
  24. package/dist/checkpoint.d.ts +67 -0
  25. package/dist/checkpoint.d.ts.map +1 -0
  26. package/dist/{chunk-RIK7IXSW.js → chunk-WJWCYGLQ.js} +1130 -147
  27. package/dist/chunk-WJWCYGLQ.js.map +1 -0
  28. package/dist/errors.d.ts +40 -0
  29. package/dist/errors.d.ts.map +1 -0
  30. package/dist/fs-handler.d.ts.map +1 -1
  31. package/dist/hub-connection.d.ts +13 -0
  32. package/dist/hub-connection.d.ts.map +1 -1
  33. package/dist/index.js +1 -1
  34. package/dist/schedule-runtime.d.ts +125 -0
  35. package/dist/schedule-runtime.d.ts.map +1 -0
  36. package/dist/session-manager.d.ts +102 -0
  37. package/dist/session-manager.d.ts.map +1 -1
  38. package/dist/skill-loader.d.ts +20 -0
  39. package/dist/skill-loader.d.ts.map +1 -1
  40. package/dist/start.d.ts +2 -0
  41. package/dist/start.d.ts.map +1 -1
  42. package/dist/start.js +1 -1
  43. package/dist/swarm-cli-client.d.ts +24 -0
  44. package/dist/swarm-cli-client.d.ts.map +1 -0
  45. package/dist/swarm-cli-client.js +83 -0
  46. package/dist/swarm-cli-client.js.map +1 -0
  47. package/dist/swarm-control-dispatch.d.ts +47 -0
  48. package/dist/swarm-control-dispatch.d.ts.map +1 -0
  49. package/dist/swarm-session-bridge.d.ts +22 -0
  50. package/dist/swarm-session-bridge.d.ts.map +1 -0
  51. package/package.json +6 -4
  52. package/skills/cocos-creator-3x-cn/SKILL.md +475 -0
  53. package/skills/cocos-creator-3x-cn/references/framework/asset-management.md +322 -0
  54. package/skills/cocos-creator-3x-cn/references/framework/component-system.md +348 -0
  55. package/skills/cocos-creator-3x-cn/references/framework/event-patterns.md +410 -0
  56. package/skills/cocos-creator-3x-cn/references/framework/playable-optimization.md +257 -0
  57. package/skills/cocos-creator-3x-cn/references/language/performance.md +363 -0
  58. package/skills/cocos-creator-3x-cn/references/language/quality-hygiene.md +307 -0
  59. package/skills/cocos-creator-3x-cn/references/review/architecture-review.md +183 -0
  60. package/skills/cocos-creator-3x-cn/references/review/quality-review.md +251 -0
  61. package/skills/cocos-performance-optimizer/SKILL.md +214 -0
  62. package/skills/game-development/2d-games/SKILL.md +129 -0
  63. package/skills/game-development/3d-games/SKILL.md +145 -0
  64. package/skills/game-development/SKILL.md +175 -0
  65. package/skills/game-development/game-art/SKILL.md +195 -0
  66. package/skills/game-development/game-audio/SKILL.md +200 -0
  67. package/skills/game-development/game-design/SKILL.md +139 -0
  68. package/skills/game-development/mobile-games/SKILL.md +118 -0
  69. package/skills/game-development/multiplayer/SKILL.md +142 -0
  70. package/skills/game-development/pc-games/SKILL.md +154 -0
  71. package/skills/game-development/vr-ar/SKILL.md +133 -0
  72. package/skills/game-development/web-games/SKILL.md +160 -0
  73. package/skills/game-engine/SKILL.md +140 -0
  74. package/skills/game-engine/assets/2d-maze-game.md +528 -0
  75. package/skills/game-engine/assets/2d-platform-game.md +1855 -0
  76. package/skills/game-engine/assets/gameBase-template-repo.md +310 -0
  77. package/skills/game-engine/assets/paddle-game-template.md +1528 -0
  78. package/skills/game-engine/assets/simple-2d-engine.md +507 -0
  79. package/skills/game-engine/references/3d-web-games.md +754 -0
  80. package/skills/game-engine/references/algorithms.md +843 -0
  81. package/skills/game-engine/references/basics.md +343 -0
  82. package/skills/game-engine/references/game-control-mechanisms.md +617 -0
  83. package/skills/game-engine/references/game-engine-core-principles.md +695 -0
  84. package/skills/game-engine/references/game-publishing.md +352 -0
  85. package/skills/game-engine/references/techniques.md +894 -0
  86. package/skills/game-engine/references/terminology.md +354 -0
  87. package/skills/game-engine/references/web-apis.md +1394 -0
  88. package/skills/theone-cocos-standards/SKILL.md +557 -0
  89. package/skills/theone-cocos-standards/references/framework/component-system.md +645 -0
  90. package/skills/theone-cocos-standards/references/framework/event-patterns.md +433 -0
  91. package/skills/theone-cocos-standards/references/framework/playable-optimization.md +429 -0
  92. package/skills/theone-cocos-standards/references/framework/size-optimization.md +308 -0
  93. package/skills/theone-cocos-standards/references/language/modern-typescript.md +658 -0
  94. package/skills/theone-cocos-standards/references/language/performance.md +580 -0
  95. package/skills/theone-cocos-standards/references/language/quality-hygiene.md +582 -0
  96. package/skills/theone-cocos-standards/references/review/architecture-review.md +250 -0
  97. package/skills/theone-cocos-standards/references/review/performance-review.md +288 -0
  98. package/skills/theone-cocos-standards/references/review/quality-review.md +239 -0
  99. package/dist/chunk-RIK7IXSW.js.map +0 -1
@@ -0,0 +1,557 @@
1
+ ---
2
+ name: theone-cocos-standards
3
+ description: Enforces TheOne Studio Cocos Creator development standards including TypeScript coding patterns, Cocos Creator 3.x architecture (Component system, EventDispatcher), and playable ads optimization guidelines. Triggers when writing, reviewing, or refactoring Cocos TypeScript code, implementing playable ads features, optimizing performance/bundle size, or reviewing code changes.
4
+ version: 1.0.0
5
+ ---
6
+
7
+ # TheOne Studio Cocos Creator Development Standards
8
+
9
+ ⚠️ **Cocos Creator 3.x (TypeScript 4.1+):** All patterns and examples are compatible with Cocos Creator 3.x playable ads development.
10
+
11
+ ## Skill Purpose
12
+
13
+ This skill enforces TheOne Studio's comprehensive Cocos Creator development standards with **CODE QUALITY FIRST**:
14
+
15
+ **Priority 1: Code Quality & Hygiene** (MOST IMPORTANT)
16
+ - TypeScript strict mode, ESLint configuration, access modifiers (public/private/protected)
17
+ - Throw exceptions (never silent errors)
18
+ - console.log for development, remove in production builds
19
+ - readonly for immutable fields, const for constants
20
+ - No inline comments (use descriptive names)
21
+ - Proper error handling and type safety
22
+
23
+ **Priority 2: Modern TypeScript Patterns**
24
+ - Array methods (map/filter/reduce) over loops
25
+ - Arrow functions, destructuring, spread operators
26
+ - Optional chaining, nullish coalescing
27
+ - Type guards, utility types (Partial, Required, Readonly)
28
+ - Modern TypeScript features
29
+
30
+ **Priority 3: Cocos Creator Architecture**
31
+ - Component-based Entity-Component (EC) system
32
+ - Lifecycle methods: onLoad→start→onEnable→update→onDisable→onDestroy
33
+ - EventDispatcher pattern for custom events
34
+ - Node event system (EventTouch, keyboard events)
35
+ - Resource management and pooling for playables
36
+
37
+ **Priority 4: Playable Ads Performance**
38
+ - DrawCall batching (<10 DrawCalls target)
39
+ - Sprite atlas configuration (auto-atlas enabled)
40
+ - GPU skinning for skeletal animations
41
+ - Zero allocations in update() loop
42
+ - Bundle size <5MB (texture compression, code minification)
43
+
44
+ ## When This Skill Triggers
45
+
46
+ - Writing or refactoring Cocos Creator TypeScript code
47
+ - Implementing playable ads features
48
+ - Working with component lifecycle and events
49
+ - Optimizing performance for playable ads
50
+ - Reviewing code changes or pull requests
51
+ - Setting up playable project architecture
52
+ - Reducing bundle size or DrawCall counts
53
+
54
+ ## Quick Reference Guide
55
+
56
+ ### What Do You Need Help With?
57
+
58
+ | Priority | Task | Reference |
59
+ |----------|------|-----------|
60
+ | **🔴 PRIORITY 1: Code Quality (Check FIRST)** | | |
61
+ | 1 | TypeScript strict mode, ESLint, access modifiers | [Quality & Hygiene](references/language/quality-hygiene.md) ⭐ |
62
+ | 1 | Throw exceptions, proper error handling | [Quality & Hygiene](references/language/quality-hygiene.md) ⭐ |
63
+ | 1 | console.log (development only), remove in production | [Quality & Hygiene](references/language/quality-hygiene.md) ⭐ |
64
+ | 1 | readonly/const, no inline comments, descriptive names | [Quality & Hygiene](references/language/quality-hygiene.md) ⭐ |
65
+ | **🟡 PRIORITY 2: Modern TypeScript Patterns** | | |
66
+ | 2 | Array methods, arrow functions, destructuring | [Modern TypeScript](references/language/modern-typescript.md) |
67
+ | 2 | Optional chaining, nullish coalescing | [Modern TypeScript](references/language/modern-typescript.md) |
68
+ | 2 | Type guards, utility types | [Modern TypeScript](references/language/modern-typescript.md) |
69
+ | **🟢 PRIORITY 3: Cocos Architecture** | | |
70
+ | 3 | Component system, @property decorator | [Component System](references/framework/component-system.md) |
71
+ | 3 | Lifecycle methods (onLoad→start→update→onDestroy) | [Component System](references/framework/component-system.md) |
72
+ | 3 | EventDispatcher, Node events, cleanup | [Event Patterns](references/framework/event-patterns.md) |
73
+ | 3 | Resource loading, pooling, memory management | [Playable Optimization](references/framework/playable-optimization.md) |
74
+ | **🔵 PRIORITY 4: Performance & Review** | | |
75
+ | 4 | DrawCall batching, sprite atlas, GPU skinning | [Playable Optimization](references/framework/playable-optimization.md) |
76
+ | 4 | Update loop optimization, zero allocations | [Performance](references/language/performance.md) |
77
+ | 4 | Bundle size reduction (<5MB target) | [Size Optimization](references/framework/size-optimization.md) |
78
+ | 4 | Architecture review (components, lifecycle, events) | [Architecture Review](references/review/architecture-review.md) |
79
+ | 4 | TypeScript quality review | [Quality Review](references/review/quality-review.md) |
80
+ | 4 | Performance review (DrawCalls, allocations) | [Performance Review](references/review/performance-review.md) |
81
+
82
+ ## 🔴 CRITICAL: Code Quality Rules (CHECK FIRST!)
83
+
84
+ ### ⚠️ MANDATORY QUALITY STANDARDS
85
+
86
+ **ALWAYS enforce these BEFORE writing any code:**
87
+
88
+ 1. **Enable TypeScript strict mode** - "strict": true in tsconfig.json
89
+ 2. **Use ESLint configuration** - @typescript-eslint rules enabled
90
+ 3. **Use access modifiers** - public/private/protected on all members
91
+ 4. **Throw exceptions for errors** - NEVER silent failures or undefined returns
92
+ 5. **console.log for development only** - Remove all console statements in production builds
93
+ 6. **Use readonly for immutable fields** - Mark fields that aren't reassigned
94
+ 7. **Use const for constants** - Constants should be const, not let
95
+ 8. **No inline comments** - Use descriptive names; code should be self-explanatory
96
+ 9. **Proper null/undefined handling** - Use optional chaining and nullish coalescing
97
+ 10. **Type safety** - Avoid `any` type, use proper types and interfaces
98
+
99
+ **Example: Enforce Quality First**
100
+
101
+ ```typescript
102
+ // ✅ EXCELLENT: All quality rules enforced
103
+ import { _decorator, Component, Node, EventTouch } from 'cc';
104
+ const { ccclass, property } = _decorator;
105
+
106
+ @ccclass('PlayerController')
107
+ export class PlayerController extends Component {
108
+ // 3. Access modifier, 6. readonly for immutable
109
+ @property(Node)
110
+ private readonly targetNode: Node | null = null;
111
+
112
+ // 7. const for constants
113
+ private static readonly MAX_HEALTH: number = 100;
114
+ private currentHealth: number = 100;
115
+
116
+ // Lifecycle: onLoad → start → onEnable
117
+ protected onLoad(): void {
118
+ // 4. Throw exception for errors
119
+ if (!this.targetNode) {
120
+ throw new Error('PlayerController: targetNode is not assigned');
121
+ }
122
+
123
+ // 9. Proper event listener setup
124
+ this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
125
+ }
126
+
127
+ protected onDestroy(): void {
128
+ // 9. Always cleanup event listeners
129
+ this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
130
+ }
131
+
132
+ private onTouchStart(event: EventTouch): void {
133
+ // 5. console.log only for development (remove in production)
134
+ if (CC_DEBUG) {
135
+ console.log('Touch detected');
136
+ }
137
+
138
+ this.takeDamage(10);
139
+ }
140
+
141
+ // 8. Descriptive method names (no inline comments needed)
142
+ private takeDamage(amount: number): void {
143
+ this.currentHealth -= amount;
144
+
145
+ if (this.currentHealth <= 0) {
146
+ this.handlePlayerDeath();
147
+ }
148
+ }
149
+
150
+ private handlePlayerDeath(): void {
151
+ // Death logic
152
+ }
153
+ }
154
+ ```
155
+
156
+ ## ⚠️ Cocos Creator Architecture Rules (AFTER Quality)
157
+
158
+ ### Component System Fundamentals
159
+
160
+ **Entity-Component (EC) System:**
161
+ - Components extend `Component` class
162
+ - Use `@ccclass` and `@property` decorators
163
+ - Lifecycle: onLoad → start → onEnable → update → lateUpdate → onDisable → onDestroy
164
+
165
+ **Execution Order:**
166
+ 1. **onLoad()** - Component initialization, one-time setup
167
+ 2. **start()** - After all components loaded, can reference other components
168
+ 3. **onEnable()** - When component/node enabled (can be called multiple times)
169
+ 4. **update(dt)** - Every frame (use sparingly for playables)
170
+ 5. **lateUpdate(dt)** - After all update() calls
171
+ 6. **onDisable()** - When component/node disabled
172
+ 7. **onDestroy()** - Cleanup, remove listeners, release resources
173
+
174
+ **Universal Rules:**
175
+ - ✅ Initialize in onLoad(), reference other components in start()
176
+ - ✅ Register events in onEnable(), unregister in onDisable()
177
+ - ✅ Always cleanup listeners in onDestroy()
178
+ - ✅ Avoid heavy logic in update() (performance critical for playables)
179
+ - ✅ Use readonly for @property fields that shouldn't be reassigned
180
+ - ✅ Throw exceptions for missing required references
181
+
182
+ ## Brief Examples
183
+
184
+ ### 🔴 Code Quality First
185
+
186
+ ```typescript
187
+ // ✅ EXCELLENT: Quality rules enforced
188
+ import { _decorator, Component, Node } from 'cc';
189
+ const { ccclass, property } = _decorator;
190
+
191
+ @ccclass('GameManager')
192
+ export class GameManager extends Component {
193
+ @property(Node)
194
+ private readonly playerNode: Node | null = null;
195
+
196
+ private static readonly MAX_SCORE: number = 1000;
197
+ private currentScore: number = 0;
198
+
199
+ protected onLoad(): void {
200
+ // Throw exception for missing required references
201
+ if (!this.playerNode) {
202
+ throw new Error('GameManager: playerNode is required');
203
+ }
204
+
205
+ if (CC_DEBUG) {
206
+ console.log('GameManager initialized'); // Development only
207
+ }
208
+ }
209
+
210
+ public addScore(points: number): void {
211
+ if (points <= 0) {
212
+ throw new Error('GameManager.addScore: points must be positive');
213
+ }
214
+
215
+ this.currentScore = Math.min(
216
+ this.currentScore + points,
217
+ GameManager.MAX_SCORE
218
+ );
219
+ }
220
+ }
221
+ ```
222
+
223
+ ### 🟡 Modern TypeScript Patterns
224
+
225
+ ```typescript
226
+ // ✅ GOOD: Array methods instead of loops
227
+ const activeEnemies = allEnemies.filter(e => e.isActive);
228
+ const enemyPositions = activeEnemies.map(e => e.node.position);
229
+
230
+ // ✅ GOOD: Optional chaining and nullish coalescing
231
+ const playerName = player?.name ?? 'Unknown';
232
+
233
+ // ✅ GOOD: Destructuring
234
+ const { x, y } = this.node.position;
235
+
236
+ // ✅ GOOD: Arrow functions
237
+ this.enemies.forEach(enemy => enemy.takeDamage(10));
238
+
239
+ // ✅ GOOD: Type guards
240
+ function isPlayer(node: Node): node is PlayerNode {
241
+ return node.getComponent(PlayerController) !== null;
242
+ }
243
+ ```
244
+
245
+ ### 🟢 Cocos Creator Component Pattern
246
+
247
+ ```typescript
248
+ import { _decorator, Component, Node, EventTouch, Vec3 } from 'cc';
249
+ const { ccclass, property } = _decorator;
250
+
251
+ @ccclass('TouchHandler')
252
+ export class TouchHandler extends Component {
253
+ @property(Node)
254
+ private readonly targetNode: Node | null = null;
255
+
256
+ private readonly tempVec3: Vec3 = new Vec3(); // Reusable vector
257
+
258
+ // 1. onLoad: Initialize component
259
+ protected onLoad(): void {
260
+ if (!this.targetNode) {
261
+ throw new Error('TouchHandler: targetNode is required');
262
+ }
263
+ }
264
+
265
+ // 2. start: Reference other components (if needed)
266
+ protected start(): void {
267
+ // Can safely access other components here
268
+ }
269
+
270
+ // 3. onEnable: Register event listeners
271
+ protected onEnable(): void {
272
+ this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
273
+ this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
274
+ }
275
+
276
+ // 4. onDisable: Unregister event listeners
277
+ protected onDisable(): void {
278
+ this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
279
+ this.node.off(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
280
+ }
281
+
282
+ // 5. onDestroy: Final cleanup
283
+ protected onDestroy(): void {
284
+ // Release any additional resources
285
+ }
286
+
287
+ private onTouchStart(event: EventTouch): void {
288
+ // Handle touch
289
+ }
290
+
291
+ private onTouchMove(event: EventTouch): void {
292
+ // Reuse vector to avoid allocations
293
+ this.targetNode!.getPosition(this.tempVec3);
294
+ this.tempVec3.y += 10;
295
+ this.targetNode!.setPosition(this.tempVec3);
296
+ }
297
+ }
298
+ ```
299
+
300
+ ### 🟢 Event Dispatcher Pattern
301
+
302
+ ```typescript
303
+ import { _decorator, Component, EventTarget } from 'cc';
304
+ const { ccclass } = _decorator;
305
+
306
+ // Custom event types
307
+ export enum GameEvent {
308
+ SCORE_CHANGED = 'score_changed',
309
+ LEVEL_COMPLETE = 'level_complete',
310
+ PLAYER_DIED = 'player_died',
311
+ }
312
+
313
+ export interface ScoreChangedEvent {
314
+ oldScore: number;
315
+ newScore: number;
316
+ }
317
+
318
+ @ccclass('EventManager')
319
+ export class EventManager extends Component {
320
+ private static instance: EventManager | null = null;
321
+ private readonly eventTarget: EventTarget = new EventTarget();
322
+
323
+ protected onLoad(): void {
324
+ if (EventManager.instance) {
325
+ throw new Error('EventManager: instance already exists');
326
+ }
327
+ EventManager.instance = this;
328
+ }
329
+
330
+ public static emit(event: GameEvent, data?: any): void {
331
+ if (!EventManager.instance) {
332
+ throw new Error('EventManager: instance not initialized');
333
+ }
334
+ EventManager.instance.eventTarget.emit(event, data);
335
+ }
336
+
337
+ public static on(event: GameEvent, callback: Function, target?: any): void {
338
+ if (!EventManager.instance) {
339
+ throw new Error('EventManager: instance not initialized');
340
+ }
341
+ EventManager.instance.eventTarget.on(event, callback, target);
342
+ }
343
+
344
+ public static off(event: GameEvent, callback: Function, target?: any): void {
345
+ if (!EventManager.instance) {
346
+ throw new Error('EventManager: instance not initialized');
347
+ }
348
+ EventManager.instance.eventTarget.off(event, callback, target);
349
+ }
350
+ }
351
+
352
+ // Usage in component
353
+ @ccclass('ScoreDisplay')
354
+ export class ScoreDisplay extends Component {
355
+ protected onEnable(): void {
356
+ EventManager.on(GameEvent.SCORE_CHANGED, this.onScoreChanged, this);
357
+ }
358
+
359
+ protected onDisable(): void {
360
+ EventManager.off(GameEvent.SCORE_CHANGED, this.onScoreChanged, this);
361
+ }
362
+
363
+ private onScoreChanged(data: ScoreChangedEvent): void {
364
+ console.log(`Score: ${data.oldScore} → ${data.newScore}`);
365
+ }
366
+ }
367
+ ```
368
+
369
+ ### 🔵 Playable Performance Optimization
370
+
371
+ ```typescript
372
+ import { _decorator, Component, Node, Sprite, SpriteAtlas } from 'cc';
373
+ const { ccclass, property } = _decorator;
374
+
375
+ @ccclass('OptimizedSpriteManager')
376
+ export class OptimizedSpriteManager extends Component {
377
+ // Use sprite atlas for DrawCall batching
378
+ @property(SpriteAtlas)
379
+ private readonly characterAtlas: SpriteAtlas | null = null;
380
+
381
+ // Preallocate arrays to avoid allocations in update()
382
+ private readonly tempNodes: Node[] = [];
383
+ private frameCount: number = 0;
384
+
385
+ protected onLoad(): void {
386
+ if (!this.characterAtlas) {
387
+ throw new Error('OptimizedSpriteManager: characterAtlas is required');
388
+ }
389
+
390
+ // Prewarm sprite frames from atlas
391
+ this.prewarmSpriteFrames();
392
+ }
393
+
394
+ private prewarmSpriteFrames(): void {
395
+ // Load all sprites from atlas (batched in single DrawCall)
396
+ const spriteFrame = this.characterAtlas!.getSpriteFrame('character_idle');
397
+ if (!spriteFrame) {
398
+ throw new Error('Sprite frame not found in atlas');
399
+ }
400
+ }
401
+
402
+ // Optimize update: avoid allocations, use object pooling
403
+ protected update(dt: number): void {
404
+ // Run expensive operations every N frames instead of every frame
405
+ this.frameCount++;
406
+ if (this.frameCount % 10 === 0) {
407
+ this.updateExpensiveOperation();
408
+ }
409
+ }
410
+
411
+ private updateExpensiveOperation(): void {
412
+ // Reuse array instead of creating new one
413
+ this.tempNodes.length = 0;
414
+
415
+ // Batch operations to reduce DrawCalls
416
+ }
417
+ }
418
+ ```
419
+
420
+ ## Code Review Checklist
421
+
422
+ ### Quick Validation (before committing)
423
+
424
+ **🔴 Code Quality (CHECK FIRST):**
425
+ - [ ] TypeScript strict mode enabled in tsconfig.json
426
+ - [ ] ESLint rules passing (no errors)
427
+ - [ ] All access modifiers correct (public/private/protected)
428
+ - [ ] Exceptions thrown for errors (no silent failures)
429
+ - [ ] console.log removed or wrapped in CC_DEBUG
430
+ - [ ] readonly used for non-reassigned fields
431
+ - [ ] const used for constants
432
+ - [ ] No inline comments (self-explanatory code)
433
+ - [ ] Proper null/undefined handling
434
+ - [ ] No `any` types (use proper types)
435
+
436
+ **🟡 Modern TypeScript Patterns:**
437
+ - [ ] Array methods used instead of manual loops
438
+ - [ ] Arrow functions for callbacks
439
+ - [ ] Optional chaining (?.) for safe property access
440
+ - [ ] Nullish coalescing (??) for default values
441
+ - [ ] Destructuring for cleaner code
442
+ - [ ] Type guards for type narrowing
443
+
444
+ **🟢 Cocos Creator Architecture:**
445
+ - [ ] Component lifecycle methods in correct order
446
+ - [ ] onLoad() for initialization, start() for references
447
+ - [ ] Event listeners registered in onEnable()
448
+ - [ ] Event listeners unregistered in onDisable()
449
+ - [ ] Resources released in onDestroy()
450
+ - [ ] @property decorator used correctly
451
+ - [ ] Required references validated (throw if null)
452
+
453
+ **🔵 Playable Performance:**
454
+ - [ ] No allocations in update() loop
455
+ - [ ] Sprite atlas used for DrawCall batching
456
+ - [ ] GPU skinning enabled for skeletal animations
457
+ - [ ] Expensive operations throttled (not every frame)
458
+ - [ ] Object pooling for frequently created objects
459
+ - [ ] Texture compression enabled
460
+ - [ ] Bundle size <5MB target
461
+ - [ ] DrawCall count <10 target
462
+
463
+ ## Common Mistakes to Avoid
464
+
465
+ ### ❌ DON'T:
466
+ 1. **Ignore TypeScript strict mode** → Enable "strict": true
467
+ 2. **Silent error handling** → Throw exceptions for errors
468
+ 3. **Leave console.log in production** → Remove or wrap in CC_DEBUG
469
+ 4. **Skip access modifiers** → Use public/private/protected
470
+ 5. **Use `any` type** → Define proper types and interfaces
471
+ 6. **Add inline comments** → Use descriptive names instead
472
+ 7. **Skip event cleanup** → Always unregister in onDisable/onDestroy
473
+ 8. **Allocate in update()** → Preallocate and reuse objects
474
+ 9. **Forget sprite atlas** → Use atlas for DrawCall batching
475
+ 10. **Heavy logic in update()** → Throttle expensive operations
476
+ 11. **Skip null checks** → Validate required references in onLoad
477
+ 12. **Mutable @property fields** → Use readonly when appropriate
478
+ 13. **Manual loops over arrays** → Use map/filter/reduce
479
+ 14. **Ignore bundle size** → Monitor and optimize (<5MB target)
480
+
481
+ ### ✅ DO:
482
+ 1. **Enable TypeScript strict mode** ("strict": true)
483
+ 2. **Throw exceptions for errors** (never silent failures)
484
+ 3. **Use console.log for development only** (remove in production)
485
+ 4. **Use access modifiers** (public/private/protected)
486
+ 5. **Define proper types** (avoid `any`)
487
+ 6. **Use descriptive names** (no inline comments)
488
+ 7. **Always cleanup events** (onDisable/onDestroy)
489
+ 8. **Preallocate objects** (reuse in update())
490
+ 9. **Use sprite atlas** (DrawCall batching)
491
+ 10. **Throttle expensive operations** (not every frame)
492
+ 11. **Validate required references** (throw in onLoad if null)
493
+ 12. **Use readonly for @property** (when appropriate)
494
+ 13. **Use array methods** (map/filter/reduce)
495
+ 14. **Monitor bundle size** (<5MB target for playables)
496
+
497
+ ## Review Severity Levels
498
+
499
+ ### 🔴 Critical (Must Fix)
500
+ - **TypeScript strict mode disabled** - Must enable "strict": true
501
+ - **Silent error handling** - Must throw exceptions for errors
502
+ - **console.log in production code** - Remove or wrap in CC_DEBUG
503
+ - **Missing access modifiers** - All members must have modifiers
504
+ - **Using `any` type without justification** - Define proper types
505
+ - **Inline comments instead of descriptive names** - Rename and remove comments
506
+ - **Event listeners not cleaned up** - Memory leak, must unregister
507
+ - **Missing required reference validation** - Must throw in onLoad if null
508
+ - **Allocations in update() loop** - Performance critical, must preallocate
509
+ - **No sprite atlas for multiple sprites** - DrawCall explosion, must use atlas
510
+ - **Bundle size >5MB** - Exceeds playable limit, must optimize
511
+
512
+ ### 🟡 Important (Should Fix)
513
+ - **Missing readonly on @property fields** - Should be readonly when not reassigned
514
+ - **Missing const for constants** - Should use const instead of let
515
+ - **Manual loops instead of array methods** - Should use map/filter/reduce
516
+ - **Missing optional chaining** - Should use ?. for safe access
517
+ - **Missing nullish coalescing** - Should use ?? for default values
518
+ - **Heavy logic in update()** - Should throttle expensive operations
519
+ - **No object pooling for frequent allocations** - Should implement pooling
520
+ - **Texture compression not enabled** - Should enable for smaller bundle
521
+ - **DrawCall count >10** - Should optimize batching
522
+
523
+ ### 🟢 Nice to Have (Suggestion)
524
+ - Could use arrow function for callback
525
+ - Could destructure for cleaner code
526
+ - Could use type guard for type safety
527
+ - Could improve naming for clarity
528
+ - Could add interface for better typing
529
+ - Could optimize algorithm for better performance
530
+
531
+ ## Detailed References
532
+
533
+ ### TypeScript Language Standards
534
+ - [Quality & Hygiene](references/language/quality-hygiene.md) - Strict mode, ESLint, access modifiers, error handling
535
+ - [Modern TypeScript](references/language/modern-typescript.md) - Array methods, optional chaining, type guards, utility types
536
+ - [Performance](references/language/performance.md) - Update loop optimization, zero allocations, caching
537
+
538
+ ### Cocos Creator Framework
539
+ - [Component System](references/framework/component-system.md) - EC system, lifecycle methods, @property decorator
540
+ - [Event Patterns](references/framework/event-patterns.md) - EventDispatcher, Node events, subscription cleanup
541
+ - [Playable Optimization](references/framework/playable-optimization.md) - DrawCall batching, sprite atlas, GPU skinning, resource pooling
542
+ - [Size Optimization](references/framework/size-optimization.md) - Bundle size reduction, texture compression, build optimization
543
+
544
+ ### Code Review
545
+ - [Architecture Review](references/review/architecture-review.md) - Component violations, lifecycle errors, event leaks
546
+ - [Quality Review](references/review/quality-review.md) - TypeScript quality issues, access modifiers, error handling
547
+ - [Performance Review](references/review/performance-review.md) - Playable-specific performance problems, DrawCalls, allocations
548
+
549
+ ## Summary
550
+
551
+ This skill provides comprehensive Cocos Creator development standards for TheOne Studio's playable ads team:
552
+ - **TypeScript Excellence**: Strict mode, modern patterns, type safety
553
+ - **Cocos Architecture**: Component lifecycle, event patterns, resource management
554
+ - **Playable Performance**: DrawCall batching, GPU skinning, <5MB bundles
555
+ - **Code Quality**: Enforced quality, hygiene, and performance rules
556
+
557
+ Use the Quick Reference Guide above to navigate to the specific pattern you need.