123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988 |
- /**
- * 广告
- */
- var ttGame;
- /**
- * 广告
- */
- (function (ttGame) {
- class BaseADManager {
- constructor(bannerAdID, rewardedAdID, interstitialAdID) {
- this.STATE_LOADED = 1; //1(01)加载完成
- this.STATE_SHOW = 2; //2(10)显示
- this.STATE_EXPOSURE = 3; //3(11)曝光(加载完成并显示)
- this._ids = { bannerAdID, rewardedAdID, interstitialAdID };
- this._adState = { bannerAdState: 0, rewardedAdState: 0, interstitialAdState: 0 };
- this.createBannerAd(bannerAdID);
- this.createRewardedVideoAd(rewardedAdID);
- this.createInterstitialAd(interstitialAdID);
- }
- //↓↓ Banner广告 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
- /** 创建Banner广告 */
- createBannerAd(bannerAdID) {
- if (!tt.createBannerAd)
- return;
- let sysInfo = platform.systemInfo.info;
- // 创建 Banner 广告实例,提前初始化
- let ad = tt.createBannerAd({
- adUnitId: bannerAdID,
- adIntervals: 30,
- style: {
- left: 0,
- top: sysInfo.windowHeight,
- width: this._bannerAdWidth ? this._bannerAdWidth : sysInfo.windowWidth
- // height:90//字节广告只有设置宽度,无高度设置
- }
- });
- if (!ad)
- return;
- ad.onResize(this.onBannerResize.bind(this));
- ad.onError(this.onBannerError.bind(this));
- ad.onLoad(this.onBannerLoaded.bind(this));
- this._bannerAd = ad;
- }
- onBannerResize(size) {
- log("Banner size:", size);
- let sysInfo = platform.systemInfo.info;
- this._bannerAd.style.left = (sysInfo.windowWidth - size.width) >> 1; //居中
- this._bannerAd.style.top = sysInfo.windowHeight - size.height; //底部
- }
- /** banner报错 */
- onBannerError(err) {
- log("Banner广告报错:", err);
- }
- /** banner加载完成 */
- onBannerLoaded() {
- // log("Banner onLoad:", windowHeight, ad.style.height)
- // ad.style.top = windowHeight - ad.style.height;//y坐标,按广告真实高度定
- this.addBannerState(this.STATE_LOADED);
- core.Manager.wtsdk.sendAdLog(this._ids.bannerAdID, core.AdLogType.REQUEST);
- }
- /** 添加状态(加载完或显示),并查看是否曝光(加载完且显示) */
- addBannerState(state) {
- this._adState.bannerAdState |= state;
- if (this._adState.bannerAdState == this.STATE_EXPOSURE) {
- core.Manager.wtsdk.sendAdLog(this._ids.bannerAdID, core.AdLogType.EXPOSURE);
- }
- }
- /** 显示 banner 广告 */
- showBanner() {
- if (this._bannerAd) {
- this._bannerAd.show();
- this.addBannerState(this.STATE_SHOW);
- }
- }
- /** 隐藏 banner 广告 */
- hideBanner() {
- if (this._bannerAd)
- this._bannerAd.hide();
- this._adState.bannerAdState = 0; //重置状态
- }
- //↑↑ Banner广告 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
- //↓↓ 激励视频广告 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
- /** 创建激励视频广告 */
- createRewardedVideoAd(rewardedAdID) {
- if (!tt.createRewardedVideoAd)
- return;
- this._rewardedVideoAd = tt.createRewardedVideoAd({ adUnitId: rewardedAdID });
- log("创建激励视频广告", this._rewardedVideoAd);
- if (!this._rewardedVideoAd)
- return;
- this._rewardedVideoAd.onError(this.onRewardedVideoAdError.bind(this));
- this._rewardedVideoAd.onClose(this.onRewardedVideoAdClosed.bind(this));
- this._rewardedVideoAd.onLoad(this.onRewardedVideoAdLoaded.bind(this));
- }
- /** 激励视频广告报错 */
- onRewardedVideoAdError(err) {
- log("激励视频出错", err);
- core.Manager.eDispatcher.event(core.Event.REWARDED_AD_ERROR, err);
- }
- /** 激励视频广告关闭 */
- onRewardedVideoAdClosed(res) {
- log("激励视频关闭", res);
- this._adState.rewardedAdState = 0; //重置状态
- if (res && res.isEnded)
- core.Manager.wtsdk.sendAdLog(this._ids.interstitialAdID, core.AdLogType.FINISH); //完成激励视频观看
- core.Manager.eDispatcher.event(core.Event.REWARDED_AD_CLOSE, res && res.isEnded);
- }
- /** 激励视频广告加载完成 */
- onRewardedVideoAdLoaded(res) {
- log("激励视频加载", res);
- this.addRewardedState(this.STATE_LOADED);
- core.Manager.wtsdk.sendAdLog(this._ids.rewardedAdID, core.AdLogType.REQUEST);
- core.Manager.eDispatcher.event(core.Event.REWARDED_AD_ONLOAD, res);
- }
- /** 添加状态(加载完或显示),并查看是否曝光(加载完且显示) */
- addRewardedState(state) {
- this._adState.rewardedAdState |= state;
- if (this._adState.rewardedAdState == this.STATE_EXPOSURE) {
- core.Manager.wtsdk.sendAdLog(this._ids.rewardedAdID, core.AdLogType.EXPOSURE);
- }
- }
- /**
- * 显示激励广告
- */
- showRewardedVideoAd() {
- if (!this._rewardedVideoAd)
- return;
- // let ad = this._rewardedVideoAd;
- // // 用户触发广告后,显示激励视频广告
- // ad.show().catch(() => {
- // // 失败,手动加载一次
- // ad.load()
- // .then(() => ad.show())
- // .catch(err =>
- // {
- // log('激励视频 广告显示失败');
- // core.Manager.eDispatcher.event(core.Event.REWARDED_AD_ERROW, err);
- // })
- // })
- let ad = this._rewardedVideoAd;
- // this._rewardedVideoAd.load().then(() => {
- // ad.show();
- // });
- ad.show();
- this.addRewardedState(this.STATE_SHOW);
- }
- //↑↑ 激励视频广告 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
- //↓↓ 插屏广告 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
- /** 创建插屏广告 */
- createInterstitialAd(interstitialAdID) {
- // // 定义插屏广告
- // // 创建插屏广告实例,提前初始化
- if (!tt.createInterstitialAd)
- return;
- this._interstitialAd = tt.createInterstitialAd({ adUnitId: interstitialAdID });
- log("创建插屏广告", this._rewardedVideoAd);
- if (!this._interstitialAd)
- return;
- this._interstitialAd.onError(this.onInterstitialAdError.bind(this));
- this._interstitialAd.onClose(this.onInterstitialAdClosed.bind(this));
- this._interstitialAd.onLoad(this.onInterstitialAdLoaded.bind(this));
- }
- /** 插屏广告报错 */
- onInterstitialAdError(err) {
- log("插屏广告出错", err);
- core.Manager.eDispatcher.event(core.Event.INTERSTITIAL_AD_ERROR, err);
- }
- /** 插屏广告关闭 */
- onInterstitialAdClosed(res) {
- log("插屏广告关闭", res);
- this._adState.interstitialAdState = 0; //重置状态
- core.Manager.eDispatcher.event(core.Event.INTERSTITIAL_AD_CLOSE, res);
- }
- /** 插屏广告加载完成 */
- onInterstitialAdLoaded(res) {
- log("插屏广告加载", res);
- this.addInterstitialState(this.STATE_LOADED);
- core.Manager.wtsdk.sendAdLog(this._ids.interstitialAdID, core.AdLogType.REQUEST);
- core.Manager.eDispatcher.event(core.Event.INTERSTITIAL_AD_ONLOAD, res);
- }
- /** 添加状态(加载完或显示),并查看是否曝光(加载完且显示) */
- addInterstitialState(state) {
- this._adState.interstitialAdState |= state;
- if (this._adState.interstitialAdState == this.STATE_EXPOSURE) {
- core.Manager.wtsdk.sendAdLog(this._ids.interstitialAdID, core.AdLogType.EXPOSURE);
- }
- }
- /**
- * 显示插屏广告
- */
- showInterstitialAd() {
- // 在适合的场景显示插屏广告
- if (!this._interstitialAd)
- return;
- let ad = this._interstitialAd;
- this._interstitialAd.load().then(() => {
- ad.show();
- this.addInterstitialState(this.STATE_SHOW);
- }).catch((err) => {
- log("显示插屏广告err:", err);
- });
- ;
- }
- }
- ttGame.BaseADManager = BaseADManager;
- })(ttGame || (ttGame = {}));
- /// <reference path="./base/BaseADManager.ts" />
- var ttGame;
- /// <reference path="./base/BaseADManager.ts" />
- (function (ttGame) {
- class ADManager extends ttGame.BaseADManager {
- constructor() {
- super("5ned9cusvp93gaecf5", "548if3698jfe98cl0c", "pdjoqnq1i9537a7o1o"); //广告id
- this._bannerAdWidth = Math.floor(tt.getSystemInfoSync().windowWidth / 3); //不取默认屏幕宽度,则设置banner宽度
- }
- //重写设置banner位置
- onBannerResize(size) {
- let windowWidth = tt.getSystemInfoSync().windowWidth;
- let windowHeight = tt.getSystemInfoSync().windowHeight;
- this._bannerAd.style.left = windowWidth - size.width; //居右
- this._bannerAd.style.top = windowHeight - size.height; //底部
- }
- }
- ttGame.ADManager = ADManager;
- })(ttGame || (ttGame = {}));
- /// <reference path="../ADManager.ts" />
- var ttGame;
- (function (ttGame) {
- class BasePlatform extends core.BasePlatform {
- constructor() {
- super();
- }
- /** 初始化监听事件 */
- initEvent() {
- tt.onShow(this.onShow.bind(this)); //监听小游戏回到前台的事件
- tt.onHide(this.onHide.bind(this)); //监听小游戏隐藏到后台事件,锁屏、按 HOME 键退到桌面等操作会触发此事件。
- }
- /**
- * 回到前台的事件处理函数
- */
- onShow(data) {
- Laya.timer.resume();
- // Laya.stage.renderingEnabled=true//恢复渲染
- // Laya.updateTimer.resume() //恢复onUpdate
- // Laya.physicsTimer.resume() //恢复物理
- // Laya.systemTimer.resume();
- core.Manager.wtsdk.sendStart({ scene: this.startScene });
- core.Manager.eDispatcher.event(core.Event.ON_SHOW, data);
- }
- /**
- * 小游戏隐藏到后台事件处理函数。
- */
- onHide(data) {
- Laya.timer.pause();
- // Laya.stage.renderingEnabled=false//停止渲染
- // Laya.updateTimer.pause() //停止onUpdate
- // Laya.physicsTimer.pause() //停止物理
- // Laya.systemTimer.pause();
- core.Manager.wtsdk.sendExit({ scene: this.startScene });
- core.Manager.eDispatcher.event(core.Event.ON_HIDE, data);
- }
- /**
- * 初始化(登陆、获取用户信息、设置默认分享)
- */
- init() {
- this.systemInfo = new ttGame.SystemInfo();
- core.Manager.baseInfo.app_name = this.systemInfo.appName; //设置应用名
- core.Manager.baseInfo.device = this.systemInfo.device; //设置设备
- core.Manager.baseInfo.platform_id = core.PlatformType.ID_TTGAME; //设置平台id(1-字节)
- // // core.Manager.wtsdk.sendVersion();//发送游戏版本到后台
- // //请求php,游戏初始化和配置数据
- // core.Manager.wtsdk.getInitData(Laya.Handler.create(this, (data) => (core.Manager.config.data = data.result)));
- // //请求php,获取游戏列表
- // core.Manager.wtsdk.getGameList(Laya.Handler.create(core.Manager, core.Manager.setGameList));
- this.openDataContext = tt.getOpenDataContext(); //获取开放数据域
- this.ad = new ttGame.ADManager(); //初始化广告
- this.initEvent(); //初始化监听事件
- this.sendRes(); //资源加载完成后,使用接口将图集透传到子域
- this.initRecorder(); //初始化录屏器
- this.setDefaultShare(); //设置默认分享
- this.login(); //登陆
- // tt.setUserGroup({ groupId: this.GROUP_ID });//设置排行分组
- }
- /**
- * 登陆 - 获取Code
- */
- login() {
- tt.login({
- force: false,
- success: this.loginComplete.bind(this, true),
- fail: this.loginComplete.bind(this, false)
- // complete:this.loginComplete.bind(this)
- });
- }
- /**
- * 登陆完成回调
- */
- loginComplete(isSucc, data) {
- // {errMsg: "login:ok", anonymousCode: "535ed5c9f15679e2", code: "6a4bfc20dc513b4e", isLogin: true}
- // 登陆失败时,后台要求anonymousCode、code发个空值
- if (!isSucc) {
- data.anonymousCode = null;
- data.code = null;
- }
- data.app_name = core.Manager.baseInfo.app_name;
- data.game_id = core.Manager.baseInfo.game_id;
- data.platform_id = core.Manager.baseInfo.platform_id;
- data.device = this.systemInfo.device;
- data.scene = this.startScene;
- data.version = BaseConfig.version;
- core.Manager.wtsdk.getUserInfo(data, Laya.Handler.create(this, this.httpUserInfoCallback)); //向后台请求用户信息
- this.getAccessToken();
- }
- /** 获取AccessToken接口 */
- getAccessToken(callBack) {
- core.Manager.wtsdk.getAccessToken(Laya.Handler.create(this, (data) => {
- // "code": 200,
- // "result": {
- // "data": {
- // "access_token": "87be87ff0c68ecb79a970e6582b30ab1e90b1118f83bdd27d7f0d985f84ba8b1eda5b32488f9d84060bca6665b96c98937410dddd992c24664c4e863c45a31ea1d6d164dc8b59638fafbc97e31497",
- // "expires_in": 1606742584
- // },
- // "appId": "tt29575feab66d7a22"
- // },
- // "msg": "操作成功"
- if (data.code) {
- this.appID = data.result.appId;
- this.accessToken = data.result.data.access_token;
- }
- if (callBack)
- callBack.runWith(data);
- }));
- }
- //向后台请求用户信息
- httpUserInfoCallback(data) {
- if (data && data.code == 200) {
- core.Manager.baseInfo.token = data.result.id;
- core.Manager.selfInfo.updateAll(data.result);
- this.checkSetting(); //获取用户信息
- }
- else
- log(data);
- }
- //向后台发送平台用户信息
- setUserInfo(userInfo) {
- //如果能获取到字节个人信息,则发送更新用户信息
- if (userInfo)
- core.Manager.wtsdk.modifyUserInfo({ userInfo: userInfo, member_id: core.Manager.selfInfo.id }, Laya.Handler.create(this, this.httpModifyUserInfoCallback));
- else {
- core.Manager.selfInfo.isAuthorized = false; //未授权
- this.sendUserInfo(core.Manager.selfInfo); //无需更新信息,则直接发送用户信息到开放域
- }
- }
- httpModifyUserInfoCallback(data) {
- // log(data);
- if (data && data.code == 200) {
- core.Manager.selfInfo.update(data.result);
- core.Manager.selfInfo.isAuthorized = true; //已授权
- this.sendUserInfo(core.Manager.selfInfo); //发送用户信息到开放域
- }
- else
- log(data);
- }
- /**
- * 查看是否已授权
- */
- checkSetting() {
- tt.getSetting({
- success: (res => {
- log("tt.getSetting:", res);
- if (!res.authSetting['scope.userInfo']) {
- this.authorizeUserInfo(); //未授权,显示授权按钮
- }
- else {
- this.getUserInfo(); //已授权,取用户信息
- }
- if (!res.authSetting['scope.screenRecord']) {
- this.authorizeScreenRecord(); //未授权录屏
- }
- else {
- core.Manager.selfInfo.isAuthorizedScreenRecord = true; //已授权录屏
- }
- }).bind(this)
- });
- }
- //发出用户信息授权请求
- authorizeUserInfo() {
- tt.authorize({
- scope: "scope.userInfo",
- success: (res => {
- this.getUserInfo(); //已授权用户信息
- log("tt.authorize UserInfo succ", res);
- }).bind(this),
- fail: (res => {
- this.setUserInfo(null);
- log("tt.authorize UserInfo fail", res);
- }).bind(this),
- complete: (res => { log("tt.authorize UserInfo complete", res); }).bind(this)
- });
- }
- //发出录屏授权请求
- authorizeScreenRecord() {
- tt.authorize({
- success: (res => {
- core.Manager.selfInfo.isAuthorizedScreenRecord = true; //已授权录屏
- log("tt.authorize screenRecord succ", res);
- }).bind(this),
- fail: (res => { log("tt.authorize screenRecord fail", res); }).bind(this),
- complete: (res => { log("tt.authorize screenRecord complete", res); }).bind(this)
- });
- }
- /**
- * 获取用户信息
- */
- getUserInfo() {
- // 已授权 - 直接获取
- tt.getUserInfo({
- withCredentials: true,
- success: (res => {
- log("getUserInfo:", res);
- this.setUserInfo(res.userInfo); //设置用户信息
- }).bind(this),
- fail: (res => {
- log("getUserInfo fail:", res);
- this.setUserInfo(null);
- }).bind(this),
- });
- }
- /** 透传资源到子域 */
- sendRes() { }
- /** 获取启动场景(php用到) */
- get startScene() {
- let options = tt.getLaunchOptionsSync();
- return options && options.scene ? options.scene : "";
- }
- /**
- * 设置默认分享(微信小游戏小程序不再支持分享回调https://developers.weixin.qq.com/community/develop/doc/0000447a5b431807af57249a551408)
- */
- setDefaultShare() {
- // tt.showShareMenu({
- // withShareTicket: true,
- // menus: ['shareAppMessage', 'shareTimeline'],
- // success: (res?: any) => { log("showShareMenu success", res) },
- // fail: (res?: any) => { log("showShareMenu fail", res) },
- // complete: (res?: any) => { log("showShareMenu complete", res) }
- // })
- tt.onShareAppMessage((() => {
- if (this._sharing)
- return;
- let channel = "";
- let data = this.getShareData();
- core.ObjectUtil.addKeys(data, {
- channel: channel, success: this.shareSuccess.bind(this), fail: this.shareFail.bind(this), complete: this.shareComplete.bind(this)
- });
- return data;
- }).bind(this));
- }
- /** 关注 */
- attention() {
- tt.openAwemeUserProfile(); //跳转个人抖音号主页,用户可以选择关注/取消关注抖音号
- }
- /** 收藏 */
- addToFavorite() {
- tt.showFavoriteGuide();
- // tt.showFavoriteGuide({
- // type: "bar", //小游戏中只能使用 tip 否 引导组件类型,可以是 bar(底部弹窗)、tip(顶部气泡)
- // content: "一键添加到我的小程序", //弹窗文案,最多显示 12 个字符
- // position: "bottom", //小游戏中该字段无意义 否 弹窗类型为 bar 时的位置参数,可以是 bottom(贴近底部)、overtab(悬于页面 tab 区域上方)
- // success(res) { log("引导组件展示成功"); },
- // fail(res) { log("引导组件展示失败"); },
- // complete(res){}
- // });
- // tt.onFavoriteStateChange(callback);
- }
- /** 获取视频列表页面(字节用) */
- getVideoList() {
- tt.request({
- url: "https://gate.snssdk.com/developer/api/get_top_video_ids_by_like",
- method: "POST",
- data: {
- app_id: this.appID,
- number_of_top: 100,
- tag: "rankTag1",
- access_token: this.accessToken,
- },
- success: (res) => {
- log("视频排行榜信息", res);
- if (res.data.err_no == -15003)
- this.getAccessToken(Laya.Handler.create(this, this.getVideoList));
- else {
- core.Manager.eDispatcher.event(core.Event.VIDEO_LIST, res.data.err_no == 0 ? res.data : []);
- }
- // 从res中获取所需视频信息(videoId数组索引与返回数据数组索引一一对应)
- },
- });
- }
- /** 跳转到分享的视频播放页面 */
- navigateToVideoView(videoId) {
- tt.navigateToVideoView({
- videoId: videoId,
- success: (res) => { log("done"); },
- fail: (err) => {
- if (err.errCode === 1006) {
- tt.showToast({
- title: "something wrong with your network",
- });
- }
- },
- });
- }
- /**
- * 主动分享
- */
- share(title) {
- if (this._sharing)
- return;
- let channel = "";
- let data = this.getShareData(title);
- core.ObjectUtil.addKeys(data, {
- channel: channel, success: this.shareSuccess.bind(this, channel), fail: this.shareFail.bind(this, channel), complete: this.shareComplete.bind(this, channel)
- });
- tt.shareAppMessage(data);
- }
- /** 分享的数据(需要重写) */
- getShareData(title) {
- return { success: this.shareSuccess.bind(this), fail: this.shareFail.bind(this), complete: this.shareComplete.bind(this) };
- }
- /** 视频分享 */
- shareVideo(videoPath) {
- if (this._sharing)
- return;
- let channel = "video";
- let data = this.getVideoShareData(videoPath);
- core.ObjectUtil.addKeys(data, {
- channel: channel, success: this.shareSuccess.bind(this, channel), fail: this.shareFail.bind(this, channel), complete: this.shareComplete.bind(this, channel)
- });
- tt.shareAppMessage(data);
- //php统计用
- core.Manager.wtsdk.sendRecord();
- }
- /** 视频分享的数据(需要重写) */
- getVideoShareData(videoPath) {
- let channel = "video";
- return { channel: channel, success: this.shareSuccess.bind(this, channel), fail: this.shareFail.bind(this, channel), complete: this.shareComplete.bind(this, channel) };
- }
- //分享成功回调
- shareSuccess(channel, data) {
- //php统计用
- if (channel == "video")
- core.Manager.wtsdk.sendRecordShare();
- else
- core.Manager.wtsdk.sendShare();
- data.channel = channel;
- core.Manager.eDispatcher.event(core.Event.SHARE_SUCCESS, data);
- log("分享成功", data);
- }
- //分享失败回调
- shareFail(channel, data) {
- data.channel = channel;
- core.Manager.eDispatcher.event(core.Event.SHARE_FAIL, data);
- log("分享失败", data);
- }
- //分享完成回调
- shareComplete(channel, data) {
- data.channel = channel;
- this._sharing = false;
- core.Manager.eDispatcher.event(core.Event.SHARE_COMPLETE, data);
- log("分享完成", data);
- }
- //↑↑分享 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
- /** 获取本地缓存数据 */
- getStorageSync(key) {
- return tt.getStorageSync(key);
- }
- /** 保存数据本地缓存 */
- setStorageSync(key, data) {
- return tt.setStorageSync(key, data);
- }
- /**
- * 向开放数据域发送消息
- * @param message {} 要发送的消息,message 中及嵌套对象中 key 的 value 只能是 primitive value。即 number、string、boolean、null、undefined。
- */
- postMessage(message) {
- this.openDataContext.postMessage(message);
- }
- /** 传递UserInfo */
- sendUserInfo(userInfo) {
- core.Manager.isLogined = true;
- let msg = { "action": core.DomainAction.UserInfo, "data": userInfo };
- this.postMessage(msg);
- }
- /** clearCanvas */
- clearCanvas() {
- let msg = { "action": core.DomainAction.ClearCanvas };
- this.postMessage(msg);
- }
- // private _rank:DYRankView;
- /** 显示排行榜 */
- showRank(rankType) {
- let msg;
- if (rankType == 0)
- msg = { "action": core.DomainAction.RankFriend };
- else
- msg = { "action": core.DomainAction.RankWorld };
- this.postMessage(msg);
- }
- /** 关闭排行榜 */
- hideRank() {
- }
- /** 排行榜切页(-1上一页 0下一页 >0跳转到具体页数) */
- rankChangePage(page) {
- this.postMessage({
- "action": core.DomainAction.Paging,
- "page": page
- });
- }
- /** 保存最高分 */
- saveScore(score) {
- this.postMessage({
- "action": core.DomainAction.SaveScore,
- "score": score
- });
- core.Manager.wtsdk.saveScore({ score: score });
- }
- //↓↓ 广告类 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
- /** 显示或隐藏Banner广告 */
- adBanner(isShow) {
- try {
- if (isShow)
- this.ad.showBanner();
- else
- this.ad.hideBanner();
- }
- catch (e) {
- log("adBanner error:", e);
- }
- }
- /** 显示激励式广告 */
- adRewardedVideo() {
- try {
- this.ad.showRewardedVideoAd();
- }
- catch (e) {
- log("adBanner error:", e);
- }
- }
- /** 显示插屏广告 */
- adInterstitial() {
- try {
- this.ad.showInterstitialAd();
- }
- catch (e) {
- log("adBanner error:", e);
- }
- }
- /** 显示或隐藏格子广告 */
- adGrid(isShow) {
- // if(isShow) this.ad.showGridAd();
- // else this.ad.hideGridAd();
- }
- //↑↑ 广告类 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
- //↓↓ 录屏 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
- initRecorder() {
- this.recorder = tt.getGameRecorderManager();
- this.recorder.onStart(res => {
- log("录屏开始", res);
- core.Manager.eDispatcher.event(core.Event.RECORD_START, res);
- });
- this.recorder.onStop(res => {
- log("录屏停止", res);
- core.Manager.eDispatcher.event(core.Event.RECORD_STOP, res.videoPath);
- });
- this.recorder.onError(err => {
- log("录屏错误", err);
- core.Manager.eDispatcher.event(core.Event.RECORD_ERROR, err);
- });
- // GameRecorderManager.onResume(function callback)// 监听录屏继续事件
- // GameRecorderManager.onPause(function callback)// 监听录屏暂停事件
- // GameRecorderManager.onInterruptionBegin(function callback)// 监听录屏中断开始
- // GameRecorderManager.onInterruptionEnd(function callback)// 监听录屏中断结束
- }
- /** 开始录屏 */
- startRecord() {
- try {
- let maskInfo = this.recorder.getMark();
- let x = (Laya.stage.width - maskInfo.markWidth) / 2;
- let y = (Laya.stage.height - maskInfo.markHeight) / 2;
- //添加水印并且居中处理
- this.recorder.start({
- duration: 30,
- isMarkOpen: true,
- locLeft: x,
- locTop: y,
- });
- }
- catch (e) {
- log("startRecord error:", e);
- }
- }
- /** 停止录屏 */
- stopRecord() {
- try {
- this.recorder.stop();
- }
- catch (e) {
- log("stopRecord error:", e);
- }
- }
- /**
- * 更多游戏图标
- * @parame isShow 是否显示
- */
- moreGameBtn(isShow) {
- core.Manager.eDispatcher.offAllCaller(this);
- // const systemInfo = tt.getSystemInfoSync();
- // iOS 不支持,建议先检测再使用
- if (this.systemInfo.device !== "ios") {
- if (isShow) {
- if (!core.Manager.gameList || core.Manager.gameList.length == 0) {
- core.Manager.eDispatcher.on(core.Event.GET_MOREGAME_COMPLETE, this, () => { this.moreGameBtn(true); });
- return null;
- }
- if (!this._moreGameBtn)
- this._moreGameBtn = new ttGame.MoreGameIcon(this.moreGameParams);
- }
- else if (this._moreGameBtn) {
- this._moreGameBtn.destroy();
- this._moreGameBtn = null;
- }
- return this._moreGameBtn;
- }
- }
- /** 更多游戏按钮参数 */
- get moreGameParams() {
- return { x: 0, y: 0, w: 60, h: 60, appLaunchOptions: [] };
- }
- /** 显示更多游戏 */
- showMoreGame() {
- // const systemInfo = tt.getSystemInfoSync();
- // iOS 不支持,建议先检测再使用
- if (this.systemInfo.device !== "ios") {
- // 打开小游戏盒子
- tt.showMoreGamesModal({
- appLaunchOptions: []
- });
- }
- }
- }
- ttGame.BasePlatform = BasePlatform;
- })(ttGame || (ttGame = {}));
- /// <reference path="./ADManager.ts" />
- /// <reference path="./base/BasePlatform.ts" />
- var ttGame;
- /// <reference path="./ADManager.ts" />
- /// <reference path="./base/BasePlatform.ts" />
- (function (ttGame) {
- class Platform extends ttGame.BasePlatform {
- constructor() {
- super();
- }
- /** 普通分享的数据 */
- getShareData(title) {
- if (!title)
- title = "跟我一起去感受风的速度吧!";
- let data = {
- title: title,
- };
- core.ObjectUtil.addKeys(data, super.getShareData(title));
- return data;
- }
- /** 视频分享的数据 */
- getVideoShareData(videoPath) {
- let data = {
- query: "",
- // templateId: "81d7bjb2go51hggi19", // 替换成通过审核的分享ID
- title: "酷跑男女",
- desc: "跟我一起去感受风的速度吧!",
- extra: {
- videoPath: videoPath,
- videoTopics: ["#酷跑男女 #跟我一起去感受风的速度吧!"],
- withVideoId: true,
- videoTag: "rankTag1",
- }
- };
- core.ObjectUtil.addKeys(data, super.getVideoShareData(videoPath));
- return data;
- }
- /** 透传资源到子域 */
- sendRes() {
- //加载完成后,使用接口将图集透传到子域
- ttGame.SendRes.sendAtlasList(["res/atlas/res/imgs/rank.atlas", "res/atlas/res/imgs/revive.atlas",]);
- // SendRes.sendSinglePicList(["unpack/rankBg.png"]);
- // SendRes.sendJsonList(["test/1.json"]);
- }
- /** 更多游戏按钮参数 */
- get moreGameParams() {
- return { x: Laya.stage.width / 2, y: 258, w: 80, h: 80, appLaunchOptions: [] };
- }
- /** 显示即将超越好友 */
- showSurpass(score) {
- this.postMessage({ "action": core.DomainActionEx.Surpass,
- "score": score,
- });
- }
- /**显示称号 */
- showTitle(score) {
- this.postMessage({
- "action": core.DomainActionEx.Title,
- "score": score
- });
- }
- // /**显示荣誉 */
- // public showRongYu()
- // {
- // this.postMessage({
- // "action":core.DomainActionEx.showRY
- // })
- // }
- /** 发送登录检查保存分数 */
- sendLoginCheck() {
- log('发送登录检查保存分数');
- this.postMessage({ 'action': core.DomainActionEx.LoginCheck });
- }
- }
- ttGame.Platform = Platform;
- })(ttGame || (ttGame = {}));
- window.ttGame = ttGame;
- //首次加载时,初始化
- window.platform = new ttGame.Platform();
- var ttGame;
- (function (ttGame) {
- class SendRes {
- //将加载完成的图集,使用接口透传到子域
- static sendAtlasList(urls) {
- if (!urls)
- return;
- while (urls.length > 0) {
- let url = urls.pop();
- if (Laya.loader.getRes(url))
- Laya.TTMiniAdapter.sendAtlasToOpenDataContext(url);
- else
- Laya.loader.load(url, Laya.Handler.create(Laya.TTMiniAdapter, Laya.TTMiniAdapter.sendAtlasToOpenDataContext, [url]));
- }
- }
- //将加载完成的单个图片文件,使用接口透传到子域
- static sendSinglePicList(urls) {
- if (!urls)
- return;
- while (urls.length > 0) {
- let url = urls.pop();
- if (Laya.loader.getRes(url))
- Laya.TTMiniAdapter.sendSinglePicToOpenDataContext(url);
- else
- Laya.loader.load(url, Laya.Handler.create(Laya.TTMiniAdapter, Laya.TTMiniAdapter.sendSinglePicToOpenDataContext, [url]));
- }
- }
- //将加载完成的json文件,使用接口透传到子域
- static sendJsonList(urls) {
- if (!urls)
- return;
- while (urls.length > 0) {
- let url = urls.pop();
- if (Laya.loader.getRes(url))
- Laya.TTMiniAdapter.sendJsonDataToDataContext(url);
- else
- Laya.loader.load(url, Laya.Handler.create(Laya.TTMiniAdapter, Laya.TTMiniAdapter.sendJsonDataToDataContext, [url]));
- }
- }
- }
- ttGame.SendRes = SendRes;
- })(ttGame || (ttGame = {}));
- var ttGame;
- (function (ttGame) {
- class SystemInfo {
- constructor() {
- this.info = tt.getSystemInfoSync();
- }
- /** 设备:android,ios */
- get device() {
- return this.info.platform;
- }
- /** app名字 */
- get appName() {
- return this.info.appName;
- }
- }
- ttGame.SystemInfo = SystemInfo;
- })(ttGame || (ttGame = {}));
- var ttGame;
- (function (ttGame) {
- class MoreGameIcon extends Laya.Box {
- constructor(params) {
- super();
- this.ICON_SIZE = 120; //游戏图标的始尺寸
- this.zOrder = core.ZOrder.POPUP;
- this._appLaunchOptions = params.appLaunchOptions;
- this.pos(params.x, params.y);
- // this.size(params.w, params.h);
- this.scale(params.w / this.ICON_SIZE, params.h / this.ICON_SIZE);
- Laya.stage.addChild(this);
- }
- onAwake() {
- this._index = 0;
- this._icon = new Laya.Image();
- this._icon.anchorX = 0.5;
- this._icon.anchorY = 0.5;
- this.addChild(this._icon);
- this._icon.mouseEnabled = true;
- this._label = new Laya.Image(this.getRes("gdhw")); //
- this._label.anchorX = 0.5;
- this._label.anchorY = 0.5;
- this._label.y = 86;
- this.addChild(this._label);
- this._label.mouseEnabled = true;
- this._iconUrls = [];
- let gameList = core.Manager.gameList;
- for (let i = gameList.length - 1; i >= 0; i--) {
- if (gameList[i].rec_degree == 1)
- this._iconUrls.push(gameList[i].icon); //取热门游戏
- }
- if (this._iconUrls.length == 0)
- this._iconUrls.push(gameList[0].icon); //无热门游戏,推第一个进去,保证起码有一个游戏
- this._tweentimeLite = new core.TweenTimeLine(0);
- this._tweentimeLite.addToTween(this, { scaleX: this.scaleX * 0.8, scaleY: this.scaleX * 0.8 }, 600, Laya.Ease.backOut);
- this._tweentimeLite.addToTween(this, { scaleX: this.scaleX, scaleY: this.scaleX }, 600, Laya.Ease.backIn);
- }
- getRes(name) {
- return core.Manager.commonResPath + "gameIcon/" + name + ".png"; //指定取资源图片
- }
- onEnable() {
- super.onEnable();
- this.timerLoop(5000, this, this.changeSkin);
- this.changeSkin();
- this._tweentimeLite.start();
- this.on(Laya.Event.CLICK, this, this.onClick);
- this._icon.on(Laya.Event.LOADED, this, this.iconLoaded);
- }
- changeSkin() {
- if (this._index >= this._iconUrls.length)
- this._index = 0;
- this._icon.skin = this._iconUrls[this._index];
- this._index++;
- }
- iconLoaded() {
- this._icon.size(this.ICON_SIZE, this.ICON_SIZE); //每个图片大小可能不一样,加载完成重新设置一下
- }
- onClick(e) {
- // // 监听弹窗关闭
- // tt.onMoreGamesModalClose(function (res) {
- // log("modal closed", res);
- // });
- // // 监听小游戏盒子跳转
- // tt.onNavigateToMiniGameBox(function (res) {
- // log(res.errCode);
- // log(res.errMsg);
- // });
- // const systemInfo = tt.getSystemInfoSync();
- // // iOS 不支持,建议先检测再使用
- // if (systemInfo.platform !== "ios") {
- // // 打开小游戏盒子
- // tt.showMoreGamesModal({
- // appLaunchOptions: this._appLaunchOptions,
- // // success(res) { log("success", res.errMsg); },
- // // fail(res) { log("fail", res.errMsg); },
- // });
- // }
- if (window.platform) {
- platform.showMoreGame();
- }
- }
- onDisable() {
- super.onDisable();
- this.clearTimer(this, this.changeSkin);
- this._tweentimeLite.pause();
- this.off(Laya.Event.CLICK, this, this.onClick);
- this._icon.off(Laya.Event.LOADED, this, this.iconLoaded);
- }
- destroy() {
- super.destroy();
- this._tweentimeLite.destroy();
- this._tweentimeLite = null;
- this._appLaunchOptions = null;
- this._iconUrls = null;
- }
- }
- ttGame.MoreGameIcon = MoreGameIcon;
- })(ttGame || (ttGame = {}));
- //# sourceMappingURL=ttGame.js.map
|