mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 10:16:14 +00:00
提交
This commit is contained in:
@@ -690,6 +690,39 @@ export class TOnHookLevel {
|
||||
}
|
||||
|
||||
|
||||
export namespace TB {
|
||||
export class TbBattleResource {
|
||||
|
||||
constructor(_json_: any) {
|
||||
if (_json_.id === undefined) { throw new Error() }
|
||||
this.id = _json_.id
|
||||
if (_json_.path === undefined) { throw new Error() }
|
||||
this.path = _json_.path
|
||||
if (_json_.type === undefined) { throw new Error() }
|
||||
this.type = _json_.type
|
||||
}
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
readonly id: number
|
||||
/**
|
||||
* 资源路径
|
||||
*/
|
||||
readonly path: string
|
||||
/**
|
||||
* 资源类型(0.Spine)
|
||||
*/
|
||||
readonly type: number
|
||||
|
||||
resolve(tables:Tables)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export class TbGGlobal{
|
||||
@@ -1204,6 +1237,38 @@ export class TbGOnHookMap1{
|
||||
|
||||
|
||||
|
||||
export class TbBattleResource{
|
||||
private _dataMap: Map<number, TB.TbBattleResource>
|
||||
private _dataList: TB.TbBattleResource[]
|
||||
constructor(_json_: any) {
|
||||
this._dataMap = new Map<number, TB.TbBattleResource>()
|
||||
this._dataList = []
|
||||
for(var _json2_ of _json_) {
|
||||
let _v: TB.TbBattleResource
|
||||
_v = new TB.TbBattleResource(_json2_)
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.id, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<number, TB.TbBattleResource> { return this._dataMap; }
|
||||
getDataList(): TB.TbBattleResource[] { return this._dataList; }
|
||||
|
||||
get(key: number): TB.TbBattleResource | undefined { return this._dataMap.get(key); }
|
||||
|
||||
resolve(tables:Tables)
|
||||
{
|
||||
for(let data of this._dataList)
|
||||
{
|
||||
data.resolve(tables)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
type JsonLoader = (file: string) => any
|
||||
|
||||
export class Tables {
|
||||
@@ -1239,6 +1304,8 @@ export class Tables {
|
||||
get TbGOnHookMaps(): TbGOnHookMaps { return this._TbGOnHookMaps;}
|
||||
private _TbGOnHookMap1: TbGOnHookMap1
|
||||
get TbGOnHookMap1(): TbGOnHookMap1 { return this._TbGOnHookMap1;}
|
||||
private _TbBattleResource: TbBattleResource
|
||||
get TbBattleResource(): TbBattleResource { return this._TbBattleResource;}
|
||||
|
||||
constructor(loader: JsonLoader) {
|
||||
this._TbGGlobal = new TbGGlobal(loader('tbgglobal'))
|
||||
@@ -1257,6 +1324,7 @@ export class Tables {
|
||||
this._TbGRoleBaseAttribute = new TbGRoleBaseAttribute(loader('tbgrolebaseattribute'))
|
||||
this._TbGOnHookMaps = new TbGOnHookMaps(loader('tbgonhookmaps'))
|
||||
this._TbGOnHookMap1 = new TbGOnHookMap1(loader('tbgonhookmap1'))
|
||||
this._TbBattleResource = new TbBattleResource(loader('tbbattleresource'))
|
||||
|
||||
this._TbGGlobal.resolve(this)
|
||||
this._TbGRole.resolve(this)
|
||||
@@ -1274,5 +1342,6 @@ export class Tables {
|
||||
this._TbGRoleBaseAttribute.resolve(this)
|
||||
this._TbGOnHookMaps.resolve(this)
|
||||
this._TbGOnHookMap1.resolve(this)
|
||||
this._TbBattleResource.resolve(this)
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
[]
|
@@ -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