mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
提交
This commit is contained in:
@@ -18,13 +18,15 @@ import JLoaderSystem from "../../extensions/ngame/assets/ngame/system/JLoaderSys
|
||||
import { sp } from "cc";
|
||||
import { SpriteFrame } from "cc";
|
||||
import Loading from "../../extensions/ngame/assets/ngame/util/Loading";
|
||||
import { Tables } from "../resources/config/data/schema";
|
||||
import { TB, Tables } from "../resources/config/data/schema";
|
||||
import { JsonAsset } from "cc";
|
||||
import { GAction } from "./consts/GAction";
|
||||
import { StorageData, StorageEnum } from "./consts/GData";
|
||||
import { JAPI, JAPIConfig } from "../../extensions/ngame/assets/ngame/util/JAPI";
|
||||
import { AppData } from "./AppData";
|
||||
import AppAction from "./AppAction";
|
||||
import { Asset } from "cc";
|
||||
import { Component } from "cc";
|
||||
|
||||
// let APIPath = `http://localhost:8080`
|
||||
// let WsPath = `ws://localhost:8080/websocket`
|
||||
@@ -144,6 +146,10 @@ export class JLoaderBattle extends JLoaderSystem{
|
||||
static loading = "JLoaderBattle";
|
||||
static loadingInit = "JLoaderBattle_Init";
|
||||
|
||||
//资源
|
||||
resources:{[id:number]:Asset} = {};
|
||||
foreverResources:number[] = []; //永久资源Id
|
||||
|
||||
roleSpine:{[id:number]:sp.SkeletonData} = {}; //角色Spine
|
||||
roleResImage:{[id:number]:SpriteFrame} = {}; //角色战斗素材图片
|
||||
roleResSpine:{[id:number]:sp.SkeletonData} = {}; //角色战斗素材Spine
|
||||
@@ -205,6 +211,80 @@ export class JLoaderBattle extends JLoaderSystem{
|
||||
|
||||
}
|
||||
|
||||
//加载永久资源
|
||||
async loadForeverResources(...ress:TB.TbBattleResource[]){
|
||||
|
||||
for (const res of ress) {
|
||||
await this.loadForeverResource(res);
|
||||
}
|
||||
|
||||
}
|
||||
//加载永久资源
|
||||
loadForeverResource(res:TB.TbBattleResource){
|
||||
return (new Promise<void>(r => {
|
||||
this.bundle.load(res.path,(error,data) => {
|
||||
if(this.foreverResources.indexOf(res.id) < 0){
|
||||
//添加永久资源
|
||||
this.resources[res.id] = data;
|
||||
data.addRef();
|
||||
}
|
||||
r();
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
//加载组件资源
|
||||
async loadComponentResource<T extends Asset>(res:TB.TbBattleResource,comp:Component):Promise<T>{
|
||||
return (new Promise<T>(r => {
|
||||
this.bundle.load(res.path,(error,data) => {
|
||||
if(!this.resources[res.id])
|
||||
this.resources[res.id] = data;
|
||||
//添加资源次数
|
||||
data.addRef();
|
||||
//添加销毁资源引用
|
||||
let onDestroy = comp["onDestroy"];
|
||||
comp["onDestroy"] = () => {
|
||||
if(onDestroy)
|
||||
onDestroy.bind(comp)();
|
||||
data.decRef();
|
||||
this.onUpdateResources();
|
||||
}
|
||||
r(data as T);
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
//销毁永久资源
|
||||
clearForeverResources(...ress:TB.TbBattleResource[]){
|
||||
this.foreverResources.forEach(id => {
|
||||
if(this.resources[id]){
|
||||
this.resources[id].decRef();
|
||||
}
|
||||
});
|
||||
this.foreverResources = [];
|
||||
this.onUpdateResources();
|
||||
}
|
||||
|
||||
//更新资源(过滤没有用的资源)
|
||||
onUpdateResources(){
|
||||
for (const key in this.resources) {
|
||||
if (Object.prototype.hasOwnProperty.call(this.resources, key)) {
|
||||
const data = this.resources[key];
|
||||
if(!data.isValid) this.resources[key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取资源
|
||||
getData<T extends Asset>(resId:number):T{
|
||||
|
||||
let res = this.resources[resId]
|
||||
if(!res) console.info(`[JLoaderBattle] 未加载资源${resId}`);
|
||||
|
||||
return res as T;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const app = {
|
||||
|
Reference in New Issue
Block a user