452 lines
10 KiB
JavaScript
452 lines
10 KiB
JavaScript
var SDKManage = require('SDKManage');
|
|
var NetManage = require('NetManage');
|
|
var baseconfig = require('Config');
|
|
|
|
var jcfw = require('jcfw');
|
|
var voiceSDK = require('voiceSDK');
|
|
const Config = require('./Config');
|
|
const jclogin = require('./jcfw/service/jclogin');
|
|
const { allBaseNet } = require('./BaseNet');
|
|
const { getSwitch } = require('./jcfw/service/jclogin');
|
|
const { GIFCache } = require('./gif/GIF');
|
|
const { showLoading } = require('./gif/Loading');
|
|
const { operation, OperationType } = require('./Operation/Operation');
|
|
const jcgamelog = require('./jcfw/service/jcgamelog');
|
|
const { uimanger } = require('./UI/UIManger');
|
|
const { default: ChainErrTip } = require('./tips/ChainErrTip');
|
|
|
|
window.connectOK = (account) => {
|
|
jcgamelog.addOperation(
|
|
OperationType.WALLET,
|
|
'connectwalletsuccess',
|
|
account
|
|
);
|
|
// window.hasWallet = true;
|
|
var tmpaccount = account;
|
|
if (cc.sys.os == cc.sys.OS_ANDROID) {
|
|
tmpaccount = `0x${account}`;
|
|
}
|
|
window.account = tmpaccount;
|
|
jclogin.getNonce();
|
|
};
|
|
|
|
window.chainErr = ()=>{
|
|
console.log("打开提示框")
|
|
cc.Notifier.emit("chainerr");
|
|
};
|
|
|
|
window.signApp = (sign) => {
|
|
jcgamelog.addOperation(OperationType.WALLET, 'signature success');
|
|
|
|
var tmpsigm = sign;
|
|
if (cc.sys.os == cc.sys.OS_ANDROID) {
|
|
tmpsigm = `0x${sign}`;
|
|
}
|
|
window.appsign = tmpsigm;
|
|
SDKManage.init('6516');
|
|
jcgamelog.addOperation(
|
|
OperationType.LOGIN,
|
|
'start login with wallet',
|
|
window.account
|
|
);
|
|
SDKManage.Login(() => {
|
|
jcgamelog.addOperation(
|
|
OperationType.LOGIN,
|
|
'login with wallet success',
|
|
window.account
|
|
);
|
|
|
|
showLoading();
|
|
cc.director.loadScene('MainScene');
|
|
|
|
//
|
|
window.hasWallet = true;
|
|
localStorage.setItem('walletaccount', window.account);
|
|
cc.Notifier.emit('hasConnectWallet', window.account);
|
|
});
|
|
|
|
var node = cc.director.getScene().getComponentInChildren('UILogin');
|
|
node.btn_wallet.active = false;
|
|
node.btn_tourist.active = false;
|
|
};
|
|
|
|
window.showToast = (msg) => {
|
|
cc.uiHelper.showTips(msg);
|
|
};
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
loadBar: {
|
|
default: null,
|
|
type: cc.ProgressBar,
|
|
},
|
|
btn_login: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
lb_text: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
progressTxt: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
versionCom: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
|
|
btn_wallet: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
btn_tourist: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_allCountry: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_currentCoutryIcon: {
|
|
default: null,
|
|
type: cc.Sprite,
|
|
},
|
|
|
|
nd_currentCoutryName: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
|
|
nd_allCountryIcon: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
onLoad() {
|
|
|
|
this.allCountry = ['Japan', 'Singapore', 'Turkey', 'USA'];
|
|
|
|
this.cpa_icon = [];
|
|
cc.Notifier.on('sdkloginnotic', this, this.sdklogin.bind(this));
|
|
cc.Notifier.on('sdkloginfail', this, this.sdkloginfail.bind(this));
|
|
cc.Notifier.on(
|
|
'sdkLoginSuccess',
|
|
this,
|
|
this.sdkLoginSuccess.bind(this)
|
|
);
|
|
|
|
cc.Notifier.on('autologinsuccess', this, this.loadMain.bind(this));
|
|
|
|
cc.Notifier.on("chainerr",this,this.showchainErrTip.bind(this));
|
|
|
|
|
|
cc.debug.setDisplayStats(false);
|
|
|
|
// if (baseconfig.mainConfig.isoffical == false) {
|
|
// this.lb_text.string = "Alpha";
|
|
// }
|
|
if (this.versionCom) {
|
|
let versionStr = baseconfig.mainConfig.version;
|
|
this.versionCom.string = versionStr;
|
|
}
|
|
|
|
if (
|
|
navigator.userAgent.match(
|
|
/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
|
|
)
|
|
) {
|
|
cc.pcmode = false;
|
|
} else {
|
|
cc.pcmode = true;
|
|
}
|
|
},
|
|
|
|
showchainErrTip(){
|
|
console.log("链id错误")
|
|
uimanger.showUI(ChainErrTip.prefabPath);
|
|
},
|
|
|
|
loadMain() {
|
|
showLoading();
|
|
cc.director.loadScene('MainScene');
|
|
cc.loader.onProgress = function (completedCount, totalCount, item) {
|
|
var progress = completedCount / totalCount;
|
|
if (item && item.uuid && progress > this.loadBar.progress) {
|
|
this.loadBar.progress = progress;
|
|
let tmpN = Math.floor(progress * 100);
|
|
if (tmpN > 100) {
|
|
tmpN = 100;
|
|
}
|
|
this.progressTxt.string = '' + tmpN + '%';
|
|
if (progress == 1) {
|
|
cc.loader.onProgress = null;
|
|
}
|
|
}
|
|
}.bind(this);
|
|
},
|
|
|
|
onDestroy() {
|
|
cc.inlogin = false;
|
|
cc.Notifier.off('sdkloginnotic', this);
|
|
cc.Notifier.off('sdkloginfail', this);
|
|
cc.Notifier.off('sdkLoginSuccess', this);
|
|
cc.Notifier.off('autologinsuccess', this);
|
|
cc.Notifier.off("chainerr",this,this.showchainErrTip.bind(this));
|
|
cc.loader.onProgress = null;
|
|
SDKManage.logEvent('login_success', 'loginmain');
|
|
},
|
|
|
|
showubar() {
|
|
this.loadBar.node.active = true;
|
|
},
|
|
loadsub(packname) {
|
|
var self = this;
|
|
cc.loader.downloader.loadSubpackage(packname, function (err) {
|
|
if (err) {
|
|
self.loadsub(packname);
|
|
return;
|
|
}
|
|
self.subcount++;
|
|
if (self.subcount == 2) {
|
|
self.subover = true;
|
|
}
|
|
});
|
|
},
|
|
start() {
|
|
GIFCache.getInstance();
|
|
cc.inlogin = true;
|
|
this.btn_login.active = false;
|
|
cc.battleCache.loadwave();
|
|
cc.usingsdk = false;
|
|
//this.time = 0.1
|
|
this.subcount = 0;
|
|
cc.mygamedelta = 0.0167;
|
|
cc.SDKManage = SDKManage;
|
|
// cc.macro.CLEANUP_IMAGE_CACHE = false
|
|
//cc.dynamicAtlasManager.enabled = false
|
|
this.callLogin = false;
|
|
this.subover = false;
|
|
this.loadBar.node.active = false;
|
|
this.neting = false;
|
|
this.getconfigover = false;
|
|
this.kaipingover = false;
|
|
this.debugstr = '';
|
|
var self = this;
|
|
//this.btn_load.active = false
|
|
cc.highmode = true;
|
|
cc.game.setFrameRate(60);
|
|
|
|
self.subover = true;
|
|
// this.btn_tourist.active = true;
|
|
// this.btn_wallet.active = true;
|
|
//
|
|
SDKManage.init('6516');
|
|
|
|
jcgamelog.addOperation(
|
|
OperationType.LOGIN,
|
|
'gamestart',
|
|
);
|
|
|
|
|
|
console.log(`current packageid `+ Config.mainConfig.packageid)
|
|
console.log(`current version `+ Config.mainConfig.version)
|
|
|
|
jcgamelog.addOperation(OperationType.Login,Config.mainConfig.packageid)
|
|
|
|
if (!localStorage.getItem('currentNet')) {
|
|
localStorage.setItem('currentNet', allBaseNet.japan);
|
|
} else {
|
|
var data = 0;
|
|
switch (localStorage.getItem('currentNet')) {
|
|
case allBaseNet.japan:
|
|
data = 0;
|
|
break;
|
|
case allBaseNet.singapore:
|
|
data = 1;
|
|
break;
|
|
case allBaseNet.turkey:
|
|
data = 2;
|
|
break;
|
|
case allBaseNet.usa:
|
|
data = 3;
|
|
break;
|
|
}
|
|
|
|
this.nd_allCountryIcon.children.forEach((element) => {
|
|
element.active = false;
|
|
});
|
|
this.nd_allCountryIcon.children[data].active = true;
|
|
this.nd_currentCoutryName.getComponent(cc.Label).string =
|
|
this.allCountry[data];
|
|
}
|
|
|
|
// if (cc.sys.isBrowser) {
|
|
// localStorage.setItem('currentNet', allBaseNet.test);
|
|
// }
|
|
|
|
getSwitch(() => {
|
|
if (!Config.isTest) {
|
|
if (localStorage.getItem('walletaccount')) {
|
|
this.btn_tourist.active = false;
|
|
this.btn_wallet.active = false;
|
|
window.hasWallet = true;
|
|
window.account = localStorage.getItem('walletaccount');
|
|
window.canAutoLogin = true;
|
|
SDKManage.init('6516');
|
|
jcgamelog.addOperation(
|
|
OperationType.LOGIN,
|
|
'auto login',
|
|
window.account
|
|
);
|
|
SDKManage.Login(() => {
|
|
jcgamelog.addOperation(
|
|
OperationType.LOGIN,
|
|
'auto login success',
|
|
window.account
|
|
);
|
|
});
|
|
} else {
|
|
this.btn_tourist.active = true;
|
|
this.btn_wallet.active = true;
|
|
}
|
|
} else {
|
|
this.btn_tourist.active = true;
|
|
this.btn_wallet.active = false;
|
|
this.btn_tourist.position = new cc.v2(0, this.btn_tourist.y);
|
|
}
|
|
});
|
|
},
|
|
|
|
btn_start(val) {
|
|
if (val == 1) {
|
|
this.nd_start.active = true;
|
|
}
|
|
},
|
|
|
|
sdkLoginSuccess() {
|
|
this.subover = true;
|
|
},
|
|
sdklogin(v) {
|
|
this.subover = true;
|
|
|
|
cc.sdkdata = v;
|
|
},
|
|
sdkloginfail() {
|
|
this.btn_login.active = true;
|
|
},
|
|
|
|
onClicktouristLogin() {
|
|
this.nd_allCountry.active = false;
|
|
this.btn_wallet.active = false;
|
|
this.btn_tourist.active = false;
|
|
SDKManage.init('6513');
|
|
jcgamelog.addOperation(
|
|
OperationType.LOGIN,
|
|
'guest login',
|
|
window.account
|
|
);
|
|
SDKManage.Login(() => {
|
|
jcgamelog.addOperation(
|
|
OperationType.LOGIN,
|
|
'guest login success',
|
|
window.account
|
|
);
|
|
this.loadMain();
|
|
});
|
|
},
|
|
|
|
onClickChangeArea() {
|
|
this.nd_allCountry.active = true;
|
|
},
|
|
|
|
onCloseChooseArea() {
|
|
this.nd_allCountry.active = false;
|
|
},
|
|
|
|
onClickPrivacy() {
|
|
this.openUrlinNative('https://www.cebg.games/privacy');
|
|
},
|
|
|
|
onClickTerms() {
|
|
this.openUrlinNative('https://www.cebg.games/terms');
|
|
},
|
|
|
|
openUrlinNative(url) {
|
|
if (cc.sys.os == cc.sys.OS_ANDROID) {
|
|
jsb.reflection.callStaticMethod(
|
|
'org/cocos2dx/javascript/AppActivity',
|
|
'openSocialUrl',
|
|
'(Ljava/lang/String;)V',
|
|
url
|
|
);
|
|
} else if (cc.sys.os == cc.sys.OS_IOS) {
|
|
jsb.reflection.callStaticMethod(
|
|
'AppController',
|
|
'openSocialUrl:',
|
|
url
|
|
);
|
|
}
|
|
},
|
|
|
|
onClickSelectCountry(event, data) {
|
|
this.nd_allCountry.active = false;
|
|
this.nd_allCountryIcon.children.forEach((element) => {
|
|
element.active = false;
|
|
});
|
|
this.nd_allCountryIcon.children[data].active = true;
|
|
this.nd_currentCoutryName.getComponent(cc.Label).string =
|
|
this.allCountry[data];
|
|
switch (data) {
|
|
case '0':
|
|
//jp
|
|
jcgamelog.addOperation(OperationType.LOGIN, 'userArea', 'jp');
|
|
localStorage.setItem('currentNet', allBaseNet.japan);
|
|
break;
|
|
case '1':
|
|
//sg
|
|
jcgamelog.addOperation(OperationType.LOGIN, 'userArea', 'sg');
|
|
localStorage.setItem('currentNet', allBaseNet.singapore);
|
|
break;
|
|
case '2':
|
|
//
|
|
jcgamelog.addOperation(
|
|
OperationType.LOGIN,
|
|
'userArea',
|
|
'turkey'
|
|
);
|
|
localStorage.setItem('currentNet', allBaseNet.turkey);
|
|
break;
|
|
case '3':
|
|
//usa
|
|
jcgamelog.addOperation(OperationType.LOGIN, 'userArea', 'usa');
|
|
localStorage.setItem('currentNet', allBaseNet.usa);
|
|
break;
|
|
}
|
|
//change area in native
|
|
if (cc.sys.os == cc.sys.OS_ANDROID) {
|
|
jsb.reflection.callStaticMethod(
|
|
'org/cocos2dx/javascript/AppActivity',
|
|
'changeArea',
|
|
'(Ljava/lang/String;)V',
|
|
data
|
|
);
|
|
} else if (cc.sys.os == cc.sys.OS_IOS) {
|
|
jsb.reflection.callStaticMethod(
|
|
'AppController',
|
|
'changeArea:',
|
|
data
|
|
);
|
|
}
|
|
},
|
|
});
|