123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617 |
- import { _decorator, AudioClip, AudioSource, Component, Node, Size, Sprite, SpriteFrame, sys, UITransform, Vec3 } from 'cc';
- import { game_run } from './game_run';
- import { attributes_data, event_item, LevelItemData, other_widget_finish_listen_item, scene_item_data, sysMessage, task_data, ui_att_item, UserData, widget_item_data } from '../../data/data';
- import { config } from '../config';
- import { sceneManager } from './sceneManager';
- import { control } from '../edit/control';
- import { http } from '../http';
- import { tools } from '../tools';
- import { main } from '../main';
- import { taskServce } from './TaskSchedule/taskServce';
- import { ClientEvent } from '../clientEvent';
- import { sysSound } from './sysSound';
- const { ccclass, property } = _decorator;
- @ccclass('gameManager')
- export class gameManager extends Component {
- private mGameRun:game_run = null;
- private mGameData:scene_item_data[] = [];
- private mCurSceneIndex:number =0; //当前第几个场景
- public static Singleton:gameManager = null;
- private static g_userData:UserData;
- public static res_map:Map<string,SpriteFrame> = new Map()
- public static mp3_cache:Map<string,AudioClip> = new Map()
- private mLevelData:LevelItemData = null;
- private static sys_data:sysMessage = null;
- @property(sceneManager) mSceneManager:sceneManager = null;
- @property(sysSound) mSysSound:sysSound = null;
- protected start(): void {
- gameManager.Singleton = this;
- }
- public static loadSceneRes(level_id:number,scene_num:number,cb){
- let count = 0;
- let num = 0;
- let scene_count = 1;
- // console.log("scene_num",scene_num)
- let call = ()=>{
- count++;
- // console.log("scene_num",scene_num,scene_count,count,num)
- if(scene_count>=scene_num){
- if(count>=num){
- // console.log("gameManager.res_map",gameManager.res_map)
- cb()
- }
- }
- }
- for (let i = 0; i <= scene_num; i++) {
- let url = http.get_level_resource(level_id,i)
- http.run_get(url,(err,data)=>{
- if(!err){
- let _data = JSON.parse(data)
- scene_count++;
- num += _data.content.length;
- // console.log("run_get:",_data.content.length)
- for (let index = 0; index < _data.content.length; index++) {
- const url:string = _data.content[index];
- console.log('url=',url)
- let hz = url.substring(url.length-3,url.length);
-
- if(hz==="png"||hz==="jpg"){
- // if(gameManager.res_map.get(url)!=null){
- // call()
- // }else{
-
- // }
- tools.loadSceneImg(url,(d)=>{
- gameManager.res_map.set(d.url,d.sf)
- call()
- })
-
- }
- if(hz==="mp3"){
- // if(gameManager.mp3_cache.get(url)!=null){
- // call()
- // }else{
-
- // }
- tools.loadSceneMp3(url,(d)=>{
- gameManager.mp3_cache.set(d.url,d.clip)
- call()
- })
- }
-
-
- }
- }else{
- tools.showToast(`获取关卡错误${err}`)
- }
- })
- }
- }
- public setLevelData(data:LevelItemData){
- this.mLevelData = data;
- }
- public getLevelData(){
- return this.mLevelData;
- }
- public static setSysData(data:sysMessage){
- gameManager.sys_data = data;
- }
- public static getSysData(){
- return gameManager.sys_data;
- }
- public static loadSceneMp3(){
- }
- public static getUserData():UserData{
- let str = sys.localStorage.getItem(config.USER_DATA)
- if(str==undefined||str==""||str==null){
- return null;
- }
- let user:UserData = JSON.parse(str)
- return user;
- }
- public static getStaticUserData(){
- return gameManager.g_userData
- }
- public static setUserData(user:UserData){
- gameManager.g_userData = user;
- gameManager.saveUserData()
- }
- public static saveUserData(){
- if(gameManager.g_userData!=null){
- sys.localStorage.setItem(config.USER_DATA, JSON.stringify(gameManager.g_userData));
- }
- }
- public reLife(){
- gameManager.Singleton.startLevelGame()
- }
- public reStartGame(){
- this.mCurSceneIndex = 0;
- gameManager.Singleton.startLevelGame()
- }
- public levleIsUnLock(levle_id:number){
- let isunlock = false;
- for (let index = 0; index < gameManager.getStaticUserData().unlock_levels.length; index++) {
- const id = gameManager.getStaticUserData().unlock_levels[index];
- if(id==levle_id){
- isunlock = true;
- break;
- }
- }
- return isunlock
- }
- public unLockLevel(levle_id:number){
- let is_have = false;
- for (let index = 0; index < gameManager.getStaticUserData().unlock_levels.length; index++) {
- const id = gameManager.getStaticUserData().unlock_levels[index];
- if(id==levle_id){
- is_have = true;
- break;
- }
- }
- if(!is_have){
- gameManager.getStaticUserData().unlock_levels.push(levle_id)
- gameManager.saveUserData()
- gameManager.Singleton.sync_data()
- }
- }
- public sync_data(){
- let url = http.sync_data()
- let unlock_levels = gameManager.getStaticUserData().unlock_levels;
- http.run_post(url,{"unlock_levels":JSON.stringify(unlock_levels)},(err,data)=>{
- if(!err){
-
- }
- })
- }
- public nextScene(){
- this.mCurSceneIndex++;
- let not_scene = false;
- if(this.mCurSceneIndex>=this.mGameData.length){
- not_scene = true;
- }
- if(!not_scene){
- let task_data = this.mGameData[this.mCurSceneIndex]._task_data
- if(task_data==null||task_data==undefined) {
- return tools.showToast('没有任务')
- }
- let call_back =(()=>{
- this.mGameRun.unInit()
- this.startLevelGame()
- })
- if(task_data.is_open_interlude_default_animation) {
- this.onLaunch(()=>{
- call_back()
- })
- } else {
- call_back()
- }
- }else{
- // tools.showToast("没有场景了!")
- }
- // this.onLaunch(()=>{
- // this.mCurSceneIndex++;
- // let not_scene = false;
- // if(this.mCurSceneIndex>=this.mGameData.length){
- // not_scene = true;
- // }
- // if(!not_scene){
- // this.mGameRun.unInit()
- // this.startLevelGame()
- // }else{
- // // tools.showToast("没有场景了!")
- // }
- // })
- }
- public gameOver(){
- ClientEvent.dispatchEvent(config.EventRun.ON_WIN)
- }
- public backGameList(){
- if(this.getLevelData()!=null){
- this.unscheduleAllCallbacks()
- this.mGameRun.backGameList()
- }
- }
- public initEvent(){
- ClientEvent.offAll(config.EventRun.NOTICE_EVENT)
- ClientEvent.offAll(config.EventRun.WIDGET_FINISH)
- ClientEvent.offAll(config.EventRun.WIDGET_FAIL)
- ClientEvent.offAll(config.EventRun.WIDGET_DRAG_OTHER_FINISH)
- ClientEvent.offAll(config.EventRun.WIDGET_QUESTION_SELECT_FINISH)
- ClientEvent.offAll(config.EventRun.ON_WIDGET_FINISH_COLLECT_EVENT)
- ClientEvent.offAll(config.EventRun.WIDGET_HIDE)
- ClientEvent.offAll(config.EventRun.SHOW_ZHAO_BU_TONG_FINISH_STATUS)
- ClientEvent.offAll(config.EventRun.ON_ZHAO_BU_TONG_ALL_FINISH)
- ClientEvent.offAll(config.EventRun.TOP_VIEW_CLOSE)
- ClientEvent.offAll(config.EventRun.TOP_VIEW_FINISH)
- ClientEvent.offAll(config.EventRun.TOP_VIEW_FAIL)
- ClientEvent.offAll(config.EventRun.TOP_VIEW_HIDE)
- ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_FAIL)
- ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_START)
- ClientEvent.offAll(config.EventRun.ON_SHOW_RULE_BTN)
- ClientEvent.offAll(config.EventRun.ON_BOSS_HURT)
- ClientEvent.on(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
- ClientEvent.on(config.EventRun.WIDGET_FAIL,this.onWidgetFailEvent.bind(this),this)
- ClientEvent.on(config.EventRun.WIDGET_DRAG_OTHER_FINISH,this.onWidgetDragOtherFinishEvent.bind(this),this)
- ClientEvent.on(config.EventRun.WIDGET_QUESTION_SELECT_FINISH,this.onWidgetQuestionSelectFinishEvent.bind(this),this)
- ClientEvent.on(config.EventRun.TOP_VIEW_CLOSE,this.onUiCloseEvent.bind(this),this)
- ClientEvent.on(config.EventRun.TOP_VIEW_FINISH,this.onUiFinishEvent.bind(this),this)
- ClientEvent.on(config.EventRun.TOP_VIEW_FAIL,this.onUiFailEvent.bind(this),this)
- ClientEvent.on(config.EventRun.TOP_VIEW_HIDE,this.onUiHideEvent.bind(this),this)
- ClientEvent.on(config.EventRun.ON_COUNT_DOWN_FAIL,this.onCountDownFailEvent.bind(this),this)
- ClientEvent.on(config.EventRun.ON_COUNT_DOWN_START,this.onStartCountDownEvent.bind(this),this)
- }
- public initGR(gr:game_run){
- this.mGameRun = gr;
- gameManager.Singleton = this;
- this.mSceneManager.init(this)
- this.clearRes()
- }
- public clearRes(){
- gameManager.res_map.clear()
- gameManager.mp3_cache.clear()
- }
- public init(gr:game_run,data:scene_item_data[],callback=null){
- this.mGameRun = gr;
- gameManager.Singleton = this;
- this.mSceneManager.init(this)
- this.mCurSceneIndex = main.Singleton.edit_scene_view.getCurSelectSceneIndex()
- // this.postLevelInfo(id,scene)
- // this.startLevelGame()
- // console.log("control.Singleton.get_bag_data().content",control.Singleton.get_bag_data())
- this.mGameData = data;
- if( this.mGameData.length<=0){
- return tools.showToast("错误的场景信息")
- }
- this.startLevelGame(callback)
- }
- public runGame(data:scene_item_data[]){
- this.mCurSceneIndex = 0;
- this.mGameData = data;
- if( this.mGameData.length<=0){
- return tools.showToast("错误的场景信息")
- }
- this.startLevelGame()
- }
- public onLaunch(call,delay=0.7){
- this.mGameRun.onlaunch(call,delay)
- }
- FilterChildScene(data:scene_item_data[]){
- let temp_scene = []
- for (let index = 0; index < data.length; index++) {
- const element = data[index];
- if(!element.is_child_scene){
- temp_scene.push(element)
- }
- }
- return temp_scene;
- }
- protected onDestroy(): void {
- ClientEvent.off(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
- ClientEvent.off(config.EventRun.WIDGET_DRAG_OTHER_FINISH,this.onWidgetDragOtherFinishEvent.bind(this),this)
- ClientEvent.off(config.EventRun.WIDGET_QUESTION_SELECT_FINISH,this.onWidgetQuestionSelectFinishEvent.bind(this),this)
- }
- public startLevelGame(callback=null){
- this.mGameRun.unInit()
- this.initEvent()
- if(callback!=null) { callback() }
- // console.log("this.mGameData",this.mGameData,this.mCurSceneIndex)
- this.mSceneManager.startLevelGame(this.mGameData[this.mCurSceneIndex])
- taskServce.initTask(this.mGameData[this.mCurSceneIndex]._task_data)
- this.scheduleOnce(()=>{
- this.startGame()
- },0.5)
- if(gameManager.Singleton.getLevelData()){
- // this.mSceneManager.playMusic(this.mLevelData.piped_music,true)
- }
- }
- public loadSceneTask(data: task_data) {
- this.mGameRun.loadSceneTask(data)
- }
- public loadScene(pages: scene_item_data[],type:number){
- this.mGameRun.loadSceneLayer(pages,type)
- }
- public loadUi(ui_widge_list:widget_item_data[]){
- this.mGameRun.loadUILayer(ui_widge_list)
- }
- public loadTextSound(ui_widge_list:widget_item_data[]){
- this.mGameRun.loadTextSound(ui_widge_list)
- }
- public loadQuestion(ui_widge_list:widget_item_data[]){
- this.mGameRun.initQuestionList(ui_widge_list)
- }
- public initCountDownList(ui_widge_list:widget_item_data[]){
- this.mGameRun.initCountDownList(ui_widge_list)
- }
- public initTaskUi(data:task_data){
- this.mGameRun.initTaskUi(data)
- }
- public startGame(){
- taskServce.startFirstEvent()
- }
- public showCheck(call){
- this.mGameRun.showCheck(call)
- }
- public showLoadingLevel(){
- this.mGameRun.showLoadingLevel()
- }
- public hideLoadingLevel(){
- this.mGameRun.hideLoadingLevel()
- }
- public static getWidgetList(scene_data:scene_item_data):widget_item_data[]{
- let temp:widget_item_data[] = []
- for (let index = 0; index < scene_data.page_widget_list.length; index++) {
- const data = scene_data.page_widget_list[index];
- if(data.type<=4 ||data.type==config.Widget_Type_List.CONTAINER_LAYER){
- temp.push(data)
- }
- }
- return temp;
- }
- public static getUIWidgetList(scene_data:scene_item_data){
- let temp:widget_item_data[] = []
- for (let index = 0; index < scene_data.page_widget_list.length; index++) {
- const data = scene_data.page_widget_list[index];
- if(data.type===config.Widget_Type_List.UI_TOP){
- if(data.att.top_data!=null&&data.att.top_data.top_ui_type!=config.top_view_type.__null){
- temp.push(data)
- }
- }
- }
- return temp;
- }
- public static getQuestionwidgetList(scene_data:scene_item_data){
- let temp:widget_item_data[] = []
- for (let index = 0; index < scene_data.page_widget_list.length; index++) {
- const data = scene_data.page_widget_list[index];
- if(data.type===config.Widget_Type_List.QUESTION_SELECT){
- if(data.att.question_select!=null){
- temp.push(data)
- }
- }
- }
- return temp;
- }
- public static getTextSoundWidgetList(scene_data:scene_item_data){
- let temp:widget_item_data[] = []
- for (let index = 0; index < scene_data.page_widget_list.length; index++) {
- const data = scene_data.page_widget_list[index];
- if(data.type===config.Widget_Type_List.TEXT_SOUND){
- if(data.att.text_sound_data!=null){
- temp.push(data)
- }
- }
- }
- return temp;
- }
- public static getCountDownWidgetList(scene_data:scene_item_data){
- let temp:widget_item_data[] = []
- for (let index = 0; index < scene_data.page_widget_list.length; index++) {
- const data = scene_data.page_widget_list[index];
- if(data.type===config.Widget_Type_List.COUNT_DOWN){
- if(data.att.count_down!=null){
- temp.push(data)
- }
- }
- }
- return temp;
- }
- public static getCacheSpriteFrameByName(sfName:string){
- // return control.res_map.get(sfName)
- return gameManager.res_map.get(sfName)
- }
- public static getCacheSoundByName(sfName:string){
- // return control.mp3_cache.get(sfName)
- return gameManager.mp3_cache.get(sfName)
- }
- public static initUiBaseAtt(node:Node,att:ui_att_item){
- node.getComponent(UITransform).setContentSize(new Size(att.width,att.height))
- node.position = new Vec3(att.x,att.y);
- node.getComponent(Sprite).spriteFrame = gameManager.getCacheSpriteFrameByName(att.res)
- }
- onWidgetFinishEvent(widget_id:number, finish_event_item:event_item){
- taskServce.onWidgetFinishEvent(widget_id, finish_event_item)
- }
- onWidgetFailEvent(widget_id:number){
- taskServce.onWidgetFailEvent(widget_id)
- }
- onWidgetQuestionSelectFinishEvent(widget_id:number, score:number) {
- taskServce.onWidgetQuestionSelectFinishEvent(widget_id, score)
- }
- onWidgetDragOtherFinishEvent(widget_id:number, score:number) {
- taskServce.onWidgetDragOtherFinishEvent(widget_id, score)
- }
- onUiCloseEvent(event_id:number){
- taskServce.extEventByEventId(event_id)
- }
- onUiFinishEvent(event_id:number){
- taskServce.extEventByEventId(event_id)
- }
- onUiFailEvent(event_id:number){
- taskServce.extEventByEventId(event_id)
- }
- onUiHideEvent(widget_id:number) {
- taskServce.checkFinishZhaoXiJieWidget(widget_id)
- }
- onCountDownFailEvent(event_id:number){
- taskServce.extEventByEventId(event_id)
- }
- onStartCountDownEvent(event_id:number){
- taskServce.extEventByEventId(event_id)
- }
-
- exeEvent(event_id:number){
- taskServce.extEventByEventId(event_id)
- }
- exeSuccessTriggerEvent(trigger_event_id:number) {
- taskServce.exeSuccessTriggerEvent(trigger_event_id)
- }
- exeNextDelayEvent(event_item:event_item) {
- taskServce.exeNextDelayEvent(event_item)
- }
- showFindRuleTips(){
- this.mGameRun.showFindRuleTips()
- }
- showTips(){
- this.mGameRun.showTips()
- }
- showRule(){
- this.mGameRun.showRule()
- }
- getSceneManager(){
- return this.mSceneManager;
- }
- IsOpenRuleStatus(){
- return taskServce.guo_ju_qing_binding_event_id==-1;
- }
- public checkWidgetList(list:other_widget_finish_listen_item[],is_finish_status:boolean=false):other_widget_finish_listen_item[]{
- let event_list = [];
- for (let index = 0; index < list.length; index++) {
- const item = list[index];
- let isFinish = this.mGameRun.isCurScenePageCheckWidgetFinish(item.widget_id)
- // console.log('item.widget_id=',item.widget_id, 'isFinish=',isFinish)
- let event_id = item.event_id;
- if(event_id!=-1) {
- if(is_finish_status && isFinish) {
- event_list.push(item)
- }
- if(!is_finish_status && !isFinish) {
- event_list.push(item)
- }
- }
- }
- return event_list;
- }
- public isCurScenePageCheckWidgetFinish(widget_id:number){
- return this.mGameRun.isCurScenePageCheckWidgetFinish(widget_id);
- }
- public isCurScenePageCheckWidgetShow(widget_id:number){
- return this.mGameRun.isCurScenePageCheckWidgetShow(widget_id);
- }
- //点击按钮音效
- public sys_click_button_music(){
- if(gameManager.sys_data!=null){
- this.mSysSound.playSound(gameManager.sys_data.content.sys_click_button_music)
- }
- }
- // //失败吓人音效
- // public sys_fail_scary_music(){
- // if(gameManager.sys_data!=null){
- // this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_scary_music)
- // }
- // }
- //失败后攻击音效
- public sys_fail_attack_music(){
- if(gameManager.sys_data!=null){
- this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_attack_music)
- }
- }
- //失败提示音效
- public sys_fail_prompt_music(){
- if(gameManager.sys_data!=null){
- this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_prompt_music)
- }
- }
- //正确通关音效
- public sys_success_complete_music(){
- if(gameManager.sys_data!=null){
- this.mSysSound.playSound(gameManager.sys_data.content.sys_success_complete_music)
- }
- }
- //点击正确细节音效
- public sys_click_correct_detail_music(){
- if(gameManager.sys_data!=null){
- this.mSysSound.playSound(gameManager.sys_data.content.sys_click_correct_detail_music)
- }
- }
- public getCurSceneIndex(){
- return this.mCurSceneIndex;
- }
- public static LookVideoCallBack(call){
- if(call!=null){
- call()
- }
- }
- public getCurSceneLayerPage(){
- return this.mGameRun.getCurSceneLayerPage()
- }
- }
|