mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
提交
This commit is contained in:
parent
931f580082
commit
fae958aac6
File diff suppressed because it is too large
Load Diff
@ -30,10 +30,10 @@ import { Component } from "cc";
|
||||
|
||||
// let APIPath = `http://localhost:8080`
|
||||
// let WsPath = `ws://localhost:8080/websocket`
|
||||
let APIPath = `http://192.168.1.23:8080`
|
||||
let WsPath = `ws://192.168.1.23:8080/websocket`
|
||||
// let APIPath = `http://192.168.0.113:8080`
|
||||
// let WsPath = `ws://192.168.0.113:8080/websocket`
|
||||
// let APIPath = `http://192.168.1.23:8080`
|
||||
// let WsPath = `ws://192.168.1.23:8080/websocket`
|
||||
let APIPath = `http://192.168.0.128:8080`
|
||||
let WsPath = `ws://192.168.0.128:8080/websocket`
|
||||
// let APIPath = `https://api.pet.jisol.cn`
|
||||
// let WsPath = `wss://api.pet.jisol.cn/websocket`
|
||||
|
||||
@ -148,7 +148,7 @@ export class JLoaderBattle extends JLoaderSystem{
|
||||
|
||||
//资源
|
||||
resources:{[id:number]:Asset} = {};
|
||||
foreverResources:number[] = []; //永久资源Id
|
||||
battleResources:number[] = []; //战斗资源Id
|
||||
|
||||
async onInit(): Promise<any> {
|
||||
|
||||
@ -161,28 +161,28 @@ export class JLoaderBattle extends JLoaderSystem{
|
||||
app.loading.setCurrent(JLoaderBattle.loadingInit);
|
||||
|
||||
//默认加载全部资源
|
||||
await this.loadForeverResources(...TD.TbBattleResource.getDataList());
|
||||
await this.loadBattleResources(...TD.TbBattleResource.getDataList());
|
||||
|
||||
app.loading.ok(JLoaderBattle.loadingInit);
|
||||
|
||||
}
|
||||
|
||||
//加载永久资源
|
||||
async loadForeverResources(...ress:TB.TbBattleResource[]){
|
||||
//加载战斗资源
|
||||
async loadBattleResources(...ress:TB.TbBattleResource[]){
|
||||
|
||||
for (const res of ress) {
|
||||
await this.loadForeverResource(res);
|
||||
await this.loadBattleResource(res);
|
||||
}
|
||||
|
||||
}
|
||||
//加载永久资源
|
||||
loadForeverResource(res:TB.TbBattleResource){
|
||||
//加载战斗资源
|
||||
loadBattleResource(res:TB.TbBattleResource){
|
||||
return (new Promise<void>(r => {
|
||||
|
||||
let Type:new ()=>Asset = [sp.SkeletonData,SpriteFrame][res.type];
|
||||
|
||||
this.bundle.load(res.path,Type,(error,data) => {
|
||||
if(this.foreverResources.indexOf(res.id) < 0){
|
||||
if(this.battleResources.indexOf(res.id) < 0){
|
||||
//添加永久资源
|
||||
this.resources[res.id] = data;
|
||||
data.addRef();
|
||||
@ -213,14 +213,14 @@ export class JLoaderBattle extends JLoaderSystem{
|
||||
}))
|
||||
}
|
||||
|
||||
//销毁永久资源
|
||||
clearForeverResources(...ress:TB.TbBattleResource[]){
|
||||
this.foreverResources.forEach(id => {
|
||||
//销毁长久资源
|
||||
clearBattleResources(...ress:TB.TbBattleResource[]){
|
||||
this.battleResources.forEach(id => {
|
||||
if(this.resources[id]){
|
||||
this.resources[id].decRef();
|
||||
}
|
||||
});
|
||||
this.foreverResources = [];
|
||||
this.battleResources = [];
|
||||
this.onUpdateResources();
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,12 @@ import { Camera } from "cc";
|
||||
import GBaseMode from "./GBaseMode";
|
||||
import { Node } from "cc";
|
||||
import { instantiate } from "cc";
|
||||
import { app } from "../App";
|
||||
import { TD, app } from "../App";
|
||||
import { JNFrameInfo, JNSyncFrameEvent } from "../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
||||
import { CCObject } from "cc";
|
||||
import { Env, EnvCurrent } from "../Env";
|
||||
import { TB } from "../../resources/config/data/schema";
|
||||
import BattleResource from "../tools/BattleResource";
|
||||
|
||||
export enum BattleMode{
|
||||
//无尽模式
|
||||
@ -26,6 +28,8 @@ export interface GBattleModeInfo{
|
||||
export enum GBattleModeEvent{
|
||||
//关闭模式
|
||||
Close = "GBattleModeEvent_Close",
|
||||
StartLoadingResource = "GBattleModeEvent_StartLoadingResource",
|
||||
EndLoadingResource = "GBattleModeEvent_EndLoadingResource",
|
||||
}
|
||||
|
||||
//全局战斗模式管理器
|
||||
@ -61,6 +65,12 @@ export default class GBattleModeManager extends Singleton {
|
||||
//模式数据
|
||||
data:any;
|
||||
|
||||
//是否加载资源
|
||||
isLoadingResource:boolean = false;
|
||||
|
||||
//加载index
|
||||
loadingIndex:number = 0;
|
||||
|
||||
//初始化管理器
|
||||
async onInit(info:GBattleModeInfo){
|
||||
|
||||
@ -77,8 +87,13 @@ export default class GBattleModeManager extends Singleton {
|
||||
}
|
||||
|
||||
//打开指定模式
|
||||
// isAuto 是否自动推帧
|
||||
// data 模式数据
|
||||
// res 资源加载列表 (因为是帧同步所以打开模式前必须提前加载可能使用的资源)
|
||||
async Open(mode:BattleMode = null,isAuto:boolean = false,data:any = this.data){
|
||||
|
||||
this.Close();
|
||||
|
||||
this.data = data;
|
||||
|
||||
if(!this.current && mode == null){
|
||||
@ -89,10 +104,25 @@ export default class GBattleModeManager extends Singleton {
|
||||
}else if(mode == null){
|
||||
return;
|
||||
}
|
||||
|
||||
this.current = mode;
|
||||
this.setAuto(isAuto);
|
||||
|
||||
//加载资源
|
||||
let loadingIndex = (this.loadingIndex+=1);
|
||||
this.isLoadingResource = true;
|
||||
app.event.emit(GBattleModeEvent.StartLoadingResource);
|
||||
console.log("[GBattleModeManager] 加载资源");
|
||||
await BattleResource.loadResource(mode,data);
|
||||
console.log("[GBattleModeManager] 加载结束",loadingIndex,this.loadingIndex);
|
||||
if(this.loadingIndex == loadingIndex){
|
||||
this.isLoadingResource = false;
|
||||
app.event.emit(GBattleModeEvent.EndLoadingResource);
|
||||
}else{
|
||||
//如果加载中途切换了模式则直接返回
|
||||
return;
|
||||
}
|
||||
|
||||
//资源加载完成则显示世界
|
||||
app.sync.onReset();
|
||||
app.sync.onStart();
|
||||
|
||||
|
26
JisolGameCocos/assets/script/tools/BattleResource.ts
Normal file
26
JisolGameCocos/assets/script/tools/BattleResource.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { TB } from "../../resources/config/data/schema";
|
||||
import { TD, app } from "../App";
|
||||
import { BattleMode } from "../battle/GBattleModeManager";
|
||||
|
||||
|
||||
export default class BattleResource {
|
||||
|
||||
//根据参数获取可能加载的资源
|
||||
static getResources(mode:BattleMode,data:any):TB.TbBattleResource[]{
|
||||
switch(mode){
|
||||
default:
|
||||
return TD.TbBattleResource.getDataList();
|
||||
}
|
||||
}
|
||||
|
||||
//加载资源
|
||||
static async loadResource(mode:BattleMode,data:any){
|
||||
|
||||
let resources = this.getResources(mode,data);
|
||||
//加载资源
|
||||
await app.battleRes.loadBattleResources(...resources);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d90fa0e9-c8d6-44f4-aad2-41aac59b7e59",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user