cocos2d-cli 1.2.1 → 1.5.0

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 (39) hide show
  1. package/README.md +142 -0
  2. package/bin/{cocos-cli.js → cocos2d-cli.js} +36 -22
  3. package/package.json +3 -3
  4. package/src/commands/add-component.js +75 -114
  5. package/src/commands/add.js +115 -294
  6. package/src/commands/build.js +1 -1
  7. package/src/commands/create-scene.js +133 -488
  8. package/src/commands/get.js +104 -158
  9. package/src/commands/prefab-create.js +57 -425
  10. package/src/commands/remove-component.js +81 -33
  11. package/src/commands/remove.js +66 -65
  12. package/src/commands/set.js +105 -253
  13. package/src/commands/tree.js +7 -11
  14. package/src/lib/cc/CCButton.js +122 -0
  15. package/src/lib/cc/CCCamera.js +93 -0
  16. package/src/lib/cc/CCCanvas.js +64 -0
  17. package/src/lib/cc/CCColor.js +32 -0
  18. package/src/lib/cc/CCComponent.js +60 -0
  19. package/src/lib/cc/CCLabel.js +109 -0
  20. package/src/lib/cc/CCNode.js +242 -0
  21. package/src/lib/cc/CCObject.js +23 -0
  22. package/src/lib/cc/CCPrefab.js +242 -0
  23. package/src/lib/cc/CCRect.js +32 -0
  24. package/src/lib/cc/CCScene.js +42 -0
  25. package/src/lib/cc/CCSceneAsset.js +271 -0
  26. package/src/lib/cc/CCSize.js +26 -0
  27. package/src/lib/cc/CCSprite.js +82 -0
  28. package/src/lib/cc/CCTrs.js +74 -0
  29. package/src/lib/cc/CCVec2.js +26 -0
  30. package/src/lib/cc/CCVec3.js +29 -0
  31. package/src/lib/cc/CCWidget.js +98 -0
  32. package/src/lib/cc/index.js +40 -0
  33. package/src/lib/fire-utils.js +58 -392
  34. package/src/lib/json-parser.js +166 -0
  35. package/src/lib/node-utils.js +395 -0
  36. package/src/lib/templates.js +49 -0
  37. package/src/lib/utils.js +202 -0
  38. package/src/commands/delete.js +0 -74
  39. package/src/lib/components.js +0 -404
@@ -0,0 +1,122 @@
1
+ const CCComponent = require('./CCComponent');
2
+ const CCColor = require('./CCColor');
3
+
4
+ /**
5
+ * Cocos Creator Button 组件
6
+ */
7
+ class CCButton extends CCComponent {
8
+ constructor() {
9
+ super();
10
+ this.__type__ = 'cc.Button';
11
+
12
+ this._normalMaterial = null;
13
+ this._grayMaterial = null;
14
+ this.duration = 0.1;
15
+ this.zoomScale = 1.2;
16
+ this.clickEvents = [];
17
+ this._N$interactable = true;
18
+ this._N$enableAutoGrayEffect = false;
19
+ this._N$transition = 3;
20
+ this.transition = 3;
21
+ this._N$normalColor = new CCColor();
22
+ this._N$pressedColor = new CCColor(200, 200, 200, 255);
23
+ this.pressedColor = new CCColor(200, 200, 200, 255);
24
+ this._N$hoverColor = new CCColor();
25
+ this.hoverColor = new CCColor();
26
+ this._N$disabledColor = new CCColor(120, 120, 120, 200);
27
+ this._N$normalSprite = null;
28
+ this._N$pressedSprite = null;
29
+ this.pressedSprite = null;
30
+ this._N$hoverSprite = null;
31
+ this.hoverSprite = null;
32
+ this._N$disabledSprite = null;
33
+ this._N$target = null;
34
+ }
35
+
36
+ /**
37
+ * 设置缩放
38
+ */
39
+ setZoomScale(scale) {
40
+ this.zoomScale = scale;
41
+ return this;
42
+ }
43
+
44
+ /**
45
+ * 设置过渡类型
46
+ * 0: NONE, 1: COLOR, 2: SPRITE, 3: SCALE
47
+ */
48
+ setTransition(type) {
49
+ this._N$transition = type;
50
+ this.transition = type;
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * 设置正常精灵
56
+ */
57
+ setNormalSprite(uuid) {
58
+ this._N$normalSprite = { __uuid__: uuid };
59
+ return this;
60
+ }
61
+
62
+ /**
63
+ * 设置点击事件
64
+ */
65
+ addClickEvent(component, handler, target = null) {
66
+ this.clickEvents.push({
67
+ target: target,
68
+ component: component,
69
+ handler: handler
70
+ });
71
+ return this;
72
+ }
73
+
74
+ /**
75
+ * 转换为属性面板显示格式
76
+ */
77
+ toPanelJSON() {
78
+ const TRANSITION = ['NONE', 'COLOR', 'SPRITE', 'SCALE'];
79
+ return {
80
+ ...super.toPanelJSON(),
81
+ interactable: this._N$interactable,
82
+ transition: TRANSITION[this._N$transition] || this._N$transition,
83
+ zoomScale: this.zoomScale,
84
+ duration: this.duration
85
+ };
86
+ }
87
+
88
+ toJSON() {
89
+ return {
90
+ __type__: this.__type__,
91
+ _name: this._name,
92
+ _objFlags: this._objFlags,
93
+ node: this.node,
94
+ _enabled: this._enabled,
95
+ _normalMaterial: this._normalMaterial,
96
+ _grayMaterial: this._grayMaterial,
97
+ duration: this.duration,
98
+ zoomScale: this.zoomScale,
99
+ clickEvents: this.clickEvents,
100
+ _N$interactable: this._N$interactable,
101
+ _N$enableAutoGrayEffect: this._N$enableAutoGrayEffect,
102
+ _N$transition: this._N$transition,
103
+ transition: this.transition,
104
+ _N$normalColor: this._N$normalColor.toJSON(),
105
+ _N$pressedColor: this._N$pressedColor.toJSON(),
106
+ pressedColor: this.pressedColor.toJSON(),
107
+ _N$hoverColor: this._N$hoverColor.toJSON(),
108
+ hoverColor: this.hoverColor.toJSON(),
109
+ _N$disabledColor: this._N$disabledColor.toJSON(),
110
+ _N$normalSprite: this._N$normalSprite,
111
+ _N$pressedSprite: this._N$pressedSprite,
112
+ pressedSprite: this.pressedSprite,
113
+ _N$hoverSprite: this._N$hoverSprite,
114
+ hoverSprite: this.hoverSprite,
115
+ _N$disabledSprite: this._N$disabledSprite,
116
+ _N$target: this._N$target,
117
+ _id: this._id
118
+ };
119
+ }
120
+ }
121
+
122
+ module.exports = CCButton;
@@ -0,0 +1,93 @@
1
+ const CCComponent = require('./CCComponent');
2
+ const CCColor = require('./CCColor');
3
+ const CCRect = require('./CCRect');
4
+
5
+ /**
6
+ * Cocos Creator Camera 组件
7
+ */
8
+ class CCCamera extends CCComponent {
9
+ constructor() {
10
+ super();
11
+ this.__type__ = 'cc.Camera';
12
+
13
+ this._cullingMask = 4294967295;
14
+ this._clearFlags = 7;
15
+ this._backgroundColor = new CCColor(0, 0, 0, 255);
16
+ this._depth = -1;
17
+ this._zoomRatio = 1;
18
+ this._targetTexture = null;
19
+ this._fov = 60;
20
+ this._orthoSize = 10;
21
+ this._nearClip = 1;
22
+ this._farClip = 4096;
23
+ this._ortho = true;
24
+ this._rect = new CCRect(0, 0, 1, 1);
25
+ this._renderStages = 1;
26
+ this._alignWithScreen = true;
27
+ }
28
+
29
+ /**
30
+ * 设置正交大小
31
+ */
32
+ setOrthoSize(size) {
33
+ this._orthoSize = size;
34
+ return this;
35
+ }
36
+
37
+ /**
38
+ * 设置深度
39
+ */
40
+ setDepth(depth) {
41
+ this._depth = depth;
42
+ return this;
43
+ }
44
+
45
+ /**
46
+ * 设置背景颜色
47
+ */
48
+ setBackgroundColor(r, g, b, a = 255) {
49
+ this._backgroundColor.set(r, g, b, a);
50
+ return this;
51
+ }
52
+
53
+ /**
54
+ * 转换为属性面板显示格式
55
+ */
56
+ toPanelJSON() {
57
+ return {
58
+ ...super.toPanelJSON(),
59
+ depth: this._depth,
60
+ zoomRatio: this._zoomRatio,
61
+ ortho: this._ortho,
62
+ orthoSize: this._orthoSize,
63
+ backgroundColor: this._backgroundColor ? `#${this._backgroundColor.r.toString(16).padStart(2,'0')}${this._backgroundColor.g.toString(16).padStart(2,'0')}${this._backgroundColor.b.toString(16).padStart(2,'0')}` : '#000000'
64
+ };
65
+ }
66
+
67
+ toJSON() {
68
+ return {
69
+ __type__: this.__type__,
70
+ _name: this._name,
71
+ _objFlags: this._objFlags,
72
+ node: this.node,
73
+ _enabled: this._enabled,
74
+ _cullingMask: this._cullingMask,
75
+ _clearFlags: this._clearFlags,
76
+ _backgroundColor: this._backgroundColor.toJSON(),
77
+ _depth: this._depth,
78
+ _zoomRatio: this._zoomRatio,
79
+ _targetTexture: this._targetTexture,
80
+ _fov: this._fov,
81
+ _orthoSize: this._orthoSize,
82
+ _nearClip: this._nearClip,
83
+ _farClip: this._farClip,
84
+ _ortho: this._ortho,
85
+ _rect: this._rect.toJSON(),
86
+ _renderStages: this._renderStages,
87
+ _alignWithScreen: this._alignWithScreen,
88
+ _id: this._id
89
+ };
90
+ }
91
+ }
92
+
93
+ module.exports = CCCamera;
@@ -0,0 +1,64 @@
1
+ const CCComponent = require('./CCComponent');
2
+ const CCSize = require('./CCSize');
3
+
4
+ /**
5
+ * Cocos Creator Canvas 组件
6
+ */
7
+ class CCCanvas extends CCComponent {
8
+ constructor() {
9
+ super();
10
+ this.__type__ = 'cc.Canvas';
11
+
12
+ this._designResolution = new CCSize(960, 640);
13
+ this._fitWidth = false;
14
+ this._fitHeight = true;
15
+ }
16
+
17
+ /**
18
+ * 设置设计分辨率
19
+ */
20
+ setDesignResolution(width, height) {
21
+ this._designResolution.set(width, height);
22
+ return this;
23
+ }
24
+
25
+ /**
26
+ * 设置适配模式
27
+ */
28
+ setFit(fitWidth, fitHeight) {
29
+ this._fitWidth = fitWidth;
30
+ this._fitHeight = fitHeight;
31
+ return this;
32
+ }
33
+
34
+ /**
35
+ * 转换为属性面板显示格式
36
+ */
37
+ toPanelJSON() {
38
+ return {
39
+ ...super.toPanelJSON(),
40
+ designResolution: {
41
+ width: this._designResolution?.width ?? 960,
42
+ height: this._designResolution?.height ?? 640
43
+ },
44
+ fitWidth: this._fitWidth,
45
+ fitHeight: this._fitHeight
46
+ };
47
+ }
48
+
49
+ toJSON() {
50
+ return {
51
+ __type__: this.__type__,
52
+ _name: this._name,
53
+ _objFlags: this._objFlags,
54
+ node: this.node,
55
+ _enabled: this._enabled,
56
+ _designResolution: this._designResolution.toJSON(),
57
+ _fitWidth: this._fitWidth,
58
+ _fitHeight: this._fitHeight,
59
+ _id: this._id
60
+ };
61
+ }
62
+ }
63
+
64
+ module.exports = CCCanvas;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Cocos Creator 颜色类
3
+ */
4
+ class CCColor {
5
+ constructor(r = 255, g = 255, b = 255, a = 255) {
6
+ this.__type__ = 'cc.Color';
7
+ this.r = r;
8
+ this.g = g;
9
+ this.b = b;
10
+ this.a = a;
11
+ }
12
+
13
+ set(r, g, b, a = 255) {
14
+ this.r = r;
15
+ this.g = g;
16
+ this.b = b;
17
+ this.a = a;
18
+ return this;
19
+ }
20
+
21
+ toJSON() {
22
+ return {
23
+ __type__: this.__type__,
24
+ r: this.r,
25
+ g: this.g,
26
+ b: this.b,
27
+ a: this.a
28
+ };
29
+ }
30
+ }
31
+
32
+ module.exports = CCColor;
@@ -0,0 +1,60 @@
1
+ const CCObject = require('./CCObject');
2
+ const { generateId } = require('../utils');
3
+
4
+ /**
5
+ * Cocos Creator 组件基类
6
+ */
7
+ class CCComponent extends CCObject {
8
+ constructor() {
9
+ super('');
10
+ this.__type__ = 'cc.Component';
11
+
12
+ // 关联的节点
13
+ this.node = null;
14
+
15
+ // 启用状态
16
+ this._enabled = true;
17
+
18
+ // 唯一标识(22位压缩格式)
19
+ this._id = generateId();
20
+ }
21
+
22
+ /**
23
+ * 设置节点引用
24
+ */
25
+ setNode(nodeIndex) {
26
+ this.node = { __id__: nodeIndex };
27
+ return this;
28
+ }
29
+
30
+ /**
31
+ * 设置启用状态
32
+ */
33
+ setEnabled(enabled) {
34
+ this._enabled = enabled;
35
+ return this;
36
+ }
37
+
38
+ /**
39
+ * 转换为属性面板显示格式(子类重写)
40
+ */
41
+ toPanelJSON() {
42
+ return {
43
+ type: this.__type__,
44
+ enabled: this._enabled
45
+ };
46
+ }
47
+
48
+ toJSON() {
49
+ return {
50
+ __type__: this.__type__,
51
+ _name: this._name,
52
+ _objFlags: this._objFlags,
53
+ node: this.node,
54
+ _enabled: this._enabled,
55
+ _id: this._id
56
+ };
57
+ }
58
+ }
59
+
60
+ module.exports = CCComponent;
@@ -0,0 +1,109 @@
1
+ const CCComponent = require('./CCComponent');
2
+
3
+ /**
4
+ * Cocos Creator Label 组件
5
+ */
6
+ class CCLabel extends CCComponent {
7
+ constructor() {
8
+ super();
9
+ this.__type__ = 'cc.Label';
10
+
11
+ this._materials = [{ __uuid__: 'eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432' }];
12
+ this._srcBlendFactor = 770;
13
+ this._dstBlendFactor = 771;
14
+ this._string = '';
15
+ this._N$string = '';
16
+ this._fontSize = 40;
17
+ this._lineHeight = 40;
18
+ this._enableWrapText = true;
19
+ this._N$file = null;
20
+ this._isSystemFontUsed = true;
21
+ this._spacingX = 0;
22
+ this._batchAsBitmap = false;
23
+ this._styleFlags = 0;
24
+ this._underlineHeight = 0;
25
+ this._N$horizontalAlign = 1;
26
+ this._N$verticalAlign = 1;
27
+ this._N$fontFamily = 'Arial';
28
+ this._N$overflow = 0;
29
+ this._N$cacheMode = 0;
30
+ }
31
+
32
+ /**
33
+ * 设置文本内容
34
+ */
35
+ setString(str) {
36
+ this._string = str;
37
+ this._N$string = str;
38
+ return this;
39
+ }
40
+
41
+ /**
42
+ * 设置字体大小
43
+ */
44
+ setFontSize(size) {
45
+ this._fontSize = size;
46
+ this._lineHeight = size;
47
+ return this;
48
+ }
49
+
50
+ /**
51
+ * 设置字体
52
+ */
53
+ setFontFamily(family) {
54
+ this._N$fontFamily = family;
55
+ return this;
56
+ }
57
+
58
+ /**
59
+ * 转换为属性面板显示格式
60
+ */
61
+ toPanelJSON() {
62
+ const H_ALIGN = ['LEFT', 'CENTER', 'RIGHT'];
63
+ const V_ALIGN = ['TOP', 'CENTER', 'BOTTOM'];
64
+ const OVERFLOW = ['NONE', 'CLAMP', 'SHRINK', 'RESIZE_HEIGHT'];
65
+ return {
66
+ ...super.toPanelJSON(),
67
+ string: this._string,
68
+ fontSize: this._fontSize,
69
+ lineHeight: this._lineHeight,
70
+ fontFamily: this._N$fontFamily,
71
+ horizontalAlign: H_ALIGN[this._N$horizontalAlign] || this._N$horizontalAlign,
72
+ verticalAlign: V_ALIGN[this._N$verticalAlign] || this._N$verticalAlign,
73
+ overflow: OVERFLOW[this._N$overflow] || this._N$overflow,
74
+ wrap: this._enableWrapText
75
+ };
76
+ }
77
+
78
+ toJSON() {
79
+ return {
80
+ __type__: this.__type__,
81
+ _name: this._name,
82
+ _objFlags: this._objFlags,
83
+ node: this.node,
84
+ _enabled: this._enabled,
85
+ _materials: this._materials,
86
+ _srcBlendFactor: this._srcBlendFactor,
87
+ _dstBlendFactor: this._dstBlendFactor,
88
+ _string: this._string,
89
+ _N$string: this._N$string,
90
+ _fontSize: this._fontSize,
91
+ _lineHeight: this._lineHeight,
92
+ _enableWrapText: this._enableWrapText,
93
+ _N$file: this._N$file,
94
+ _isSystemFontUsed: this._isSystemFontUsed,
95
+ _spacingX: this._spacingX,
96
+ _batchAsBitmap: this._batchAsBitmap,
97
+ _styleFlags: this._styleFlags,
98
+ _underlineHeight: this._underlineHeight,
99
+ _N$horizontalAlign: this._N$horizontalAlign,
100
+ _N$verticalAlign: this._N$verticalAlign,
101
+ _N$fontFamily: this._N$fontFamily,
102
+ _N$overflow: this._N$overflow,
103
+ _N$cacheMode: this._N$cacheMode,
104
+ _id: this._id
105
+ };
106
+ }
107
+ }
108
+
109
+ module.exports = CCLabel;