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