Skip to content

Commit f777ffc

Browse files
committed
issue cocos2d#3419 add parse method for ComAttribute
1 parent 7e98ae4 commit f777ffc

File tree

2 files changed

+21
-47
lines changed

2 files changed

+21
-47
lines changed

extensions/CocoStudio/Components/CCComAttribute.js

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@
2828
* @extends ccs.Component
2929
*/
3030
ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
31-
_attributes: null,
3231
_jsonDict: null,
3332
_filePath: "",
3433
ctor: function () {
3534
cc.Component.prototype.ctor.call(this);
36-
this._attributes = {};
3735
this._jsonDict = {};
3836
this._filePath = "";
3937
this._name = "CCComAttribute";
4038
},
4139
init: function () {
42-
this._attributes = {};
4340
this._jsonDict = {};
4441
return true;
4542
},
@@ -54,7 +51,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
5451
cc.log("Argument must be non-nil");
5552
return;
5653
}
57-
this._attributes[key] = value;
54+
this._jsonDict[key] = value;
5855
},
5956

6057
/**
@@ -67,7 +64,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
6764
cc.log("Argument must be non-nil");
6865
return;
6966
}
70-
this._attributes[key] = value;
67+
this._jsonDict[key] = value;
7168
},
7269

7370
/**
@@ -80,7 +77,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
8077
cc.log("Argument must be non-nil");
8178
return;
8279
}
83-
this._attributes[key] = value;
80+
this._jsonDict[key] = value;
8481
},
8582

8683
/**
@@ -93,7 +90,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
9390
cc.log("Argument must be non-nil");
9491
return;
9592
}
96-
this._attributes[key] = value;
93+
this._jsonDict[key] = value;
9794
},
9895

9996
/**
@@ -106,7 +103,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
106103
cc.log("Argument must be non-nil");
107104
return;
108105
}
109-
this._attributes[key] = value;
106+
this._jsonDict[key] = value;
110107
},
111108

112109
/**
@@ -119,7 +116,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
119116
cc.log("Argument must be non-nil");
120117
return;
121118
}
122-
this._attributes[key] = value;
119+
this._jsonDict[key] = value;
123120
},
124121

125122
/**
@@ -128,7 +125,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
128125
* @returns {Number}
129126
*/
130127
getInt: function (key) {
131-
var ret = this._attributes[key];
128+
var ret = this._jsonDict[key];
132129
return parseInt(ret || 0);
133130
},
134131

@@ -138,7 +135,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
138135
* @returns {Number}
139136
*/
140137
getDouble: function (key) {
141-
var ret = this._attributes[key];
138+
var ret = this._jsonDict[key];
142139
return parseFloat(ret || 0.0);
143140
},
144141

@@ -148,7 +145,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
148145
* @returns {Number}
149146
*/
150147
getFloat: function (key) {
151-
var ret = this._attributes[key];
148+
var ret = this._jsonDict[key];
152149
return parseFloat(ret || 0.0);
153150
},
154151

@@ -158,7 +155,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
158155
* @returns {Boolean}
159156
*/
160157
getBool: function (key) {
161-
var ret = this._attributes[key];
158+
var ret = this._jsonDict[key];
162159
return Boolean(ret || false);
163160
},
164161

@@ -168,7 +165,7 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
168165
* @returns {String}
169166
*/
170167
getCString: function (key) {
171-
var ret = this._attributes[key];
168+
var ret = this._jsonDict[key];
172169
return ret || "";
173170
},
174171

@@ -178,37 +175,18 @@ ccs.ComAttribute = ccs.Component.extend(/** @lends ccs.ComAttribute# */{
178175
* @returns {Object}
179176
*/
180177
getObject: function (key) {
181-
return this._attributes[key];
178+
return this._jsonDict[key];
182179
},
183180

184181
/**
185-
* Getter of jsonDict
182+
*
183+
* @param path
186184
*/
187-
getDict: function () {
188-
return this._jsonDict;
189-
},
190-
191-
/**
192-
* setter of jsonDict
193-
* @returns {Object}
194-
*/
195-
setDict: function (dict) {
196-
this._jsonDict = dict;
197-
},
198-
199-
/**
200-
* Getter of jsonName
201-
* @returns {String}
202-
*/
203-
getFile:function(){
204-
return this._filePath;
205-
},
206-
207-
/**
208-
* setter of fileName
209-
*/
210-
setFile:function(filePath){
211-
this._filePath = filePath;
185+
parse:function(path){
186+
var data = cc.FileUtils.getInstance().getTextFileData(path);
187+
if (data) {
188+
this._jsonDict = JSON.parse(data);
189+
}
212190
}
213191
});
214192
/**

extensions/CocoStudio/Reader/SceneReader.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,8 @@ ccs.SceneReader = ccs.Class.extend(/** @lends ccs.SceneReader# */{
245245
var attribute = null;
246246
if (resType == 0) {
247247
attribute = ccs.ComAttribute.create();
248-
if(this._baseBath!=path){
249-
var data = cc.FileUtils.getInstance().getTextFileData(path);
250-
if (data) {
251-
attribute.setDict(JSON.parse(data));
252-
}
248+
if (this._baseBath != path) {
249+
attribute.parse(path);
253250
}
254251
}
255252
else {
@@ -259,7 +256,6 @@ ccs.SceneReader = ccs.Class.extend(/** @lends ccs.SceneReader# */{
259256
if (comName) {
260257
attribute.setName(comName);
261258
}
262-
attribute.setFile(path);
263259
gb.addComponent(attribute);
264260
this._callSelector(attribute, subDict);
265261
}

0 commit comments

Comments
 (0)