1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3  Copyright (c) 2008-2010 Ricardo Quesada
  4  Copyright (c) 2011      Zynga 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 cc.TMXObjectGroup = cc.Class.extend(/** @lends cc.TMXObjectGroup# */{
 33     //name of the group
 34     _groupName:"",
 35     _positionOffset:cc.PointZero(),
 36     _properties:null,
 37     _objects:null,
 38 
 39     /**
 40      *  Constructor
 41      */
 42     ctor:function () {
 43         this._properties = [];
 44         this._objects = [];
 45     },
 46 
 47     /**
 48      * Offset position of child objects
 49      * @return {cc.Point}
 50      */
 51     getPositionOffset:function () {
 52         return this._positionOffset;
 53     },
 54 
 55     /**
 56      * @param {cc.Point} Var
 57      */
 58     setPositionOffset:function (Var) {
 59         this._positionOffset = Var;
 60     },
 61 
 62     /**
 63      * List of properties stored in a dictionary
 64      * @return {Array}
 65      */
 66     getProperties:function () {
 67         return this._properties;
 68     },
 69 
 70     /**
 71      * @param {object} Var
 72      */
 73     setProperties:function (Var) {
 74         this._properties.push(Var);
 75     },
 76 
 77     /**
 78      * @return {String}
 79      */
 80     getGroupName:function () {
 81         return this._groupName.toString();
 82     },
 83 
 84     /**
 85      * @param {String} groupName
 86      */
 87     setGroupName:function (groupName) {
 88         this._groupName = groupName;
 89     },
 90 
 91     /**
 92      * Return the value for the specific property name
 93      * @param {String} propertyName
 94      * @return {object}
 95      */
 96     propertyNamed:function (propertyName) {
 97         return this._properties[propertyName];
 98     },
 99 
100     /**
101      * <p>Return the dictionary for the specific object name. <br />
102      * It will return the 1st object found on the array for the given name.</p>
103      * @param {String} objectName
104      * @return {object|Null}
105      */
106     objectNamed:function (objectName) {
107         if (this._objects && this._objects.length > 0) {
108             for (var i = 0, len = this._objects.length; i < len; i++) {
109                 var name = this._objects[i]["name"];
110                 if (name && name == objectName) {
111                     return this._objects[i];
112                 }
113             }
114         }
115         // object not found
116         return null;
117     },
118 
119     /**
120      * @return {Array}
121      */
122     getObjects:function () {
123         return this._objects;
124     },
125 
126     /**
127      * @param {object} objects
128      */
129     setObjects:function (objects) {
130         this._objects.push(objects);
131     }
132 });
133