1 /**************************************************************************** 2 Copyright (c) 2008-2010 Ricardo Quesada 3 Copyright (c) 2011-2012 cocos2d-x.org 4 Copyright (c) 2013-2014 Chukong Technologies Inc. 5 6 http://www.cocos2d-x.org 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this software and associated documentation files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE. 25 ****************************************************************************/ 26 27 /** 28 * cc.TMXObjectGroup represents the TMX object group. 29 * @class 30 * @extends cc.Class 31 * 32 * @property {Array} properties - Properties from the group. They can be added using tilemap editors 33 * @property {String} groupName - Name of the group 34 */ 35 cc.TMXObjectGroup = cc.Class.extend(/** @lends cc.TMXObjectGroup# */{ 36 properties: null, 37 groupName: "", 38 39 _positionOffset: null, 40 _objects: null, 41 42 /** 43 * <p>The cc.TMXObjectGroup's constructor. <br/> 44 * This function will automatically be invoked when you create a node using new construction: "var node = new cc.TMXObjectGroup()".<br/> 45 * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p> 46 */ 47 ctor:function () { 48 this.groupName = ""; 49 this._positionOffset = cc.p(0,0); 50 this.properties = []; 51 this._objects = []; 52 }, 53 54 /** 55 * Offset position of child objects 56 * @return {cc.Point} 57 */ 58 getPositionOffset:function () { 59 return cc.p(this._positionOffset); 60 }, 61 62 /** 63 * Offset position of child objects 64 * @param {cc.Point} offset 65 */ 66 setPositionOffset:function (offset) { 67 this._positionOffset.x = offset.x; 68 this._positionOffset.y = offset.y; 69 }, 70 71 /** 72 * List of properties stored in a dictionary 73 * @return {Array} 74 */ 75 getProperties:function () { 76 return this.properties; 77 }, 78 79 /** 80 * List of properties stored in a dictionary 81 * @param {object} Var 82 */ 83 setProperties:function (Var) { 84 this.properties.push(Var); 85 }, 86 87 /** 88 * Gets the Group name. 89 * @return {String} 90 */ 91 getGroupName:function () { 92 return this.groupName.toString(); 93 }, 94 95 /** 96 * Set the Group name 97 * @param {String} groupName 98 */ 99 setGroupName:function (groupName) { 100 this.groupName = groupName; 101 }, 102 103 /** 104 * Return the value for the specific property name 105 * @param {String} propertyName 106 * @return {object} 107 */ 108 propertyNamed:function (propertyName) { 109 return this.properties[propertyName]; 110 }, 111 112 /** 113 * <p>Return the dictionary for the specific object name. <br /> 114 * It will return the 1st object found on the array for the given name.</p> 115 * @deprecated since v3.4 please use .getObject 116 * @param {String} objectName 117 * @return {object|Null} 118 */ 119 objectNamed:function (objectName) { 120 return this.getObject(objectName); 121 }, 122 123 /** 124 * <p>Return the dictionary for the specific object name. <br /> 125 * It will return the 1st object found on the array for the given name.</p> 126 * @param {String} objectName 127 * @return {object|Null} 128 */ 129 getObject: function(objectName){ 130 if (this._objects && this._objects.length > 0) { 131 var locObjects = this._objects; 132 for (var i = 0, len = locObjects.length; i < len; i++) { 133 var name = locObjects[i]["name"]; 134 if (name && name === objectName) 135 return locObjects[i]; 136 } 137 } 138 // object not found 139 return null; 140 }, 141 142 /** 143 * Gets the objects. 144 * @return {Array} 145 */ 146 getObjects:function () { 147 return this._objects; 148 }, 149 150 /** 151 * Set the objects. 152 * @param {object} objects 153 */ 154 setObjects:function (objects) { 155 this._objects.push(objects); 156 } 157 }); 158