Files
fc/dev/project/assets/Scripts/ffengine/ff_sdk.js
T

366 lines
11 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
const CPluginHelp = require("plugin_help");
const CMiscHelp = require("misc_help");
import { ErolabsSDK } from "../erolabs/ErolabsSDK";
// const LoginMod = require( "login.mod" );
let FFSDK = cc.Class({
statics: {
instance: null
},
ctor: function () {
this.mInited = false;
this.mJsonSDKInfo = undefined;
},
isEnableSDK : function () {
return CPluginHelp.getInstance().isEnableSDK();
},
// callback type::( param : any ) => void
regSdkCallBack: function( funcName, callback, owner ) {
CPluginHelp.getInstance().regSdkCallBack( funcName, callback, owner );
},
removeSdkCallBack: function( funcName, callback ) {
CPluginHelp.getInstance().removeSdkCallBack( funcName, callback );
},
// 越早调用越好!
init : function () {
if( this.mInited ) { return this.mJsonSDKInfo; }
this.mInited = true;
// CPluginHelp.getInstance().regSdkCallBack( "pay", this._onPayResult );
// CPluginHelp.getInstance().regSdkCallBack( "login", this._onLoginResult );
// CPluginHelp.getInstance().regSdkCallBack( "logout", this._onLogoutResult );
// CPluginHelp.getInstance().regSdkCallBack( "bindaccount", this._onBindAccountResult );
let platformInfo = CPluginHelp.getInstance().callSdk( "platformInfo", "{}" );
if ( platformInfo && 0 < platformInfo.length ) {
this.mJsonSDKInfo = JSON.parse( platformInfo );
if( this.mJsonSDKInfo.channelName == "erolabs" ){
ErolabsSDK.initialize( "88",
this.mJsonSDKInfo.channelName, this.mJsonSDKInfo.lang, ( _data )=>{
// ErolabsSDK.setLanguage( this.mJsonSDKInfo.lang );
} );
}
}
return this.mJsonSDKInfo;
},
////////////// quick call functions //////////////
autoLogin : function() {
if( this.mJsonSDKInfo.channelName == "erolabs" ){
ErolabsSDK.openLogin(_ => {
let uid = _.data.user_info.user_id;
this.accountinfo = _;
let account = nx.dt.strNEmpty( this.accountinfo.data.user_info.account ) ? this.accountinfo.data.user_info.account : uid ;
// console.log( JSON.stringify( _ ) + "autoLogin" + JSON.stringify( this.accountinfo ) );
CPluginHelp.getInstance().sendSdkCallBack( "login", { openId: account } );
let stroge = nx.storage.get( "bindreward" + this.accountinfo.data.user_info.account );
if( nx.dt.strNEmpty( this.accountinfo.data.user_info.account ) ){
ErolabsSDK.reqCoins();
ErolabsSDK.postAccountBindGame( this.accountinfo.data.user_info.account ,_ => {
})
nx.mTip.openTip( "setting.bind", !stroge );
}
nx.mTip.openTip( "unbind", nx.dt.strEmpty( this.accountinfo.data.user_info.account ) );
})
}else{
nx.mTip.openTip( "setting.bind", false );
nx.mTip.openTip( "unbind", false );
CPluginHelp.getInstance().callSdk( "autoLogin", "{}" );
}
},
doLogout :function(){
// ErolabsSDK.openLogin(_ => {
// let uid = _.data.user_info.user_id;
// CPluginHelp.getInstance().sendSdkCallBack( "login", { openId: uid } );
// })
ErolabsSDK.openLogout( ( _result ) =>{
let resultback = nx.dt.strEmpty( _result.exception ) ? 1 : 0;
console.log( "OpenLogout---->>>>>" + JSON.stringify( _result ));
CPluginHelp.getInstance().sendSdkCallBack( "logout", { result : resultback } );
} )
},
switchAccount : function () {
let self = this;
if( this.mJsonSDKInfo.channelName == "erolabs" ){
ErolabsSDK.openLogout( ( _result ) =>{
if( nx.dt.strEmpty( _result.exception ) ){
self.autoLogin();
}
} )
}else{
CPluginHelp.getInstance().callSdk( "switchAccount", "{}" );
}
},
logOut : function() {
let self = this;
if( this.mJsonSDKInfo.channelName == "erolabs" ){
console.log( "sdklogOut" + JSON.stringify( this.accountinfo ) );
if( nx.dt.strEmpty( this.accountinfo.data.user_info.account ) ){
nx.mbox( "BingAccountTip", [ 'Cancle', 'confirm' ], ( _key, _box )=>{
_box.close();
if( _key == 'confirm' ){
self.doLogout();
}
} )
}else{
self.doLogout();
}
}else{
CPluginHelp.getInstance().callSdk( "loginOut", "{}" );
}
},
// 游客绑定
guestBind : function( _cb ) {
if( this.mJsonSDKInfo.channelName == "erolabs" ){
let info = nx.bridge.vget( "curAccount" );
if( nx.dt.strEmpty( this.accountinfo.data.user_info.account ) ){
// console.log( "绑定游客账号chuan" + info.account );
ErolabsSDK.openAccountBindGame( info.account, _cb )
}
// CPluginHelp.getInstance().sendSdkCallBack( "logout", { result : resultback } );
}else{
CPluginHelp.getInstance().callSdk( "bindaccount", "{}" );
}
},
checkUpdate : function () {
CPluginHelp.getInstance().callSdk( "checkUpdate", "{}" );
},
report : function ( evtName, evtValue ) {
var msg = "{\"event\":\"" + evtName + "\",\"value\":\"" + evtValue + "\"}";
CPluginHelp.getInstance().callSdk( "report", msg );
},
// 上报账号ID
reportOpenID : function( openID ) {
if ( CMiscHelp.getInstance().isValid( openID ) ) {
this.report( "setOpenID", "" + openID );
}
},
// 上报服务器ID
reportServerID : function( serverID ) {
if ( CMiscHelp.getInstance().isValid( serverID ) ) {
this.report( "setUserServer", "" + serverID );
}
},
// 上报主角ID
reportRoleID : function( roleID ) {
if ( CMiscHelp.getInstance().isValid( roleID ) ) {
this.report( "setRoleID", "" + roleID );
}
},
// 上报主角昵称
reportRoleName : function( roleName ) {
if ( CMiscHelp.getInstance().isValid( roleName ) ) {
this.report( "setRoleName", "" + roleName );
}
},
// 上报主角等级
reportRoleLevel : function( level ) {
if ( CMiscHelp.getInstance().isValid( level ) ) {
this.report( "setRoleLevel", "" + level );
}
},
showFloatView : function ( visible ) {
var msg = "{\"visible\":\"" + ( visible ? 1 : 0 ) + "\"}";
CPluginHelp.getInstance().callSdk( "showFloatView", msg );
},
pay : function ( payID, price, productName, productDesc,
openID, roleID, serverID ) {
let self = this;
let msgBody = {
payid : payID,
price : price,
name : productName,
desc : productDesc,
openid: openID,
roleID: roleID,
srvid : serverID
};
if( this.mJsonSDKInfo.channelName == "erolabs" ){
if( nx.dt.strEmpty( this.accountinfo.data.user_info.account ) ){
nx.mbox( "BuyNoAccountTip", [ 'Cancle', 'BuyNoAGoto' ], ( _key, _box )=>{
_box.close();
if( _key == 'BuyNoAGoto' ){
// LoginMod.getInstance().reqSDKLogout( ()=>{
// self.guestBind();
// } );
self.doLogout();
}else{
CPluginHelp.getInstance().sendSdkCallBack( "pay", { } );
}
} )
}else{
let tip = nx.text.getKey( "sdkerolabsNoEnoughTip" );
let etip = nx.text.format( "sdkerolabsEnoughTip", this.getCoinsSelf() );
if( this.getCoinsSelf() < price ){
nx.mbox( tip, [ 'Cancle', 'confirm' ], ( _key, _box )=>{
_box.close();
if( _key == 'confirm' ){
ErolabsSDK.openPayment();
CPluginHelp.getInstance().sendSdkCallBack( "pay", { } );
}else{
CPluginHelp.getInstance().sendSdkCallBack( "pay", { } );
}
} )
}else{
nx.mbox( etip, [ 'Cancle', 'confirm' ], ( _key, _box )=>{
_box.close();
if( _key == 'confirm' ){
msgBody.Token = ErolabsSDK.getToken();
let msg = JSON.stringify( msgBody );
CPluginHelp.getInstance().callSdk( "pay", msg );
}else{
CPluginHelp.getInstance().sendSdkCallBack( "pay", { } );
}
} )
}
}
}else{
let msg = JSON.stringify( msgBody );
CPluginHelp.getInstance().callSdk( "pay", msg );
}
},
getCoinsSelf : function(){
return ErolabsSDK.getCoins();
},
reqCoins : function(){
ErolabsSDK.reqCoins();
},
openUrl : function ( url ) {
let msg = "{\"url\":\"" + url + "\"}";
CPluginHelp.getInstance().callSdk( "openUrl", msg );
},
// 获取粘贴板文本
getClipboard : function() {
return CPluginHelp.getInstance().callSdk( "getClipboard", "{}" );
},
/////////////////// SDK Call Back ///////////////////
// _onLoginResult : function ( jsonParams ) {
// if( jsonParams )
// {
// let openIDVal = jsonParams[ "openId" ];
// // TODO :
// }
// },
// _onPayResult : function ( jsonParams ) {
// if( jsonParams )
// {
// let result = jsonParams[ "result" ];
// let msg = jsonParams[ "msg" ];
// if( result && msg && 0 !== parseInt(result) && 0 !== msg.length )
// {
// // TODO : Failed with msg
// return;
// }
// }
// // TODO : Success
// },
// _onLogoutResult : function ( jsonParams ) {
// if( jsonParams )
// {
// let result = jsonParams[ "result" ];
// if( result && 0 !== parseInt(result) ) {
// // TODO : onLogout
// }
// }
// },
// _onBindAccountResult : function ( jsonParams ) {
// if( jsonParams )
// {
// let result = jsonParams[ "guest" ];
// if( undefined !== result ) {
// let is_guest = ( 0 !== parseInt(result) );
// // TODO : bind result
// }
// }
// },
});
FFSDK.getInstance = function () {
if (!FFSDK.instance) {
FFSDK.instance = new FFSDK();
}
return FFSDK.instance;
}
module.exports = FFSDK;