diff --git a/cocos2d/ToMerge/wrappers/tiled-map.js b/cocos2d/ToMerge/wrappers/tiled-map.js deleted file mode 100644 index 2d17af8e23..0000000000 --- a/cocos2d/ToMerge/wrappers/tiled-map.js +++ /dev/null @@ -1,103 +0,0 @@ - -var NodeWrapper = require('./node'); - -var TiledMapWrapper = cc.Class({ - name: 'cc.TiledMapWrapper', - extends: NodeWrapper, - - properties: { - - file_: { - get: function () { - return this.targetN._file || ''; - }, - set: function (value) { - if ( !value ) { - cc.error('The new file must not be null'); - return; - } - - // first remove all layers - var layers = target.allLayers(); - layers.forEach( function (layer) { - target.removeChild(layer); - }); - - TiledMapWrapper.preloadTmx( value , function (err, textures) { - if (err) { - throw err; - return; - } - - this._textures = textures; - target._file = value; - target.initWithTMXFile( value ); - }.bind(this) ); - }, - url: cc.TiledMapAsset, - displayName: 'File' - }, - - childrenN: { - get: function () { - var children = this.targetN.children.filter( function (child) { - return !(child instanceof _ccsg.TMXLayer); - }); - return children; - }, - }, - - _textures: { - default: [], - url: [cc.Texture2D] - }, - - file: { - default: '', - url: cc.TiledMapAsset, - visible: false - } - }, - - statics: { - preloadTmx: function (file, cb) { - cc.loader.load(file, function (err) { - if (err) { - if (cb) cb(err); - return; - } - - var mapInfo = new cc.TMXMapInfo(file); - var sets = mapInfo.getTilesets(); - - if (sets) { - var textures = sets.map(function (set) { - return set.sourceImage; - }); - - cc.loader.load(textures, function (err) { - cb(err, textures); - }); - } - else { - if (cb) cb(); - } - }); - } - }, - - onBeforeSerialize: function () { - this.file = this.file_; - }, - - createNode: function (node) { - node = node || new cc.TMXTiledMap( this.file ); - node._file = this.file; - - NodeWrapper.prototype.createNode.call(this, node); - - return node; - } -}); - -cc.TiledMapWrapper = module.exports = TiledMapWrapper; diff --git a/cocos2d/core/utils/find.js b/cocos2d/core/utils/find.js index 908fedbf2b..986b1b9dff 100644 --- a/cocos2d/core/utils/find.js +++ b/cocos2d/core/utils/find.js @@ -56,28 +56,11 @@ cc.find = module.exports = function (path, referenceNode) { // parse path for (var n = startIndex; n < nameList.length; n++) { var name = nameList[n]; - var findByComp = name[0] === '<' && name[name.length - 1] === '>'; - var Comp; - if (findByComp) { - var compName = name.slice(1, -1); - Comp = cc.js.getClassByName(compName); - if (!Comp) { - cc.warn('Failed to find component ' + compName); - return null; - } - } - // visit sub nodes var children = match._children; match = null; for (var t = 0, len = children.length; t < len; ++t) { var subChild = children[t]; - if (findByComp) { - if (subChild.getComponent(Comp)) { - match = subChild; - break; - } - } - else if (subChild.name === name) { + if (subChild.name === name) { match = subChild; break; } diff --git a/test/qunit/unit/test-find.js b/test/qunit/unit/test-find.js new file mode 100644 index 0000000000..62905ea8fe --- /dev/null +++ b/test/qunit/unit/test-find.js @@ -0,0 +1,31 @@ +module('cc.find', SetupEngine); + +test('test', function () { + var scene = cc.director.getScene(); + + var node = new cc.Node(''); + scene.addChild(node); + + ok(cc.find('/') === node, 'should found, empty name, path starts with sep'); + ok(cc.find('') === node, 'should found, empty name'); + + var node2 = new cc.Node('.赞'); + scene.addChild(node2); + ok(cc.find('/.赞') === node2, 'should found, Chinese name, path starts with sep'); + ok(cc.find('.赞') === node2, 'should found, Chinese name'); + + var nodenode = new cc.Node(''); + node.addChild(nodenode); + ok(cc.find('//') === nodenode, 'should found, empty name * 2'); + ok(cc.find('/', node) === nodenode, 'should found by reference node, empty name * 2'); + + var node2node2 = new cc.Node('Jare Guo'); + node2.addChild(node2node2); + ok(cc.find('/.赞/Jare Guo') === node2node2, 'should found, name contains space, path starts with sep'); + ok(cc.find('.赞/Jare Guo') === node2node2, 'should found, name contains space'); + ok(cc.find('Jare Guo', node2) === node2node2, 'should found by reference node, name contains space'); + + var ent2ent2ent2 = new cc.Node('FOO'); + node2node2.addChild(ent2ent2ent2); + ok(cc.find('Jare Guo/FOO', node2) === ent2ent2ent2, 'should found by reference node'); +});