1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3 
  4  http://www.cocos2d-x.org
  5 
  6  Permission is hereby granted, free of charge, to any person obtaining a copy
  7  of this software and associated documentation files (the "Software"), to deal
  8  in the Software without restriction, including without limitation the rights
  9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  copies of the Software, and to permit persons to whom the Software is
 11  furnished to do so, subject to the following conditions:
 12 
 13  The above copyright notice and this permission notice shall be included in
 14  all copies or substantial portions of the Software.
 15 
 16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22  THE SOFTWARE.
 23  ****************************************************************************/
 24 
 25 /**
 26  * @namespace Base singleton object for ccs.ActionManager
 27  */
 28 ccs.actionManager = /** @lends ccs.actionManager# */{
 29     _actionDic: {},
 30 
 31     /**
 32      * Init properties with json dictionary
 33      * @param {String} jsonName
 34      * @param {Object} dic
 35      * @param {Object} root
 36      */
 37     initWithDictionary: function (jsonName, dic, root) {
 38         var path = jsonName;
 39         var pos = path.lastIndexOf("/");
 40         var fileName = path.substr(pos + 1, path.length);
 41         var actionList = dic["actionlist"];
 42         var locActionList = [];
 43         for (var i = 0; i < actionList.length; i++) {
 44             var locAction = new ccs.ActionObject();
 45             var locActionDic = actionList[i];
 46             locAction.initWithDictionary(locActionDic, root);
 47             locActionList.push(locAction);
 48         }
 49         this._actionDic[fileName] = locActionList;
 50     },
 51 
 52     /**
 53      * Gets an actionObject with a name.
 54      * @param {String} jsonName
 55      * @param {String} actionName
 56      * @returns {ccs.ActionObject}
 57      */
 58     getActionByName: function (jsonName, actionName) {
 59         var actionList = this._actionDic[jsonName];
 60         if (!actionList) {
 61             return null;
 62         }
 63         for (var i = 0; i < actionList.length; i++) {
 64             var locAction = actionList[i];
 65             if (actionName == locAction.getName()) {
 66                 return locAction;
 67             }
 68         }
 69         return null;
 70     },
 71 
 72     /**
 73      * Play an Action with a name.
 74      * @param {String} jsonName
 75      * @param {String} actionName
 76      * @param {cc.CallFunc} fun
 77      */
 78     playActionByName: function (jsonName, actionName, fun) {
 79         var action = this.getActionByName(jsonName, actionName);
 80         if (action) {
 81             action.play(fun);
 82         }
 83     },
 84 
 85     /**
 86      * Release all actions.
 87      */
 88     releaseActions: function () {
 89         this._actionDic = {};
 90 
 91     },
 92 
 93 	/**
 94 	 * Clear data: Release all actions.
 95 	 */
 96 	clear: function() {
 97 		this._actionDic = {};
 98 	}
 99 };