/****************************************************************** * * 桥接:核心流程管理 * ******************************************************************/ const BridgeController = require( "bridge.controller" ); const BDef = require( "bridge.define" ); const RoleController = require( "role_controller" ); const BridgeGame = cc.Class( { extends: BridgeController, // 初始化配置数据 initConfig: function() { // 全局支持 nx.bridge.game = this; }, // 注册监听事件 registerEvents: function() { }, // 注册协议接受事件 registerProtocals: function() { this.RegisterProtocal( 10300, this.onGameReady ); // 前端准备完毕 this.RegisterProtocal( 10304, this.onEnterGame ); // 显示主场景(登录成功) this.RegisterProtocal( 10370, this.onGameReadyDone ); // 登录推送数据完成 this.RegisterProtocal( 10810, this.on10810 ); // BUG反馈处理 this.RegisterProtocal( 10996, this.onVerifyVersion ); // 版本验证 }, // 前端准备完毕 gameReady: function( _cb ) { nx.debug( "$GAME:前端准备完毕!" ); this.cbDone = _cb; this.SendProtocal( 10300, {}, ( _ret, _data ) => { if( !_ret ) { nx.dt.fnInvoke( _cb, _ret, _data ); this.cbDone = null; return; } } ); }, // 前端准备完毕 onGameReady: function( _data ) { // TODO... }, // 开服天数推送(首次标记代表登录推送数据完成) onGameReadyDone: function( _data ) { if( !_data || _data.first != 1 ) { return; } // 推送完成,所有模块初始化 nx.debug( "$GAME:推送完成,准备初始化模块..." ); nx.dt.fnInvoke( this.cbDone, true ); this.cbDone = null; }, // 进入主场景 enterGame: function() { // 首次进入引导 let role = RoleController.getInstance().getRoleVo(); if( role && role.lev <= 1 && nx.dt.arrEmpty( nx.bridge.plot.records.ids ) ) { nx.debug( "$GAME:进入首次引导场景..." ); nx.bridge.setGS( BDef.GameStage.First ); return; } // 进入主场景 nx.debug( "$GAME:进入主场景..." ); nx.bridge.setGS( BDef.GameStage.Game ); }, // 显示主场景(登录成功) onEnterGame: function( _data ) { nx.debug( "$GAME:正式进入游戏!" ); // 请求数据通告 let flag = nx.bridge.vget( "RoleReady" ); nx.bridge.vset( "RoleReady", flag + 1 ); }, // ================================================================= // 核心步骤 // ================================================================= // 初始化所有模块 initModules: function( _cb ) { // 基础模块 nx.bridge.mods.initModules( ( _ret, _data ) => { nx.dt.fnInvoke( _cb, _ret, _data ); } ); }, // ================================================================= // BUG反馈 // ================================================================= // 发送反馈信息 reqCommitIssue: function( issue_type, title, content, _cb ) { var protocal = {}; protocal.issue_type = issue_type; protocal.title = title; protocal.content = content; this.SendProtocal( 10810, protocal, _cb ); }, // 反馈结果 on10810: function( data ) { if( data && nx.dt.strNEmpty( data.msg ) ) { nx.tbox( data.msg ); } }, // 版本验证 onVerifyVersion: function( _data ) { if( !_data || !_data.cli_ver_list ) { return; } // 渠道验证 let info = null; let cname = nx.bridge.vget( "channelName"); let list = _data.cli_ver_list || []; for( let i = 0; i < list.length; ++i ) { if( list[i].sdk == cname ) { info = list[i]; break; } } // 验证参数更新 if( info ) { nx.bridge.vset( "matVersion", info.cli_ver || "" ); } }, } ); module.exports = BridgeGame;