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 
  9  Permission is hereby granted, free of charge, to any person obtaining a copy
 10  of this software and associated documentation files (the "Software"), to deal
 11  in the Software without restriction, including without limitation the rights
 12  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 13  copies of the Software, and to permit persons to whom the Software is
 14  furnished to do so, subject to the following conditions:
 15 
 16  The above copyright notice and this permission notice shall be included in
 17  all copies or substantial portions of the Software.
 18 
 19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 24  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 25  THE SOFTWARE.
 26  ****************************************************************************/
 27 (function () {
 28     var engine = [
 29         // Core
 30         'core/platform/CCClass.js',
 31         'core/cocoa/CCGeometry.js',
 32         'core/platform/Sys.js',
 33         'core/platform/CCConfig.js',
 34         'core/platform/miniFramework.js',
 35         'core/platform/CCCommon.js',
 36         'core/platform/CCMacro.js',
 37         'core/platform/CCFileUtils.js',
 38         'core/platform/CCTypes.js',
 39         'core/platform/CCEGLView.js',
 40         'core/platform/CCScreen.js',
 41         'core/platform/CCVisibleRect.js',
 42         'core/cocoa/CCNS.js',
 43         'core/cocoa/CCAffineTransform.js',
 44         'core/support/CCPointExtension.js',
 45         'core/support/CCVertex.js',
 46         'core/support/TransformUtils.js',
 47         'core/base_nodes/CCNode.js',
 48         'core/base_nodes/CCAtlasNode.js',
 49         'core/textures/CCTexture2D.js',
 50         'core/textures/CCTextureCache.js',
 51         'core/textures/CCTextureAtlas.js',
 52         'core/scenes_nodes/CCScene.js',
 53         'core/layers_nodes/CCLayer.js',
 54         'core/sprite_nodes/CCSprite.js',
 55         'core/sprite_nodes/CCAnimation.js',
 56         'core/sprite_nodes/CCAnimationCache.js',
 57         'core/sprite_nodes/CCSpriteFrame.js',
 58         'core/sprite_nodes/CCSpriteFrameCache.js',
 59         'core/sprite_nodes/CCSpriteBatchNode.js',
 60         'core/CCConfiguration.js',
 61         'core/CCDirector.js',
 62         'core/CCCamera.js',
 63         'core/CCScheduler.js',
 64         'core/CCLoader.js',
 65         'core/CCDrawingPrimitives.js',
 66         'core/platform/CCApplication.js',
 67         'core/platform/CCSAXParser.js',
 68         'core/platform/AppControl.js',
 69         'core/labelTTF/CCLabelTTF.js',
 70         'core/CCActionManager.js',
 71         'kazmath/utility.js',
 72         'kazmath/vec2.js',
 73         'kazmath/vec3.js',
 74         'kazmath/vec4.js',
 75         'kazmath/ray2.js',
 76         'kazmath/mat3.js',
 77         'kazmath/mat4.js',
 78         'kazmath/plane.js',
 79         'kazmath/quaternion.js',
 80         'kazmath/aabb.js',
 81         'kazmath/GL/mat4stack.js',
 82         'kazmath/GL/matrix.js',
 83         'shaders/CCShaders.js',
 84         'shaders/CCShaderCache.js',
 85         'shaders/CCGLProgram.js',
 86         'shaders/CCGLStateCache.js',
 87         'render_texture/CCRenderTexture.js',
 88         'motion_streak/CCMotionStreak.js',
 89         'clipping_nodes/CCClippingNode.js',
 90         'effects/CCGrid.js',
 91         'effects/CCGrabber.js',
 92         'shape_nodes/CCDrawNode.js',
 93         'actions/CCAction.js',
 94         'actions/CCActionInterval.js',
 95         'actions/CCActionInstant.js',
 96         'actions/CCActionCamera.js',
 97         'actions/CCActionEase.js',
 98         'actions/CCActionCatmullRom.js',
 99         'actions/CCActionTween.js',
100         'actions3d/CCActionGrid.js',
101         'actions3d/CCActionGrid3D.js',
102         'actions3d/CCActionTiledGrid.js',
103         'actions3d/CCActionPageTurn3D.js',
104         'progress_timer/CCProgressTimer.js',
105         'progress_timer/CCActionProgressTimer.js',
106         'transitions_nodes/CCTransition.js',
107         'transitions_nodes/CCTransitionProgress.js',
108         'transitions_nodes/CCTransitionPageTurn.js',
109         'label_nodes/CCLabelAtlas.js',
110         'label_nodes/CCLabelBMFont.js',
111         'compress/ZipUtils.js',
112         'compress/base64.js',
113         'compress/gzip.js',
114         'compress/zlib.min.js',
115         'particle_nodes/CCFormatHelper.js',
116         'particle_nodes/CCPNGReader.js',
117         'particle_nodes/CCTIFFReader.js',
118         'particle_nodes/CCParticleSystem.js',
119         'particle_nodes/CCParticleExamples.js',
120         'particle_nodes/CCParticleBatchNode.js',
121         'touch_dispatcher/CCTouchDelegateProtocol.js',
122         'touch_dispatcher/CCTouchHandler.js',
123         'touch_dispatcher/CCTouchDispatcher.js',
124         'touch_dispatcher/CCMouseDispatcher.js',
125         'keyboard_dispatcher/CCKeyboardDelegate.js',
126         'keyboard_dispatcher/CCKeyboardDispatcher.js',
127         'accelerometer/CCAccelerometer.js',
128         'text_input_node/CCIMEDispatcher.js',
129         'text_input_node/CCTextFieldTTF.js',
130         'menu_nodes/CCMenuItem.js',
131         'menu_nodes/CCMenu.js',
132         'tileMap_nodes/CCTGAlib.js',
133         'tileMap_nodes/CCTMXTiledMap.js',
134         'tileMap_nodes/CCTMXXMLParser.js',
135         'tileMap_nodes/CCTMXObjectGroup.js',
136         'tileMap_nodes/CCTMXLayer.js',
137         'parallax_nodes/CCParallaxNode.js',
138         'audio/SimpleAudioEngine.js',
139 
140         // useless
141         'CCUserDefault.js',
142         'CCImage.js'
143 
144     ];
145 
146     var d = document;
147     var c = d["ccConfig"];
148 
149     if (c.loadExtension != null && c.loadExtension == true) {
150         engine = engine.concat([
151             '../extensions/GUI/CCControlExtension/CCControl.js',
152             '../extensions/GUI/CCControlExtension/CCControlButton.js',
153             '../extensions/GUI/CCControlExtension/CCControlUtils.js',
154             '../extensions/GUI/CCControlExtension/CCInvocation.js',
155             '../extensions/GUI/CCControlExtension/CCScale9Sprite.js',
156             '../extensions/GUI/CCControlExtension/CCMenuPassive.js',
157             '../extensions/GUI/CCControlExtension/CCControlSaturationBrightnessPicker.js',
158             '../extensions/GUI/CCControlExtension/CCControlHuePicker.js',
159             '../extensions/GUI/CCControlExtension/CCControlColourPicker.js',
160             '../extensions/GUI/CCControlExtension/CCControlSlider.js',
161             '../extensions/GUI/CCControlExtension/CCControlSwitch.js',
162             '../extensions/GUI/CCControlExtension/CCControlStepper.js',
163             '../extensions/GUI/CCControlExtension/CCControlPotentiometer.js',
164             '../extensions/GUI/CCScrollView/CCScrollView.js',
165             '../extensions/GUI/CCScrollView/CCSorting.js',
166             '../extensions/GUI/CCScrollView/CCTableView.js',
167             '../extensions/CCBReader/CCNodeLoader.js',
168             '../extensions/CCBReader/CCBReaderUtil.js',
169             '../extensions/CCBReader/CCControlLoader.js',
170             '../extensions/CCBReader/CCSpriteLoader.js',
171             '../extensions/CCBReader/CCNodeLoaderLibrary.js',
172             '../extensions/CCBReader/CCBReader.js',
173             '../extensions/CCBReader/CCBValue.js',
174             '../extensions/CCBReader/CCBKeyframe.js',
175             '../extensions/CCBReader/CCBSequence.js',
176             '../extensions/CCBReader/CCBRelativePositioning.js',
177             '../extensions/CCBReader/CCBAnimationManager.js',
178             '../extensions/CCEditBox/CCdomNode.js',
179             '../extensions/CCEditBox/CCEditBox.js',
180 
181             '../extensions/CocoStudio/Components/CCComponent.js',
182             '../extensions/CocoStudio/Components/CCComponentContainer.js',
183             '../extensions/CocoStudio/CocoStudio.js',
184             // CocoStudio Armature
185             '../extensions/CocoStudio/Armature/utils/CCArmatureDefine.js',
186             '../extensions/CocoStudio/Armature/utils/CCDataReaderHelper.js',
187             '../extensions/CocoStudio/Armature/utils/CCSpriteFrameCacheHelper.js',
188             '../extensions/CocoStudio/Armature/utils/CCTransformHelp.js',
189             '../extensions/CocoStudio/Armature/utils/CCTweenFunction.js',
190             '../extensions/CocoStudio/Armature/utils/CCUtilMath.js',
191             '../extensions/CocoStudio/Armature/utils/CCArmatureDataManager.js',
192             '../extensions/CocoStudio/Armature/datas/CCDatas.js',
193             '../extensions/CocoStudio/Armature/display/CCDecorativeDisplay.js',
194             '../extensions/CocoStudio/Armature/display/CCDisplayFactory.js',
195             '../extensions/CocoStudio/Armature/display/CCDisplayManager.js',
196             '../extensions/CocoStudio/Armature/display/CCSkin.js',
197             '../extensions/CocoStudio/Armature/animation/CCProcessBase.js',
198             '../extensions/CocoStudio/Armature/animation/CCArmatureAnimation.js',
199             '../extensions/CocoStudio/Armature/animation/CCTween.js',
200             '../extensions/CocoStudio/Armature/physics/CCColliderDetector.js',
201             '../extensions/CocoStudio/Armature/CCArmature.js',
202             '../extensions/CocoStudio/Armature/CCBone.js',
203             // CocoStudio Action
204             '../extensions/CocoStudio/Action/CCActionFrame.js',
205             '../extensions/CocoStudio/Action/CCActionManager.js',
206             '../extensions/CocoStudio/Action/CCActionNode.js',
207             '../extensions/CocoStudio/Action/CCActionObject.js',
208             // CocoStudio Components
209             '../extensions/CocoStudio/Components/CCComAttribute.js',
210             '../extensions/CocoStudio/Components/CCComAudio.js',
211             '../extensions/CocoStudio/Components/CCComController.js',
212             '../extensions/CocoStudio/Components/CCComRender.js',
213             // CocoStudio Trigger
214             '../extensions/CocoStudio/Trigger/ObjectFactory.js',
215             '../extensions/CocoStudio/Trigger/TriggerBase.js',
216             '../extensions/CocoStudio/Trigger/TriggerMng.js',
217             '../extensions/CocoStudio/Trigger/TriggerObj.js',
218             // CocoStudio GUI
219             '../extensions/CocoStudio/GUI/BaseClasses/UIWidget.js',
220             '../extensions/CocoStudio/GUI/Layouts/UILayout.js',
221             '../extensions/CocoStudio/GUI/Layouts/UILayoutParameter.js',
222             '../extensions/CocoStudio/GUI/Layouts/UILayoutDefine.js',
223             '../extensions/CocoStudio/GUI/System/CocosGUI.js',
224             '../extensions/CocoStudio/GUI/System/UIHelper.js',
225             '../extensions/CocoStudio/GUI/System/UILayer.js',
226             '../extensions/CocoStudio/GUI/UIWidgets/UIButton.js',
227             '../extensions/CocoStudio/GUI/UIWidgets/UICheckBox.js',
228             '../extensions/CocoStudio/GUI/UIWidgets/UIImageView.js',
229             '../extensions/CocoStudio/GUI/UIWidgets/UILabel.js',
230             '../extensions/CocoStudio/GUI/UIWidgets/UILabelAtlas.js',
231             '../extensions/CocoStudio/GUI/UIWidgets/UILabelBMFont.js',
232             '../extensions/CocoStudio/GUI/UIWidgets/UILoadingBar.js',
233             '../extensions/CocoStudio/GUI/UIWidgets/UISlider.js',
234             '../extensions/CocoStudio/GUI/UIWidgets/UISwitch.js',
235             '../extensions/CocoStudio/GUI/UIWidgets/UITextField.js',
236             '../extensions/CocoStudio/GUI/UIWidgets/Compatible/CompatibleClasses.js',
237             '../extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.js',
238             '../extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIListView.js',
239             '../extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIPageView.js',
240             '../extensions/CocoStudio/Reader/GUIReader.js',
241             '../extensions/CocoStudio/Reader/SceneReader.js'
242 
243         ]);
244     }
245 
246     if (c.loadPluginx != null && c.loadPluginx == true) {
247         engine = engine.concat([
248             //protocols
249             '../extensions/PluginX/protocols/Config.js',
250             '../extensions/PluginX/protocols/PluginUtils.js',
251             '../extensions/PluginX/protocols/PluginProtocol.js',
252             '../extensions/PluginX/protocols/ProtocolSocial.js',
253             //'../extensions/PluginX/protocols/ProtocolAds.js',
254             //'../extensions/PluginX/protocols/ProtocolAnalytics.js',
255             //'../extensions/PluginX/protocols/ProtocolIAP.js',
256             '../extensions/PluginX/protocols/PluginFactory.js',
257             '../extensions/PluginX/protocols/PluginManager.js',
258 
259             //plugins
260             '../extensions/PluginX/plugins/SocialWeibo.js',
261             '../extensions/PluginX/plugins/SocialQQWeibo.js',
262             '../extensions/PluginX/plugins/SocialQzone.js',
263             '../extensions/PluginX/plugins/SocialTwitter.js',
264             '../extensions/PluginX/plugins/SocialFacebook.js'
265             //'../extensions/PluginX/plugins/AdsGoogle.js'
266         ]);
267     }
268 
269     if (!c.engineDir) {
270         engine = [];
271     }
272     else {
273         if(c.box2d || c.chipmunk){
274             engine.push('physics_nodes/CCPhysicsSprite.js');
275             engine.push('physics_nodes/CCPhysicsDebugNode.js');
276             if (c.box2d === true)
277                 engine.push('../external/box2d/box2d.js');
278             if (c.chipmunk === true)
279                 engine.push('../external/chipmunk/chipmunk.js');
280         }
281         engine.forEach(function (e, i) {
282             engine[i] = c.engineDir + e;
283         });
284     }
285     if (typeof c.box2d === "string") {
286         engine.push(c.box2d);
287     }
288     if (typeof c.chipmunk === "string") {
289         engine.push(c.chipmunk);
290     }
291 
292     var loadJsImg = document.getElementById("cocos2d_loadJsImg");
293     if(!loadJsImg){
294         loadJsImg = document.createElement('img');
295         loadJsImg.src = "data:image/gif;base64,R0lGODlhEAAQALMNAD8/P7+/vyoqKlVVVX9/fxUVFUBAQGBgYMDAwC8vL5CQkP///wAAAP///wAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFAAANACwAAAAAEAAQAAAEO5DJSau9OOvNex0IMnDIsiCkiW6g6BmKYlBFkhSUEgQKlQCARG6nEBwOgl+QApMdCIRD7YZ5RjlGpCUCACH5BAUAAA0ALAAAAgAOAA4AAAQ6kLGB0JA4M7QW0hrngRllkYyhKAYqKUGguAws0ypLS8JxCLQDgXAIDg+FRKIA6v0SAECCBpXSkstMBAAh+QQFAAANACwAAAAACgAQAAAEOJDJORAac6K1kDSKYmydpASBUl0mqmRfaGTCcQgwcxDEke+9XO2WkxQSiUIuAQAkls0n7JgsWq8RACH5BAUAAA0ALAAAAAAOAA4AAAQ6kMlplDIzTxWC0oxwHALnDQgySAdBHNWFLAvCukc215JIZihVIZEogDIJACBxnCSXTcmwGK1ar1hrBAAh+QQFAAANACwAAAAAEAAKAAAEN5DJKc4RM+tDyNFTkSQF5xmKYmQJACTVpQSBwrpJNteZSGYoFWjIGCAQA2IGsVgglBOmEyoxIiMAIfkEBQAADQAsAgAAAA4ADgAABDmQSVZSKjPPBEDSGucJxyGA1XUQxAFma/tOpDlnhqIYN6MEAUXvF+zldrMBAjHoIRYLhBMqvSmZkggAIfkEBQAADQAsBgAAAAoAEAAABDeQyUmrnSWlYhMASfeFVbZdjHAcgnUQxOHCcqWylKEohqUEAYVkgEAMfkEJYrFA6HhKJsJCNFoiACH5BAUAAA0ALAIAAgAOAA4AAAQ3kMlJq704611SKloCAEk4lln3DQgyUMJxCBKyLAh1EMRR3wiDQmHY9SQslyIQUMRmlmVTIyRaIgA7";
296 
297         var canvasNode = document.getElementById(c.tag);
298         canvasNode.style.backgroundColor = "black";
299         canvasNode.parentNode.appendChild(loadJsImg);
300         
301         var canvasStyle = getComputedStyle?getComputedStyle(canvasNode):canvasNode.currentStyle;
302         loadJsImg.style.left = canvasNode.offsetLeft + (parseFloat(canvasStyle.width) - loadJsImg.width)/2 + "px";
303         loadJsImg.style.top = canvasNode.offsetTop + (parseFloat(canvasStyle.height) - loadJsImg.height)/2 + "px";
304         loadJsImg.style.position = "absolute";
305     }
306     
307     var updateLoading = function(p){
308         if(p>=1) {
309             loadJsImg.parentNode.removeChild(loadJsImg);
310         }
311     };
312 
313     var loaded = 0;
314     var que = engine.concat(c.appFiles);
315     que.push('main.js');
316 
317     if (navigator.userAgent.indexOf("Trident/5") > -1) {
318         //ie9
319         var i = -1;
320         var loadNext = function () {
321             i++;
322             if (i < que.length) {
323                 var f = d.createElement('script');
324                 f.src = que[i];
325                 f.addEventListener('load',function(){
326                     loadNext();
327                     updateLoading(loaded / que.length);
328                     this.removeEventListener('load', arguments.callee, false);
329                 },false);
330                 d.body.appendChild(f);
331             }
332             updateLoading(i / (que.length - 1));
333         };
334         loadNext();
335     }
336     else {
337         que.forEach(function (f, i) {
338             var s = d.createElement('script');
339             s.async = false;
340             s.src = f;
341             s.addEventListener('load',function(){
342                 loaded++;
343                 updateLoading(loaded / que.length);
344                 this.removeEventListener('load', arguments.callee, false);
345             },false);
346             d.body.appendChild(s);
347         });
348     }
349 })();
350