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