499 lines
12 KiB
JavaScript
499 lines
12 KiB
JavaScript
|
|
/*******************************************************************************
|
|
*
|
|
* Nx老项目桥接
|
|
*
|
|
*
|
|
* 2021.12.10
|
|
******************************************************************************/
|
|
|
|
const CFG = require( "config" );
|
|
const NxMod = require( "nx.mod" );
|
|
const BDef = require( "bridge.define" );
|
|
const PathTool = require( "pathtool" );
|
|
const FFSDK = require( "ff_sdk" );
|
|
const FFMisc = require( "misc_help" );
|
|
const { CFMap } = require( "bridge.conditions" );
|
|
|
|
const NxBridge = cc.Class( {
|
|
|
|
extends: NxMod,
|
|
|
|
name: "NxBridge",
|
|
|
|
// 初始化
|
|
initialize: function( _args ) {
|
|
|
|
// 初始化
|
|
if( !this._super( _args ) ) {
|
|
cc.error( "初始化NX框架失败!" );
|
|
return false;
|
|
}
|
|
|
|
// 视图创建
|
|
nx.plugin.add( this, [ "view" ] );
|
|
this.vbuild( BDef.ViewBridge );
|
|
|
|
// 界面集合
|
|
this.panels = {};
|
|
// tag2回溯界面
|
|
this.setTag2Infos = [];
|
|
// 初始参数解析
|
|
this.sdkConfigs();
|
|
|
|
return true;
|
|
},
|
|
|
|
// 销毁
|
|
uninitialize: function() {
|
|
|
|
// USPER
|
|
return this._super();
|
|
},
|
|
|
|
// 初始参数解析
|
|
sdkConfigs: function() {
|
|
|
|
let info = FFSDK.getInstance().init() || {};
|
|
nx.frame.vset( "DebugOpen", CC_DEBUG );
|
|
nx.frame.vset( "Platform", FFMisc.getInstance().getPlatformName() );
|
|
nx.frame.vset( "DeviceID", info.deviceId || nx.sdk.getDeviceID() );
|
|
nx.frame.vset( "ApkName", info.appName || "" );
|
|
nx.frame.vset( "ApkVersion", info.appVersion || nx.sdk.getPackVersion() );
|
|
nx.frame.vset( "LocalLanguage", info.lang || CFG.DesignLanguage );
|
|
nx.frame.vset( "IDFA", info.idfa || "" );
|
|
nx.frame.vset( "NetType", info.netType || "4g" );
|
|
nx.frame.vset( "Simulator", info.simulator == "1" );
|
|
nx.frame.vset( "Host", info.ip || "0.0.0.0" );
|
|
nx.frame.vset( "hMode", info.hMode == "1" );
|
|
nx.frame.vset( "GUUID", info.gUUID || CFG.GName );
|
|
|
|
console.log( "APK:" + JSON.stringify( info ) );
|
|
// 日志
|
|
let llv = parseInt( info.logLv || "2" );
|
|
if( CC_DEBUG ) {
|
|
llv = 0;
|
|
}
|
|
nx.frame.vset( "LogLevel", llv );
|
|
nx.logger.setLevel( llv );
|
|
|
|
this.vset( "gname", info.gameName || CFG.GName );
|
|
this.vset( "channel", info.channelId || nx.dt.queryURLArg( "ch" ) || CFG.Channel );
|
|
this.vset( "channelName", info.channelName || CFG.Platform );
|
|
this.vset( "gm", info.openGM == "1" );
|
|
this.vset( "ssl", parseInt( info.ssl ) == 1 );
|
|
this.vset( "hideSwitch", parseInt( info.hideSwitch || "0" ) != 0 );
|
|
this.vset( "enableGuest", parseInt( info.enableGuest || "0" ) != 0 );
|
|
this.vset( "gmUrl", info.gmUrl || "" );
|
|
this.vset( "socialUrl", info.socialUrl || "" );
|
|
this.vset( "phpUrls", info.php || CFG.PHPs );
|
|
|
|
// 汇率
|
|
this.vset( "excRates", {
|
|
name: info.currency_name || "¥",
|
|
mult: parseInt( info.currency_multiple || "1" ),
|
|
divi: parseInt( info.currency_division || "1" ),
|
|
round: ( 0 != parseInt( info.currency_round || "1" ) )
|
|
} );
|
|
|
|
// GM开关
|
|
if( CC_DEBUG && cc.sys.isBrowser ) {
|
|
this.vset( "gm", true );
|
|
}
|
|
|
|
// MAC调试
|
|
// if( cc.sys.os == cc.sys.OS_OSX ) {
|
|
// this.vset( "gm", true );
|
|
// nx.frame.vset( "hMode", true );
|
|
// nx.warn( "$Bridge:MAC调试开启" );
|
|
// }
|
|
|
|
},
|
|
|
|
// 桥接服务初始化
|
|
initMods: function() {
|
|
|
|
// 桥接服务
|
|
nx.factory.createService( "bridge.remote" );
|
|
nx.factory.createService( "bridge.mods" );
|
|
|
|
// 工具服务
|
|
this.partner = require( "bridge.partner" );
|
|
this.jumper = require( "bridge.jumper" );
|
|
this.condition = require( "bridge.conditions" );
|
|
this.attrs = require( "bridge.attributes" );
|
|
this.time = require( "bridge.time" );
|
|
this.cmd = require( "bridge.cmd" );
|
|
|
|
},
|
|
|
|
// 桥接服务销毁
|
|
uninitMods: function() {
|
|
|
|
nx.factory.remove( nx.bridge.remote );
|
|
|
|
// 工具服务
|
|
this.partner = null;
|
|
this.jumper = null;
|
|
this.condition = null;
|
|
this.attrs = null;
|
|
this.time = null;
|
|
this.cmd = null;
|
|
|
|
},
|
|
|
|
// 语种设置
|
|
setLang: function( _key ) {
|
|
let key = _key || CFG.DesignLanguage;
|
|
nx.setLocLanguage( key );
|
|
},
|
|
|
|
// 设置游戏阶段
|
|
setGS: function( _stage, _args ) {
|
|
|
|
let old = this.vget( "GS" );
|
|
if( old == _stage ) {
|
|
nx.warn( "$Bridge:GS重复 ", _stage );
|
|
return;
|
|
}
|
|
|
|
// 切换中
|
|
if( this.gsDoing ) {
|
|
nx.error( "$Bridge:GS更改失败,尚在进行 %s -> %s", old, _stage );
|
|
return;
|
|
}
|
|
|
|
nx.debug( "$Bridge:GS更改 %s -> %s", old, _stage );
|
|
this.vset( "GSArgs", _args || {} );
|
|
this.vset( "GS", _stage );
|
|
|
|
// 统计新阶段展示UI
|
|
let wid1 = BDef.StageScene[ _stage ];
|
|
if( nx.dt.strEmpty( wid1 ) ) {
|
|
nx.warn( "$Bridge:GS对应界面缺失: %s", _stage );
|
|
return;
|
|
}
|
|
|
|
// 新界面展示
|
|
this.createPanel( wid1, _args );
|
|
|
|
// 延迟关闭老阶段UI
|
|
let wid2 = BDef.StageScene[ old ];
|
|
if( nx.dt.strNEmpty( wid2 ) ) {
|
|
setTimeout( () => {
|
|
this.closePanel( wid2 );
|
|
}, 1 );
|
|
}
|
|
|
|
},
|
|
|
|
// ================================================================
|
|
//
|
|
// 注册一些快捷方法
|
|
//
|
|
// ================================================================
|
|
|
|
//子节点全部销毁
|
|
NodeChidrenDestroy(parNode){
|
|
if(parNode instanceof cc.Node){
|
|
if(parNode.children){
|
|
for(let i in parNode.children){
|
|
if(parNode.children[i].destroy){
|
|
parNode.children[i].destroy();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
// 条件检查
|
|
checkConditions: function( _conds ) {
|
|
|
|
// 参数无效
|
|
if( nx.dt.arrEmpty( _conds ) ) {
|
|
return {};
|
|
}
|
|
|
|
// 条件参数规范
|
|
// 如果参数是一维数组[key,val],则转为二维数组[[key,val],[key,val]]
|
|
let conds = _conds;
|
|
if( !nx.dt.arrGood( conds[ 0 ] ) ) {
|
|
conds = [ _conds ];
|
|
}
|
|
|
|
let ret = {};
|
|
for( let i in conds ) {
|
|
|
|
let item = conds[ i ];
|
|
let func = CFMap[ item[ 0 ] ];
|
|
if( !nx.dt.fnGood( func ) ) {
|
|
nx.error( "解锁条件未识别:", item[ 0 ] );
|
|
continue;
|
|
}
|
|
|
|
let desc = func( item[ 1 ] );
|
|
if( nx.dt.strNEmpty( desc ) ) {
|
|
ret = { key: item[ 0 ], val: item[ 1 ], desc: desc };
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
},
|
|
|
|
// 快速图标设置
|
|
setIcon: function( _refnode, _names, _icon, _badPath ) {
|
|
|
|
let path = PathTool.queryIconPath( _icon );
|
|
nx.gui.setSpriteFrame( _refnode, _names, path, ( _ret ) => {
|
|
if( !_ret ) {
|
|
nx.gui.setSpriteFrame( _refnode, _names, _badPath || PathTool.BadIcon );
|
|
}
|
|
} );
|
|
},
|
|
|
|
// 快速小图标设置
|
|
setIconS: function( _refnode, _names, _icon, _badPath ) {
|
|
|
|
let path = PathTool.querySmallIconPath( _icon );
|
|
nx.gui.setSpriteFrame( _refnode, _names, path, ( _ret ) => {
|
|
if( !_ret ) {
|
|
nx.gui.setSpriteFrame( _refnode, _names, _badPath || PathTool.BadIconS );
|
|
}
|
|
} );
|
|
},
|
|
|
|
// 快速设置头像(face_id)
|
|
setAvatarByFaceId: function( _refnode, _names, _faceId ) {
|
|
this.setIcon( _refnode, _names, _faceId, PathTool.BadAvatar );
|
|
},
|
|
|
|
// 快速设置头像框(avatar_base_id)
|
|
setAvatarFrame: function( _refnode, _names, _fid ) {
|
|
let path = cc.path.join( "resDB/aframes", _fid );
|
|
nx.gui.setSpriteFrame( _refnode, _names, path, ( _ret ) => {
|
|
if( !_ret ) {
|
|
nx.gui.setSpriteFrame( _refnode, _names, PathTool.BadAvatarFrame );
|
|
}
|
|
} );
|
|
},
|
|
|
|
// 快速设置聊天泡泡(bubble_bid)
|
|
setChatBubble: function( _refnode, _names, _bid ) {
|
|
let path = cc.path.join( "resDB/chatskin", _bid );
|
|
nx.gui.setSpriteFrame( _refnode, _names, path, ( _ret ) => {
|
|
if( !_ret ) {
|
|
nx.gui.setSpriteFrame( _refnode, _names, PathTool.BadChatBubble );
|
|
}
|
|
} );
|
|
},
|
|
|
|
// 获取子节点上的BridgeWindow组件
|
|
getBridgeWindow: function( _refnode, _names ) {
|
|
|
|
var node = nx.gui.find( _refnode, _names );
|
|
if( !node ) {
|
|
return null;
|
|
}
|
|
|
|
let components = node._components;
|
|
if( nx.dt.arrEmpty( components ) ) {
|
|
return null;
|
|
}
|
|
|
|
for( let i in components ) {
|
|
let cmp = components[ i ];
|
|
if( cmp && nx.dt.strGood( cmp.BKEY ) ) {
|
|
return cmp;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
},
|
|
|
|
// ================================================================
|
|
// 界面相关快捷方法
|
|
// ================================================================
|
|
|
|
// 创建界面
|
|
createPanel: function( _wname, _params ) {
|
|
this.ui.openWindow( _wname, _params );
|
|
|
|
// //設置回溯界面
|
|
// this.setTag2PanelInfos(_wname, _params);
|
|
},
|
|
|
|
// 关闭界面
|
|
closePanel: function( _wname ) {
|
|
this.ui.closeWindow( _wname );
|
|
this.Tag2PanelClose(_wname);
|
|
},
|
|
|
|
// 清理所有非场景层节点
|
|
cleanPanels: function() {
|
|
this.ui.cleanWindows();
|
|
this.resetTag2Panels();
|
|
},
|
|
|
|
// 清理所有非场景层节点
|
|
cleanWindowsByTag: function( _tag ) {
|
|
this.ui.cleanWindowsByTag( _tag );
|
|
},
|
|
|
|
// 設置回溯界面
|
|
setTag2PanelInfos: function( _wname, _args, _tag ) {
|
|
// if(!window.game.isMainScene)return;
|
|
if(_wname == "MainScene" || _wname == "WndBattleScene" || _wname == "WndFormView"
|
|
|| _wname == "WndSummonAnimation" || _wname == "WndFromView" || _wname == "WndPersonalPush"
|
|
|| _wname == "WndCampfightFinal" )return;
|
|
|
|
//去重
|
|
for(let i in this.setTag2Infos){
|
|
let info = this.setTag2Infos[i];
|
|
if(info && info.panel){
|
|
if(_wname == info.panel){
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
//最大回溯 size 3
|
|
if(this.setTag2Infos.length == 3){
|
|
//去除最早的
|
|
this.setTag2Infos.shift();
|
|
}
|
|
|
|
this.setTag2Infos.push({
|
|
panel:_wname,
|
|
args:_args,
|
|
tag: _tag
|
|
});
|
|
},
|
|
|
|
// 回溯界面已關閉
|
|
Tag2PanelClose: function( _wname ) {
|
|
// if(!window.game.isMainScene)return;
|
|
for(let i in this.setTag2Infos){
|
|
let info = this.setTag2Infos[i];
|
|
if(info && info.panel){
|
|
if(info.panel == _wname){
|
|
this.setTag2Infos.splice(i,1);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
// 界面回溯
|
|
resetTag2PanelfromBat: function( ) {
|
|
for(let i in this.setTag2Infos){
|
|
let info = this.setTag2Infos[i];
|
|
if(info && info.panel && info.args){
|
|
let par = this.ui.getSceneNode(info.tag);
|
|
let view = this.getBridgeWindow(par,info.panel);
|
|
if(!view ){
|
|
|
|
this.createPanel(info.panel, info.args);
|
|
}
|
|
}
|
|
}
|
|
|
|
//清空緩存
|
|
// this.setTag2Infos = [];
|
|
},
|
|
|
|
// 界面回溯
|
|
resetTag2Panels: function( ) {
|
|
//清空緩存
|
|
this.setTag2Infos = [];
|
|
},
|
|
|
|
// ================================================================
|
|
// 全屏等待
|
|
// ================================================================
|
|
|
|
// 添加单等待
|
|
addWaiting: function( _key, _desc = "", _tout = 5 ) {
|
|
|
|
if( nx.dt.strEmpty( _key ) ) {
|
|
nx.error( "无效空等待添加" );
|
|
return;
|
|
}
|
|
|
|
nx.debug( "全局等待(ADD):", _key, _desc );
|
|
|
|
let keys = this.vget( "GWaitings" );
|
|
if( nx.dt.arrMember( keys, null, ( _m ) => {
|
|
return _m && ( _m.key == _key );
|
|
} ) ) {
|
|
nx.error( "全屏等待:重复." + _key );
|
|
return;
|
|
}
|
|
|
|
keys.push( { key: _key, desc: _desc, tout: _tout } );
|
|
this.vset( "GWaitings", keys );
|
|
},
|
|
|
|
// 删除单等待
|
|
delWaiting: function( _key ) {
|
|
|
|
if( nx.dt.strEmpty( _key ) ) {
|
|
nx.error( "无效空等待删除" );
|
|
return;
|
|
}
|
|
|
|
nx.debug( "全局等待(DEL):", _key );
|
|
|
|
let keys = this.vget( "GWaitings" );
|
|
keys = nx.dt.arrDelete( keys, ( _m ) => {
|
|
return _m && ( _m.key == _key );
|
|
} );
|
|
|
|
this.vset( "GWaitings", keys );
|
|
},
|
|
|
|
// 清空等待
|
|
cleanWaitings: function() {
|
|
|
|
nx.debug( "全局等待(CLEAN):" );
|
|
this.vset( "GWaitings", [] );
|
|
},
|
|
|
|
// ================================================================
|
|
// 原方法参数保全兼容过渡
|
|
// ================================================================
|
|
|
|
// 获取服务器本地名字
|
|
localServerName: function( _srvid ) {
|
|
|
|
if( nx.dt.strEmpty( _srvid ) ) {
|
|
return "";
|
|
}
|
|
|
|
let RC = require( "role_controller" ).getInstance();
|
|
let role = RC.getRoleVo();
|
|
if( !role ) {
|
|
return "";
|
|
}
|
|
|
|
let name = "";
|
|
let listOr = _srvid.split( "_" );
|
|
let listMe = role.srv_id.split( "_" );
|
|
if( listOr[ 1 ] && listMe[ 0 ] && listOr[ 0 ] != listMe[ 0 ] ) {
|
|
name = nx.text.getKey( "msg_functiontool_tip1" );
|
|
} else if( listOr.length > 1 ) {
|
|
name = cc.js.formatStr( "S%s", listOr[ listOr.length - 1 ] );
|
|
}
|
|
|
|
// 代表机器人
|
|
if( _srvid == "robot_1" ) {
|
|
name = name;
|
|
}
|
|
|
|
return name;
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
module.exports = NxBridge;
|