You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
7.5 KiB
207 lines
7.5 KiB
1 week ago
|
/*
|
||
|
* @Descripttion:
|
||
|
* @version: 1.0.0
|
||
|
* @Author: YeeChan
|
||
|
* @Date: 2020-07-09 18:54:40
|
||
|
*/
|
||
|
|
||
|
import User from "../User/User";
|
||
|
|
||
|
import AppConfig from "../Config/AppConfig";
|
||
|
|
||
|
import GameReport, { ENTERTYPE } from "../Report/ZyZyReport";
|
||
|
import { DateUtils } from "../Util/DateUtils";
|
||
|
|
||
|
import PrefabManage, { GameType } from "../../Scripts/PrefabManager/PrefabManage";
|
||
|
import Common5 from "../../Platform/th/Common5";
|
||
|
import { GameStoryConfigData } from "../../Scripts/FirstSelectScene/GameStoryConfig";
|
||
|
import AppPlatform from "../Util/AppPlatform";
|
||
|
import UserManager from "../../Scripts/Manager/UserManager";
|
||
|
import CommonDefine from "../../Platform/th/CommonDefine";
|
||
|
|
||
|
|
||
|
//游戏管理器,游戏代码的入口
|
||
|
export default class GameMgr {
|
||
|
public isFirstLoadAD: boolean = false;
|
||
|
public isWinner: boolean = false;
|
||
|
private static _instance_custom: GameMgr = new GameMgr();
|
||
|
private saveTime = 0;
|
||
|
|
||
|
public static getInstance_custom(): GameMgr {
|
||
|
return GameMgr._instance_custom;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 预加载一些场景 在Main.ts中
|
||
|
*/
|
||
|
public preloadScene_custom() {
|
||
|
// PrefabManage.preloadPrefabByType(GameType.LinJiaDaYuan)
|
||
|
// cc.director.preloadScene("FMMainScene");
|
||
|
// cc.director.preloadScene("FMGameScene");
|
||
|
// cc.director.preloadScene("FMGameSettleWinScene");
|
||
|
// cc.director.preloadScene("FMGameSettleFailScene");
|
||
|
//LogUtils.warn_custom("GameMgr.getInstance().preloadScene_custom这里可以加载需要预加载的场景");
|
||
|
}
|
||
|
|
||
|
//在合适的时候 cc.director.preloadScene 预加载你的场景
|
||
|
|
||
|
/**
|
||
|
* 登录加载后跳转自己的场景
|
||
|
*/
|
||
|
public onLoadToWorldScene_custom() {
|
||
|
// cc.director.loadScene("FMMainScene", function (err, scene) {
|
||
|
// console.log("跳转游戏场景 FMMainScene")
|
||
|
// });
|
||
|
|
||
|
// console.error(User.getFirstInNew(), 'User.getFirstInNew')
|
||
|
// if(User.getFirstInNew()){
|
||
|
// console.error("老玩家重置数据");
|
||
|
// User.restartGame()
|
||
|
// // User.setFirstInNew(false)
|
||
|
// }
|
||
|
let time = new Date().getTime()
|
||
|
console.log('shaoyang_登录加载后跳转自己的场景', time - Common5.shiJianChuo)
|
||
|
if (User.getCurGameLevelIndex() == 0) {
|
||
|
if (AppPlatform.is_TT_GAME_custom()) {
|
||
|
this.getServerData()
|
||
|
}else{
|
||
|
this.loadScene()
|
||
|
}
|
||
|
// if (!Common5.gameConfig) {
|
||
|
// Common5.gameConfig = GameStoryConfigData;
|
||
|
// }
|
||
|
// Common5.selectGameInfo = Common5.gameConfig[0];
|
||
|
// GameMgr.getInstance_custom().onLoadToGameScene_custom();
|
||
|
} else {
|
||
|
cc.director.loadScene("FirstSelectScene", function (err, scene) {
|
||
|
console.log("跳转选关场景 FirstSelectScene");
|
||
|
Common5.ReportDY("inLevel", '任务001-登录游戏');
|
||
|
|
||
|
GameReport.setLoadingFinishTime(DateUtils.getNowTime_custom())
|
||
|
GameReport.getOpenUserId()
|
||
|
if (User.getFirstInNew()) {
|
||
|
Common5.ReportDY("inLevel", '任务001-初次进入游戏');
|
||
|
User.setFirstInNew(false);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
// if(AppPlatform.is_TT_GAME_custom()){
|
||
|
// TTAPI.onShow((res)=>{
|
||
|
|
||
|
// console.log(res, "从侧边栏进入游戏 MainScene");
|
||
|
// if(res.launch_from == 'homepage' && res.location == 'sidebar_card'){
|
||
|
// Common5.isCeBianLanEnter = true
|
||
|
// EventMgr.emitEvent_custom(ryw_Event.CheckIsEnterFromCeBianLan)
|
||
|
// }
|
||
|
// Common5.playMusicCustom('CommonRes', 'sound/背景音');
|
||
|
// })
|
||
|
|
||
|
// TTAPI.checkScene(()=>{
|
||
|
// //EventMgr.emitEvent_custom(ryw_Event.CheckCeBianLan, true)
|
||
|
// },()=>{
|
||
|
// //EventMgr.emitEvent_custom(ryw_Event.CheckCeBianLan, false)
|
||
|
// })
|
||
|
// }
|
||
|
}
|
||
|
|
||
|
getServerData() {
|
||
|
if (!AppPlatform.is_TT_GAME_custom()) {
|
||
|
//登录获取
|
||
|
} else {
|
||
|
let userID = User.getUserId()
|
||
|
console.error(userID, '读取数据userID')
|
||
|
|
||
|
if (userID == '') {
|
||
|
//读取数据
|
||
|
let onFail = () => { }
|
||
|
let onSuccess = (response) => {
|
||
|
console.log(response, '登录成功获取userid++1+=====')
|
||
|
if (response.msg == 'OK') {
|
||
|
User.setUserId(response.openid)
|
||
|
User.setFirstIn(false);
|
||
|
console.warn('获取服务器数据完成')
|
||
|
let comSuccesscall = (GameData) => {
|
||
|
if (GameData) {
|
||
|
UserManager.readDataByUrl(GameData)
|
||
|
}
|
||
|
setTimeout(() => {
|
||
|
this.loadScene()
|
||
|
}, 500);
|
||
|
}
|
||
|
|
||
|
let comFailcall = () => {
|
||
|
setTimeout(() => {
|
||
|
this.loadScene()
|
||
|
}, 500);
|
||
|
}
|
||
|
CommonDefine.getServerData(comSuccesscall, comFailcall)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let appsuccesscall = (code) => {
|
||
|
console.error(code, '没有code获取code22')
|
||
|
CommonDefine.getLoginInfo(code, onFail, onSuccess)
|
||
|
}
|
||
|
let appfailcall = () => {
|
||
|
//
|
||
|
console.error('appfailcall')
|
||
|
setTimeout(() => {
|
||
|
this.loadScene()
|
||
|
}, 500);
|
||
|
}
|
||
|
AppPlatform.loginPlatform_custom(appsuccesscall, appfailcall)
|
||
|
console.error('读取数据22')
|
||
|
} else {
|
||
|
console.log('不需要读取数据')
|
||
|
setTimeout(() => {
|
||
|
this.loadScene()
|
||
|
}, 500);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public loadScene() {
|
||
|
if (User.getCurGameLevelIndex() == 0) {
|
||
|
if (!Common5.gameConfig) {
|
||
|
Common5.gameConfig = GameStoryConfigData;
|
||
|
}
|
||
|
Common5.selectGameInfo = Common5.gameConfig[0];
|
||
|
GameMgr.getInstance_custom().onLoadToGameScene_custom();
|
||
|
} else {
|
||
|
cc.director.loadScene("FirstSelectScene");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public onLoadToGameScene_custom() {
|
||
|
cc.director.loadScene("MainScene", function (err, scene) {
|
||
|
console.log("跳转游戏场景 MainScene");
|
||
|
if (User.getFirstStepIndex() == 0) {
|
||
|
Common5.ReportDY("inLevel", '任务001-开始第一关');
|
||
|
User.setFirstStepIndex(1);
|
||
|
}
|
||
|
//Common5.ReportDY("inLevel", `进入第${Common5.selectGameInfo.index + 1}幕剧情`);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public onLoadToSelectScene_custom() {
|
||
|
cc.director.loadScene("FirstSelectScene", function (err, scene) {
|
||
|
console.log("跳转选关场景 FirstSelectScene");
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
//游戏存档,合适的时候调用它来保存
|
||
|
//游戏存档,合适的时候调用它来保存
|
||
|
public saveGameData_custom(bForceSave?) {
|
||
|
//存本地
|
||
|
if (Date.now() - this.saveTime > 3000 || bForceSave) {
|
||
|
this.saveTime = Date.now();
|
||
|
cc.sys.localStorage.setItem("data" + AppConfig.AppID_custom, User.getSaveData_custom());
|
||
|
console.log("save data")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|