var touch,__extends=this&&this.__extends||function(){var e=function(i,t){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(e[t]=i[t])})(i,t)};return function(i,t){function n(){this.constructor=i}if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");e(i,t),i.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}}();!function(e){var i=function(i){function t(){var e=i.call(this)||this;return e._gameScene=null,e._scene=null,e._indexView=null,e._gameView=null,e._rewardTipView=null,e._settingDialog=null,e._tipDialog=null,e._skinDialog=null,e._awardDialog=null,e._matchDialog=null,e._inited=!1,e}return __extends(t,i),Object.defineProperty(t,"instance",{get:function(){return t._inst||(t._inst=new t),t._inst},enumerable:!1,configurable:!0}),t.prototype.init=function(){this._inited||(this._inited=!0,e.CustomMaterial.precompile(),e.GameData.instance.init(this.onInited.bind(this)))},t.prototype.onInited=function(i){e.GameData.instance.loadAdjust(this.onConfigReady.bind(this))},t.prototype.onConfigReady=function(i){console.info("===> Config Loaded"),e.TaskManager.instance.init(),e.SkinManager.init(),SdkHelper.SdkUtils.init(),SdkHelper.EventLogger.init(),this.on(e.GameEvent.ENTER_MULTIPLE_PLAYER_GAME,this,this.onEnterMultiplePlayerGame),this.on(e.GameEvent.ENTER_SINGLE_GAME,this,this.onEnterSinglePlayerGame),this.on(e.GameEvent.BACK,this,this.onBack),this.on(e.GameEvent.GAME_OVER,this,this.onGameOver),this.on(e.GameEvent.SHOW_REWARD,this,this.showSkinReward),this.on(e.GameEvent.HIDE_REWARD,this,this.onHideReward),this.on(e.GameEvent.OPEN_SETTING,this,this.onSetting),this.on(e.GameEvent.OPEN_TIP,this,this.onTip),this.on(e.GameEvent.OPEN_SKIN,this,this.showSkin),this.on(e.GameEvent.OPEN_GIFT,this,this.showGift),this.on(e.GameEvent.CLOSE_SKIN,this,this.closeSkin),this.on(e.GameEvent.MATCH_OVER,this,this.closeMatchDialog),this.on(e.GameEvent.START_AGAIN,this,this.onStartAgain),this.on(e.GameEvent.TASK_FINISHED,this,this.onTaskFinished),this.on(e.GameEvent.GAME_SCENE_READY,this,this.onGameSceneReady),Laya.stage.on(Laya.Event.RESIZE,this,this.onResize),this.onResize(),this._scene=new Laya.Scene,Laya.stage.addChild(this._scene),this.startGame(),e.GameFactory.instance.preloadResource(this._scene)},t.prototype.onResize=function(){GameBaseData.refreshScreenSize()},t.prototype.startGame=function(){this.startOldGame(),Laya.timer.loop(1e3,this,this.onTimeLoop)},t.prototype.onGameSceneReady=function(){this._indexView&&(this._indexView.showPlayButtons(this._gameScene.isReady),this._indexView.showLoading(!this._gameScene.isReady))},t.prototype.startOldGame=function(){this._gameScene=new e.GameScene(this,this._scene),this.showIndexView()},t.prototype.startGame2=function(){game2.GameConfig2.init();var e=new game2.GameControl;e.preloadResource(void 0,function(i){console.info("==> Resource Ready"),e.prepareMaterials(),e.setupScene()}),e.initScene()},t.prototype.destroy=function(){console.warn("!!SHOULD NOT DESTROY GAME MODULE!!"),t._inst=null,Laya.timer.clear(this,this.onTimeLoop),this.off(e.GameEvent.ENTER_MULTIPLE_PLAYER_GAME,this,this.onEnterMultiplePlayerGame),this.off(e.GameEvent.ENTER_SINGLE_GAME,this,this.onEnterSinglePlayerGame),this.off(e.GameEvent.BACK,this,this.onBack),this.off(e.GameEvent.GAME_OVER,this,this.onGameOver),this.off(e.GameEvent.SHOW_REWARD,this,this.showSkinReward),this.off(e.GameEvent.HIDE_REWARD,this,this.onHideReward),this.off(e.GameEvent.OPEN_SETTING,this,this.onSetting),this.off(e.GameEvent.OPEN_TIP,this,this.onTip),this.off(e.GameEvent.OPEN_SKIN,this,this.showSkin),this.off(e.GameEvent.OPEN_GIFT,this,this.showGift),this.off(e.GameEvent.CLOSE_SKIN,this,this.closeSkin),this.off(e.GameEvent.MATCH_OVER,this,this.closeMatchDialog),this.off(e.GameEvent.START_AGAIN,this,this.onStartAgain),this.off(e.GameEvent.TASK_FINISHED,this,this.onTaskFinished),this.off(e.GameEvent.GAME_SCENE_READY,this,this.onGameSceneReady),this.hideIndexView(),this.hideGameView(),this.onHideReward(),this.closeMatchDialog(),null!=this._settingDialog&&(this._settingDialog.destroy(),this._settingDialog=null),Laya.stage.on(Laya.Event.RESIZE,this,this.onResize)},t.prototype.showIndexView=function(){null==this._indexView&&(this._indexView=new e.IndexView(this),Laya.stage.addChild(this._indexView),this._indexView.showPlayButtons(this._gameScene.isReady),this._indexView.showLoading(!this._gameScene.isReady))},t.prototype.hideIndexView=function(){null!=this._indexView&&(this._indexView.removeSelf(),this._indexView.destroy(),this._indexView=null)},t.prototype.showGameView=function(){null==this._gameView&&(this._gameView=new e.GameView(this),Laya.stage.addChild(this._gameView),GameBaseData.isShowGameView=!0),this._gameScene&&this._gameScene.showBall(!0)},t.prototype.hideGameView=function(){null!=this._gameView&&(this._gameView.removeSelf(),this._gameView.destroy(),this._gameView=null,GameBaseData.isShowGameView=!1)},t.prototype.onEnterMultiplePlayerGame=function(){GameBaseData.isDebug&&console.log("开始游戏1"),e.TipDialog.gameTimes++,GameBaseData.newMatch(GAME_MODE.MULTIPLE_PLAYER),e.SoundManager.playMusic("res/sounds/bgm_low.mp3",!0),e.GameDefine.AI_COUNT=4,console.info("Set AI: ",e.GameDefine.AI_COUNT),this.hideIndexView(),this.showMatchDialog(),SdkHelper.EventLogger.logGameStart(GameBaseData.currentGameMode)},t.prototype.onEnterSinglePlayerGame=function(){GameBaseData.isDebug&&console.log("开始游戏2"),e.TipDialog.gameTimes++,GameBaseData.newMatch(GAME_MODE.SINGLE_PLAYER),e.SoundManager.playMusic("res/sounds/bgm_low.mp3",!0),this.hideIndexView(),this.showGameView(),console.info("Set AI: ",e.GameDefine.AI_COUNT),SdkHelper.EventLogger.logGameStart(GameBaseData.currentGameMode)},t.prototype.onBack=function(){this.hideGameView(),this.showIndexView()},t.prototype.onGameOver=function(i){0==e.GameData.instance.skinIndex&&(e.GameData.instance.randomSkinIndex(),this.event(e.GameEvent.CHANGE_SKIN))},t.prototype.onShowReward=function(i,t,n,a){this.onHideReward(),this._rewardTipView=new e.RewardTipView(this),this._rewardTipView.imgIcon.skin=i,this._rewardTipView.tfImage.visible=!1,this._rewardTipView.tfNum.text=t.toString(),n&&(this._rewardTipView.tfImage.visible=!0),a&&this._rewardTipView.showDoubleGet(),this._rewardTipView.zOrder=1e3,Laya.stage.addChild(this._rewardTipView)},t.prototype.showSkinReward=function(i){e.NewAwardDialog.showSkinAwards(i)},t.prototype.onHideReward=function(){null!=this._rewardTipView&&(this._rewardTipView.removeSelf(),this._rewardTipView.destroy(),this._rewardTipView=null)},t.prototype.onSetting=function(){null==this._settingDialog&&(this._settingDialog=new e.SettingDialog(this)),this._settingDialog.popup(null,!1)},t.prototype.onTip=function(i){null==this._tipDialog&&(this._tipDialog=new e.TipDialog(this)),this._tipDialog.onSetType(i),this._tipDialog.popup()},t.prototype.showSkin=function(){null==this._skinDialog&&(this._skinDialog=new e.SkinDialog(this,e.GameFactory.instance.getAllSkins())),this._skinDialog.popup(null,!1)},t.prototype.showGift=function(){null==this._awardDialog&&(this._awardDialog=new e.AwardDialog(this)),this._awardDialog.updateOnlineReward(),this._awardDialog.popup(null,!1)},t.prototype.closeSkin=function(){null!=this._skinDialog&&(this._skinDialog.close("",!1),this._skinDialog.destroy(),this._skinDialog=null)},t.prototype.onTimeLoop=function(){e.GameData.instance.onlineTime++},t.prototype.showMatchDialog=function(){null==this._matchDialog&&(this._matchDialog=new e.MatchDialog(this)),this._matchDialog.popup(null,!1)},t.prototype.closeMatchDialog=function(){this.showGameView(),null!=this._matchDialog&&(this._matchDialog.close("",!1),this._matchDialog.destroy(),this._matchDialog=null)},t.prototype.onStartAgain=function(){SdkHelper.EventLogger.logGameStart(GameBaseData.currentGameMode),GameBaseData.isDebug&&console.log("再来一局"),GameBaseData.rematch(),e.TipDialog.gameTimes++,e.SoundManager.playMusic("res/sounds/bgm_low.mp3",!0),this.hideGameView(),GameBaseData.isSinglePlayerMode?(this.showGameView(),SdkHelper.EventLogger.logPlaySingle(),SdkHelper.EventLogger.logPlaySingleWithTimes()):(this.showMatchDialog(),e.GameDefine.AI_COUNT=4,SdkHelper.EventLogger.logPlayMulti(),SdkHelper.EventLogger.logPlayMultiWithTimes())},t.prototype.onTaskFinished=function(i){console.info("Task Finished: ",e.TaskManager.getTaskDesc(i)),i.rewardType==e.REWARD_TYPE.SKIN&&e.SkinManager.unlockSkin(i.rewardValue,!0)&&(e.SkinManager.save(),this.event(e.GameEvent.SKIN_UNLOCkED,i.rewardValue))},t}(Laya.EventDispatcher);e.GameModule=i}(touch||(touch={}));