From 8aa59dce287b07f87f8508f4751023f06b90748d Mon Sep 17 00:00:00 2001 From: dgflash Date: Mon, 7 Jul 2025 10:07:47 +0800 Subject: [PATCH 01/16] =?UTF-8?q?GameManager=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=B8=B8=E6=88=8F=E5=85=83=E7=B4=A0=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/game/GameManager.ts | 47 ++++++++++++++++++++++++++- assets/core/gui/layer/LayerManager.ts | 1 - 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/assets/core/game/GameManager.ts b/assets/core/game/GameManager.ts index 48b351d..2f5d64c 100644 --- a/assets/core/game/GameManager.ts +++ b/assets/core/game/GameManager.ts @@ -5,16 +5,61 @@ * @LastEditTime: 2022-09-02 12:09:55 */ import { Node, director } from 'cc'; +import { ViewUtil } from '../utils/ViewUtil'; +import { resLoader } from '../common/loader/ResLoader'; +import { GameComponent } from '../../module/common/GameComponent'; + +/** 游戏元素打开参数 */ +export interface ElementParams { + /** 远程包名 */ + bundle?: string; + /** 节点排序索引 */ + siblingIndex?: number; +} /** 游戏世界管理 */ export class GameManager { - /** 界面根节点 */ + /** 自定义游戏世界根节点 */ root!: Node; constructor(root: Node) { this.root = root; } + /** + * 自定义游戏元素显示 + * @param parent 元素父节点 + * @param prefabPath 元素预制 + * @param params 可选参数据 + */ + open(parent: Node | GameComponent, prefabPath: string, params?: ElementParams): Promise { + return new Promise(async (resolve, reject) => { + let bundleName: string = null! + if (params && params.bundle) { + bundleName = params.bundle; + } + else { + bundleName = resLoader.defaultBundleName; + } + let node: Node = null!; + // 自动内存管理 + if (parent instanceof GameComponent) { + node = await parent.createPrefabNodeAsync(prefabPath, bundleName); + node.parent = parent.node; + } + // 手动内存管理 + else { + node = await ViewUtil.createPrefabNodeAsync(prefabPath, bundleName); + node.parent = parent; + } + + // 自定义节点排序索引 + if (params && params.siblingIndex) node.setSiblingIndex(params.siblingIndex); + + resolve(node); + }); + } + /** 设置游戏动画速度 */ setTimeScale(scale: number) { //@ts-ignore diff --git a/assets/core/gui/layer/LayerManager.ts b/assets/core/gui/layer/LayerManager.ts index b4e6e5f..4dc08a3 100644 --- a/assets/core/gui/layer/LayerManager.ts +++ b/assets/core/gui/layer/LayerManager.ts @@ -170,7 +170,6 @@ export class LayerManager { * oops.gui.toast("提示内容"); */ toast(content: string, useI18n: boolean = false) { - this.notify.toast(content, useI18n) } -- Gitee From ff14392e813fac198f553ce01aec563a4745650b Mon Sep 17 00:00:00 2001 From: dgflash Date: Sun, 20 Jul 2025 17:38:29 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E5=BA=9F=E5=BC=83=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E7=9A=84=E8=80=81=E7=89=88=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=8C=E5=87=8F=E5=B0=8F=E5=8C=85=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/Oops.ts | 6 - assets/libs/network.meta | 12 - assets/libs/network/.network.md | 3 - assets/libs/network/HttpRequest.ts | 317 -- assets/libs/network/HttpRequest.ts.meta | 9 - assets/libs/network/NetInterface.ts | 92 - assets/libs/network/NetInterface.ts.meta | 11 - assets/libs/network/NetManager.ts | 148 - assets/libs/network/NetManager.ts.meta | 11 - assets/libs/network/NetNode.ts | 491 --- assets/libs/network/NetNode.ts.meta | 11 - assets/libs/network/NetProtocolPako.ts | 69 - assets/libs/network/NetProtocolPako.ts.meta | 9 - assets/libs/network/WebSock.ts | 84 - assets/libs/network/WebSock.ts.meta | 11 - assets/libs/network/protocol.meta | 12 - assets/libs/network/protocol/pako.min.js | 3424 ----------------- assets/libs/network/protocol/pako.min.js.meta | 17 - 18 files changed, 4737 deletions(-) delete mode 100644 assets/libs/network.meta delete mode 100644 assets/libs/network/.network.md delete mode 100644 assets/libs/network/HttpRequest.ts delete mode 100644 assets/libs/network/HttpRequest.ts.meta delete mode 100644 assets/libs/network/NetInterface.ts delete mode 100644 assets/libs/network/NetInterface.ts.meta delete mode 100644 assets/libs/network/NetManager.ts delete mode 100644 assets/libs/network/NetManager.ts.meta delete mode 100644 assets/libs/network/NetNode.ts delete mode 100644 assets/libs/network/NetNode.ts.meta delete mode 100644 assets/libs/network/NetProtocolPako.ts delete mode 100644 assets/libs/network/NetProtocolPako.ts.meta delete mode 100644 assets/libs/network/WebSock.ts delete mode 100644 assets/libs/network/WebSock.ts.meta delete mode 100644 assets/libs/network/protocol.meta delete mode 100644 assets/libs/network/protocol/pako.min.js delete mode 100644 assets/libs/network/protocol/pako.min.js.meta diff --git a/assets/core/Oops.ts b/assets/core/Oops.ts index cc53a34..1e9dda9 100644 --- a/assets/core/Oops.ts +++ b/assets/core/Oops.ts @@ -10,8 +10,6 @@ import { ecs } from "../libs/ecs/ECS"; import { ECSRootSystem } from "../libs/ecs/ECSSystem"; import { LanguageManager } from "../libs/gui/language/Language"; import { VM } from "../libs/model-view/ViewModel"; -import { HttpRequest } from "../libs/network/HttpRequest"; -import { NetManager } from "../libs/network/NetManager"; import { Config } from "../module/config/Config"; import { AudioManager } from "./common/audio/AudioManager"; import { MessageManager } from "./common/event/MessageManager"; @@ -55,10 +53,6 @@ export class oops { /** 多语言模块 */ static language: LanguageManager = new LanguageManager(); - /** HTTP */ - static http: HttpRequest = new HttpRequest(); // 使用流程文档可参考、简化与服务器对接、使用新版API体验,可进入下面地址获取新版本,替换network目录中的内容(https://store.cocos.com/app/detail/5877) - /** WebSocket */ - static tcp: NetManager = new NetManager(); // 使用流程文档可参考、简化与服务器对接、使用新版API体验,可进入下面地址获取新版本,替换network目录中的内容(https://store.cocos.com/app/detail/5877) /** ECS */ static ecs: ECSRootSystem = new ecs.RootSystem(); /** MVVM */ diff --git a/assets/libs/network.meta b/assets/libs/network.meta deleted file mode 100644 index 56f3c5e..0000000 --- a/assets/libs/network.meta +++ /dev/null @@ -1,12 +0,0 @@ -{ - "ver": "1.2.0", - "importer": "directory", - "imported": true, - "uuid": "2b3f701c-188a-4390-94a5-b5d3781f54f9", - "files": [], - "subMetas": {}, - "userData": { - "compressionType": {}, - "isRemoteBundle": {} - } -} diff --git a/assets/libs/network/.network.md b/assets/libs/network/.network.md deleted file mode 100644 index 8ff44c7..0000000 --- a/assets/libs/network/.network.md +++ /dev/null @@ -1,3 +0,0 @@ -游戏网络库 -1. Http -2. WebSocket \ No newline at end of file diff --git a/assets/libs/network/HttpRequest.ts b/assets/libs/network/HttpRequest.ts deleted file mode 100644 index 48bff56..0000000 --- a/assets/libs/network/HttpRequest.ts +++ /dev/null @@ -1,317 +0,0 @@ -/* - * @Author: dgflash - * @Date: 2022-09-01 18:00:28 - * @LastEditors: dgflash - * @LastEditTime: 2022-09-09 18:10:50 - */ -import { error, warn } from "cc"; - -/** - * 使用流程文档可参考、简化与服务器对接、使用新版API体验,可进入下面地址获取新版本,替换network目录中的内容 - * https://store.cocos.com/app/detail/5877 - */ - -/** 当前请求地址集合 */ -var urls: any = {}; -/** 请求参数 */ -var reqparams: any = {}; - -type HttpCallback = (ret: HttpReturn) => void; - -/** 请求事件 */ -export enum HttpEvent { - /** 断网 */ - NO_NETWORK = "http_request_no_network", - /** 未知错误 */ - UNKNOWN_ERROR = "http_request_unknown_error", - /** 请求超时 */ - TIMEOUT = "http_request_timout" -} - -/** - * HTTP请求返回值 - */ -export class HttpReturn { - /** 是否请求成功 */ - isSucc: boolean = false; - /** 请求返回数据 */ - res?: any; - /** 请求错误数据 */ - err?: any; -} - -/** HTTP请求 */ -export class HttpRequest { - /** 服务器地址 */ - server: string = "http://127.0.0.1/"; - /** 请求超时时间 */ - timeout: number = 10000; - /** 自定义请求头信息 */ - private header: Map = new Map(); - - /** - * 添加自定义请求头信息 - * @param name 信息名 - * @param value 信息值 - */ - addHeader(name: string, value: string) { - this.header.set(name, value); - } - - /** - * HTTP GET请求 - * @param name 协议名 - * @param onComplete 请求完整回调方法 - * @param params 查询参数 - * @example - var param = '{"uid":12345}' - var complete = (ret: HttpReturn) => { - console.log(ret.res); - } - oops.http.getWithParams(name, complete, param); - */ - get(name: string, onComplete: HttpCallback, params: any = null) { - this.sendRequest(name, params, false, onComplete) - } - - /** - * HTTP GET请求 - * @param name 协议名 - * @param params 查询参数 - * @example - var txt = await oops.http.getAsync(name); - if (txt.isSucc) { - console.log(txt.res); - } - */ - getAsync(name: string, params: any = null): Promise { - return new Promise((resolve, reject) => { - this.sendRequest(name, params, false, (ret: HttpReturn) => { - resolve(ret); - }) - }); - } - - /** - * HTTP GET请求非文本格式数据 - * @param name 协议名 - * @param onComplete 请求完整回调方法 - * @param params 查询参数 - */ - getByArraybuffer(name: string, onComplete: HttpCallback, params: any = null) { - this.sendRequest(name, params, false, onComplete, 'arraybuffer', false); - } - - /** - * HTTP GET请求非文本格式数据 - * @param name 协议名 - * @param params 查询参数 - * @returns Promise - */ - getAsyncByArraybuffer(name: string, params: any = null): Promise { - return new Promise((resolve, reject) => { - this.sendRequest(name, params, false, (ret: HttpReturn) => { - resolve(ret); - }, 'arraybuffer', false); - }); - } - - /** - * HTTP POST请求 - * @param name 协议名 - * @param params 查询参数 - * @param onComplete 请求完整回调方法 - * @example - var param = '{"LoginCode":"donggang_dev","Password":"e10adc3949ba59abbe56e057f20f883e"}' - var complete = (ret: HttpReturn) => { - console.log(ret.res); - } - oops.http.post(name, complete, param); - */ - post(name: string, onComplete: HttpCallback, params: any = null) { - this.sendRequest(name, params, true, onComplete); - } - - /** - * HTTP POST请求 - * @param name 协议名 - * @param params 查询参数 - */ - postAsync(name: string, params: any = null): Promise { - return new Promise((resolve, reject) => { - this.sendRequest(name, params, true, (ret: HttpReturn) => { - resolve(ret); - }); - }); - } - - /** - * 取消请求中的请求 - * @param name 协议名 - */ - abort(name: string) { - var xhr = urls[this.server + name]; - if (xhr) { - xhr.abort(); - } - } - - /** - * 获得字符串形式的参数 - * @param params 参数对象 - * @returns 参数字符串 - */ - private getParamString(params: any) { - var result = ""; - for (var name in params) { - let data = params[name]; - if (data instanceof Object) { - for (var key in data) - result += `${key}=${data[key]}&`; - } - else { - result += `${name}=${data}&`; - } - } - return result.substring(0, result.length - 1); - } - - /** - * Http请求 - * @param name(string) 请求地址 - * @param params(JSON) 请求参数 - * @param isPost(boolen) 是否为POST方式 - * @param callback(function) 请求成功回调 - * @param responseType(string) 响应类型 - * @param isOpenTimeout(boolean) 是否触发请求超时错误 - */ - private sendRequest(name: string, - params: any, - isPost: boolean, - onComplete: HttpCallback, - responseType?: string, - isOpenTimeout: boolean = true) { - if (name == null || name == '') { - error("请求地址不能为空"); - return; - } - - var url: string, newUrl: string, paramsStr: string = ""; - if (name.toLocaleLowerCase().indexOf("http") == 0) { - url = name; - } - else { - url = this.server + name; - } - - if (params) { - paramsStr = this.getParamString(params); - if (url.indexOf("?") > -1) - newUrl = url + "&" + paramsStr; - else - newUrl = url + "?" + paramsStr; - } - else { - newUrl = url; - } - - if (urls[newUrl] != null && reqparams[newUrl] == paramsStr) { - warn(`地址【${url}】已正在请求中,不能重复请求`); - return; - } - - var xhr = new XMLHttpRequest(); - - // 防重复请求功能 - urls[newUrl] = xhr; - reqparams[newUrl] = paramsStr; - - if (isPost) { - xhr.open("POST", url); - } - else { - xhr.open("GET", newUrl); - } - - // 添加自定义请求头信息 - for (const [key, value] of this.header) { - xhr.setRequestHeader(key, value); - } - // xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); - // xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8"); - - var data: any = {}; - data.url = url; - data.params = params; - - // 请求超时 - if (isOpenTimeout) { - xhr.timeout = this.timeout; - xhr.ontimeout = () => { - this.deleteCache(newUrl); - - ret.isSucc = false; - ret.err = HttpEvent.TIMEOUT; // 超时 - onComplete(data); - } - } - - // 响应结果 - var ret: HttpReturn = new HttpReturn(); - - xhr.onloadend = () => { - if (xhr.status == 500) { - this.deleteCache(newUrl); - - ret.isSucc = false; - ret.err = HttpEvent.NO_NETWORK; // 断网 - onComplete(ret); - } - } - - xhr.onerror = () => { - this.deleteCache(newUrl); - - ret.isSucc = false; - if (xhr.readyState == 0 || xhr.readyState == 1 || xhr.status == 0) { - ret.err = HttpEvent.NO_NETWORK; // 断网 - } - else { - ret.err = HttpEvent.UNKNOWN_ERROR; // 未知错误 - } - - onComplete(ret); - }; - - xhr.onreadystatechange = () => { - if (xhr.readyState != 4) return; - - this.deleteCache(newUrl); - - if (xhr.status == 200 && onComplete) { - ret.isSucc = true; - if (responseType == 'arraybuffer') { - xhr.responseType = responseType; // 加载非文本格式 - ret.res = xhr.response; - } - else { - ret.res = JSON.parse(xhr.response); - } - onComplete(ret); - } - }; - - // 发送请求 - if (params == null || params == "") { - xhr.send(); - } - else { - xhr.send(paramsStr); - } - } - - private deleteCache(url: string) { - delete urls[url]; - delete reqparams[url]; - } -} \ No newline at end of file diff --git a/assets/libs/network/HttpRequest.ts.meta b/assets/libs/network/HttpRequest.ts.meta deleted file mode 100644 index dc4c2e3..0000000 --- a/assets/libs/network/HttpRequest.ts.meta +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "806e5b7c-51eb-45cb-8b29-9fcf5d9ee6a7", - "files": [], - "subMetas": {}, - "userData": {} -} diff --git a/assets/libs/network/NetInterface.ts b/assets/libs/network/NetInterface.ts deleted file mode 100644 index 90dab00..0000000 --- a/assets/libs/network/NetInterface.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* - * @Author: dgflash - * @Date: 2022-09-01 18:00:28 - * @LastEditors: dgflash - * @LastEditTime: 2022-09-09 18:31:18 - */ - -/* - * 网络相关接口定义 - */ -export type NetData = (string | ArrayBufferLike | Blob | ArrayBufferView); -export type NetCallFunc = (data: any) => void; - -/** 请求协议 */ -export interface IRequestProtocol { - /** 协议命令编号 */ - cmd: string, - /** 回调方法名 */ - callback?: string, - /** 是否压缩 */ - isCompress: boolean, - /** 渠道编号 */ - channelid: number, - /** 消息内容 */ - data?: any; -} - -/** 响应协议 */ -export interface IResponseProtocol { - /** 响应协议状态码 */ - code: number, - /** 数据是否压缩 */ - isCompress: boolean, - /** 协议数据 */ - data?: any, - /** 协议回调方法名 */ - callback?: string -} - -/** 回调对象 */ -export interface CallbackObject { - target: any, // 回调对象,不为null时调用target.callback(xxx) - callback: NetCallFunc, // 回调函数 -} - -/** 请求对象 */ -export interface RequestObject { - buffer: NetData, // 请求的Buffer - rspCmd: string, // 等待响应指令 - rspObject: CallbackObject | null, // 等待响应的回调对象 -} - -/** 协议辅助接口 */ -export interface IProtocolHelper { - /** 返回包头长度 */ - getHeadlen(): number; - /** 返回一个心跳包 */ - getHearbeat(): NetData; - /** 返回整个包的长度 */ - getPackageLen(msg: NetData): number; - /** 检查包数据是否合法(避免客户端报错崩溃) */ - checkResponsePackage(msg: IResponseProtocol): boolean; - /** 处理请求包数据 */ - handlerRequestPackage(reqProtocol: IRequestProtocol): string; - /** 处理响应包数据 */ - handlerResponsePackage(respProtocol: IResponseProtocol): boolean; - /** 返回包的id或协议类型 */ - getPackageId(msg: IResponseProtocol): string; -} - -export type SocketFunc = (event: any) => void; -export type MessageFunc = (msg: NetData) => void; - -/** Socket接口 */ -export interface ISocket { - onConnected: SocketFunc | null; // 连接回调 - onMessage: MessageFunc | null; // 消息回调 - onError: SocketFunc | null; // 错误回调 - onClosed: SocketFunc | null; // 关闭回调 - - connect(options: any): any; // 连接接口 - send(buffer: NetData): number; // 数据发送接口 - close(code?: number, reason?: string): void; // 关闭接口 -} - -/** 网络提示接口 */ -export interface INetworkTips { - connectTips(isShow: boolean): void; - reconnectTips(isShow: boolean): void; - requestTips(isShow: boolean): void; - responseErrorCode(code: number): void; -} \ No newline at end of file diff --git a/assets/libs/network/NetInterface.ts.meta b/assets/libs/network/NetInterface.ts.meta deleted file mode 100644 index 42f5745..0000000 --- a/assets/libs/network/NetInterface.ts.meta +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "d9f8bf82-57af-45c8-ac27-51d0a33ad69d", - "files": [], - "subMetas": {}, - "userData": { - "simulateGlobals": [] - } -} diff --git a/assets/libs/network/NetManager.ts b/assets/libs/network/NetManager.ts deleted file mode 100644 index 753ce04..0000000 --- a/assets/libs/network/NetManager.ts +++ /dev/null @@ -1,148 +0,0 @@ -/* - * @Author: dgflash - * @Date: 2022-09-01 18:00:28 - * @LastEditors: dgflash - * @LastEditTime: 2022-09-09 18:10:50 - */ -import { CallbackObject, IRequestProtocol, NetData } from "./NetInterface"; -import { NetConnectOptions, NetNode } from "./NetNode"; - -/** - * 使用流程文档可参考、简化与服务器对接、使用新版API体验,可进入下面地址获取新版本,替换network目录中的内容 - * https://store.cocos.com/app/detail/5877 - */ - -/* - * 网络节点管理类 - */ -export class NetManager { - private static _instance: NetManager; - protected _channels: { [key: number]: NetNode } = {}; - - /** 网络管理单例对象 */ - static getInstance(): NetManager { - if (!this._instance) { - this._instance = new NetManager(); - } - return this._instance; - } - - /** - * 添加网络节点 - * @param node 网络节点 - * @param channelId 通道编号 - * @example - // 游戏服务器心跳协议 - class GameProtocol extends NetProtocolPako { - // 自定义心跳协议 - getHearbeat(): NetData { - return '{"action":"LoginAction","method":"heart","data":"null","callback":"LoginAction_heart"}'; - } - } - - var net = new NetNodeGame(); - var ws = new WebSock(); // WebSocket 网络连接对象 - var gp = new GameProtocol(); // 网络通讯协议对象 - var gt = new NetGameTips() // 网络提示对象 - net.init(ws, gp, gt); - NetManager.getInstance().setNetNode(net, NetChannelType.Game); - */ - setNetNode(node: NetNode, channelId: number = 0) { - this._channels[channelId] = node; - } - - /** 移除Node */ - removeNetNode(channelId: number) { - delete this._channels[channelId]; - } - - /** - * 网络节点连接服务器 - * @param options 连接参数 - * @param channelId 通道编号 - * @example - var options = { - url: 'ws://127.0.0.1:3000', - autoReconnect: 0 // -1 永久重连,0不自动重连,其他正整数为自动重试次数 - } - NetManager.getInstance().connect(options, NetChannelType.Game); - */ - connect(options: NetConnectOptions, channelId: number = 0): boolean { - if (this._channels[channelId]) { - return this._channels[channelId].connect(options); - } - return false; - } - - /** 节点连接发送数据*/ - send(buf: NetData, force: boolean = false, channelId: number = 0): number { - let node = this._channels[channelId]; - if (node) { - return node!.send(buf, force); - } - return -1; - } - - /** - * 发起请求,并在在结果返回时调用指定好的回调函数 - * @param reqProtocol 请求协议 - * @param rspObject 回调对象 - * @param showTips 是否触发请求提示 - * @param force 是否强制发送 - * @param channelId 通道编号 - * @example - let protocol: IRequestProtocol = { - action: action, - method: method, - data: JSON.stringify(data), - isCompress: this.isCompress, - channelid: netConfig.channelid - } - return this.request(protocol, rspObject, showTips, force); - */ - request(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false, channelId: number = 0) { - let node = this._channels[channelId]; - if (node) { - node.request(reqProtocol, rspObject, showTips, force); - } - } - - /** - * 同request功能一致,但在request之前会先判断队列中是否已有rspCmd,如有重复的则直接返回 - * @param reqProtocol 请求协议 - * @param rspObject 回调对象 - * @param showTips 是否触发请求提示 - * @param force 是否强制发送 - * @param channelId 通道编号 - * @example - let protocol: IRequestProtocol = { - action: action, - method: method, - data: JSON.stringify(data), - isCompress: this.isCompress, - channelid: netConfig.channelid - } - return this.request(protocol, rspObject, showTips, force); - */ - requestUnique(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false, channelId: number = 0): boolean { - let node = this._channels[channelId]; - if (node) { - return node.requestUnique(reqProtocol, rspObject, showTips, force); - } - return false; - } - - /** - * 节点网络断开 - * @param code 关闭码 - * @param reason 关闭原因 - * @param channelId 通道编号 - * @example - * NetManager.getInstance().close(undefined, undefined, NetChannelType.Game); - */ - close(code?: number, reason?: string, channelId: number = 0) { - if (this._channels[channelId]) { - return this._channels[channelId].closeSocket(code, reason); - } - } -} \ No newline at end of file diff --git a/assets/libs/network/NetManager.ts.meta b/assets/libs/network/NetManager.ts.meta deleted file mode 100644 index aa09a64..0000000 --- a/assets/libs/network/NetManager.ts.meta +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "d8cd57a5-e860-464d-84d6-f8df1bf04b89", - "files": [], - "subMetas": {}, - "userData": { - "simulateGlobals": [] - } -} diff --git a/assets/libs/network/NetNode.ts b/assets/libs/network/NetNode.ts deleted file mode 100644 index c17259a..0000000 --- a/assets/libs/network/NetNode.ts +++ /dev/null @@ -1,491 +0,0 @@ -import { error, warn } from "cc"; -import { Logger } from "../../core/common/log/Logger"; -import { CallbackObject, INetworkTips, IProtocolHelper, IRequestProtocol, ISocket, NetCallFunc, NetData, RequestObject } from "./NetInterface"; - -/* -* CocosCreator网络节点基类,以及网络相关接口定义 -* 1. 网络连接、断开、请求发送、数据接收等基础功能 -* 2. 心跳机制 -* 3. 断线重连 + 请求重发 -* 4. 调用网络屏蔽层 -*/ - -type ExecuterFunc = (callback: CallbackObject, buffer: NetData) => void; -type CheckFunc = (checkedFunc: VoidFunc) => void; -type VoidFunc = () => void; -type BoolFunc = () => boolean; - -var NetNodeStateStrs = ["已关闭", "连接中", "验证中", "可传输数据"]; - -/** 网络提示类型枚举 */ -export enum NetTipsType { - Connecting, - ReConnecting, - Requesting, -} - -/** 网络状态枚举 */ -export enum NetNodeState { - Closed, // 已关闭 - Connecting, // 连接中 - Checking, // 验证中 - Working, // 可传输数据 -} - -/** 网络连接参数 */ -export interface NetConnectOptions { - host?: string, // 地址 - port?: number, // 端口 - url?: string, // url,与地址+端口二选一 - autoReconnect?: number, // -1 永久重连,0不自动重连,其他正整数为自动重试次数 -} - -/** 网络节点 */ -export class NetNode { - protected _connectOptions: NetConnectOptions | null = null; - protected _autoReconnect: number = 0; - protected _isSocketInit: boolean = false; // Socket是否初始化过 - protected _isSocketOpen: boolean = false; // Socket是否连接成功过 - protected _state: NetNodeState = NetNodeState.Closed; // 节点当前状态 - protected _socket: ISocket | null = null; // Socket对象(可能是原生socket、websocket、wx.socket...) - - protected _networkTips: INetworkTips | null = null; // 网络提示ui对象(请求提示、断线重连提示等) - protected _protocolHelper: IProtocolHelper | null = null; // 包解析对象 - protected _connectedCallback: CheckFunc | null = null; // 连接完成回调 - protected _disconnectCallback: BoolFunc | null = null; // 断线回调 - protected _callbackExecuter: ExecuterFunc | null = null; // 回调执行 - - protected _keepAliveTimer: any = null; // 心跳定时器 - protected _receiveMsgTimer: any = null; // 接收数据定时器 - protected _reconnectTimer: any = null; // 重连定时器 - protected _heartTime: number = 10000; // 心跳间隔 - protected _receiveTime: number = 6000000; // 多久没收到数据断开 - protected _reconnetTimeOut: number = 8000000; // 重连间隔 - protected _requests: RequestObject[] = Array(); // 请求列表 - protected _listener: { [key: string]: CallbackObject[] | null } = {} // 监听者列表 - - /********************** 网络相关处理 *********************/ - init(socket: ISocket, protocol: IProtocolHelper, networkTips: INetworkTips | null = null, execFunc: ExecuterFunc | null = null) { - Logger.instance.logNet(`网络初始化`); - this._socket = socket; - this._protocolHelper = protocol; - this._networkTips = networkTips; - this._callbackExecuter = execFunc ? execFunc : (callback: CallbackObject, buffer: NetData) => { - callback.callback.call(callback.target, buffer); - } - } - - /** - * 请求连接服务器 - * @param options 连接参数 - */ - connect(options: NetConnectOptions): boolean { - if (this._socket && this._state == NetNodeState.Closed) { - if (!this._isSocketInit) { - this.initSocket(); - } - this._state = NetNodeState.Connecting; - if (!this._socket.connect(options)) { - this.updateNetTips(NetTipsType.Connecting, false); - return false; - } - if (this._connectOptions == null && typeof options.autoReconnect == "number") { - this._autoReconnect = options.autoReconnect; - } - this._connectOptions = options; - this.updateNetTips(NetTipsType.Connecting, true); - return true; - } - return false; - } - - protected initSocket() { - if (this._socket) { - this._socket.onConnected = (event) => { this.onConnected(event) }; - this._socket.onMessage = (msg) => { this.onMessage(msg) }; - this._socket.onError = (event) => { this.onError(event) }; - this._socket.onClosed = (event) => { this.onClosed(event) }; - this._isSocketInit = true; - } - } - - protected updateNetTips(tipsType: NetTipsType, isShow: boolean) { - if (this._networkTips) { - if (tipsType == NetTipsType.Requesting) { - this._networkTips.requestTips(isShow); - } - else if (tipsType == NetTipsType.Connecting) { - this._networkTips.connectTips(isShow); - } - else if (tipsType == NetTipsType.ReConnecting) { - this._networkTips.reconnectTips(isShow); - } - } - } - - /** 网络连接成功 */ - protected onConnected(event: any) { - Logger.instance.logNet("网络已连接") - this._isSocketOpen = true; - // 如果设置了鉴权回调,在连接完成后进入鉴权阶段,等待鉴权结束 - if (this._connectedCallback !== null) { - this._state = NetNodeState.Checking; - this._connectedCallback(() => { this.onChecked() }); - } - else { - this.onChecked(); - } - Logger.instance.logNet(`网络已连接当前状态为【${NetNodeStateStrs[this._state]}】`); - } - - /** 连接验证成功,进入工作状态 */ - protected onChecked() { - Logger.instance.logNet("连接验证成功,进入工作状态"); - this._state = NetNodeState.Working; - // 关闭连接或重连中的状态显示 - this.updateNetTips(NetTipsType.Connecting, false); - this.updateNetTips(NetTipsType.ReConnecting, false); - - // 重发待发送信息 - var requests = this._requests.concat(); - if (requests.length > 0) { - Logger.instance.logNet(`请求【${this._requests.length}】个待发送的信息`); - - for (var i = 0; i < requests.length;) { - let req = requests[i]; - this._socket!.send(req.buffer); - if (req.rspObject == null || req.rspCmd != "") { - requests.splice(i, 1); - } - else { - ++i; - } - } - // 如果还有等待返回的请求,启动网络请求层 - this.updateNetTips(NetTipsType.Requesting, this._requests.length > 0); - } - } - - /** 接收到一个完整的消息包 */ - protected onMessage(msg: any): void { - // Logger.logNet(`接受消息状态为【${NetNodeStateStrs[this._state]}】`); - - var json = JSON.parse(msg); - - // 进行头部的校验(实际包长与头部长度是否匹配) - if (!this._protocolHelper!.checkResponsePackage(json)) { - error(`校验接受消息数据异常`); - return; - } - - // 处理相应包数据 - if (!this._protocolHelper!.handlerResponsePackage(json)) { - if (this._networkTips) - this._networkTips.responseErrorCode(json.code); - } - - // 接受到数据,重新定时收数据计时器 - this.resetReceiveMsgTimer(); - // 重置心跳包发送器 - this.resetHearbeatTimer(); - // 触发消息执行 - let rspCmd = this._protocolHelper!.getPackageId(json); - - Logger.instance.logNet(`接受到命令【${rspCmd}】的消息`); - // 优先触发request队列 - if (this._requests.length > 0) { - for (let reqIdx in this._requests) { - let req = this._requests[reqIdx]; - if (req.rspCmd == rspCmd && req.rspObject) { - Logger.instance.logNet(`触发请求命令【${rspCmd}】的回调`); - this._callbackExecuter!(req.rspObject, json.data); - this._requests.splice(parseInt(reqIdx), 1); - break; - } - } - - if (this._requests.length == 0) { - this.updateNetTips(NetTipsType.Requesting, false); - } - else { - Logger.instance.logNet(`请求队列中还有【${this._requests.length}】个请求在等待`); - } - } - - let listeners = this._listener[rspCmd]; - if (null != listeners) { - for (const rsp of listeners) { - Logger.instance.logNet(`触发监听命令【${rspCmd}】的回调`); - this._callbackExecuter!(rsp, json.data); - } - } - } - - protected onError(event: any) { - error(event); - } - - protected onClosed(event: any) { - this.clearTimer(); - - // 执行断线回调,返回false表示不进行重连 - if (this._disconnectCallback && !this._disconnectCallback()) { - Logger.instance.logNet(`断开连接`); - return; - } - - // 自动重连 - if (this.isAutoReconnect()) { - this.updateNetTips(NetTipsType.ReConnecting, true); - this._reconnectTimer = setTimeout(() => { - this._socket!.close(); - this._state = NetNodeState.Closed; - this.connect(this._connectOptions!); - if (this._autoReconnect > 0) { - this._autoReconnect -= 1; - } - }, this._reconnetTimeOut); - } - else { - this._state = NetNodeState.Closed; - } - } - - /** - * 断开网络 - * @param code 关闭码 - * @param reason 关闭原因 - */ - close(code?: number, reason?: string) { - this.clearTimer(); - this._listener = {}; - this._requests.length = 0; - if (this._networkTips) { - this._networkTips.connectTips(false); - this._networkTips.reconnectTips(false); - this._networkTips.requestTips(false); - } - if (this._socket) { - this._socket.close(code, reason); - } - else { - this._state = NetNodeState.Closed; - } - } - - /** - * 只是关闭Socket套接字(仍然重用缓存与当前状态) - * @param code 关闭码 - * @param reason 关闭原因 - */ - closeSocket(code?: number, reason?: string) { - if (this._socket) { - this._socket.close(code, reason); - } - } - - /** - * 发起请求,如果当前处于重连中,进入缓存列表等待重连完成后发送 - * @param buf 网络数据 - * @param force 是否强制发送 - */ - send(buf: NetData, force: boolean = false): number { - if (this._state == NetNodeState.Working || force) { - return this._socket!.send(buf); - } - else if (this._state == NetNodeState.Checking || - this._state == NetNodeState.Connecting) { - this._requests.push({ - buffer: buf, - rspCmd: "", - rspObject: null - }); - Logger.instance.logNet(`当前状态为【${NetNodeStateStrs[this._state]}】,繁忙并缓冲发送数据`); - return 0; - } - else { - error(`当前状态为【${NetNodeStateStrs[this._state]}】,请求错误`); - return -1; - } - } - - /** - * 发起请求,并进入缓存列表 - * @param reqProtocol 请求协议 - * @param rspObject 回调对象 - * @param showTips 是否触发请求提示 - * @param force 是否强制发送 - */ - request(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false) { - var rspCmd = this._protocolHelper!.handlerRequestPackage(reqProtocol); - this.base_request(reqProtocol, rspCmd, rspObject, showTips, force); - } - - /** - * 唯一request,确保没有同一响应的请求(避免一个请求重复发送,netTips界面的屏蔽也是一个好的方法) - * @param reqProtocol 请求协议 - * @param rspObject 回调对象 - * @param showTips 是否触发请求提示 - * @param force 是否强制发送 - */ - requestUnique(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false): boolean { - var rspCmd = this._protocolHelper!.handlerRequestPackage(reqProtocol); - - for (let i = 0; i < this._requests.length; ++i) { - if (this._requests[i].rspCmd == rspCmd) { - Logger.instance.logNet(`命令【${rspCmd}】重复请求`); - return false; - } - } - - this.base_request(reqProtocol, rspCmd, rspObject, showTips, force); - return true; - } - - private base_request(reqProtocol: IRequestProtocol, rspCmd: string, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false) { - var buf: NetData = JSON.stringify(reqProtocol); // 转为二进制流发送 - - if (this._state == NetNodeState.Working || force) { - this._socket!.send(buf); - } - - Logger.instance.logNet(`队列命令为【${rspCmd}】的请求,等待请求数据的回调`); - - // 进入发送缓存列表 - this._requests.push({ - buffer: buf, rspCmd, rspObject - }); - // 启动网络请求层 - if (showTips) { - this.updateNetTips(NetTipsType.Requesting, true); - } - } - - /********************** 回调相关处理 *********************/ - /** - * 设置一个唯一的服务器推送监听 - * @param cmd 命令字串 - * @param callback 回调方法 - * @param target 目标对象 - */ - setResponeHandler(cmd: string, callback: NetCallFunc, target?: any): boolean { - if (callback == null) { - error(`命令为【${cmd}】设置响应处理程序错误`); - return false; - } - this._listener[cmd] = [{ target, callback }]; - return true; - } - - /** - * 可添加多个同类返回消息的监听 - * @param cmd 命令字串 - * @param callback 回调方法 - * @param target 目标对象 - * @returns - */ - addResponeHandler(cmd: string, callback: NetCallFunc, target?: any): boolean { - if (callback == null) { - error(`命令为【${cmd}】添加响应处理程序错误`); - return false; - } - let rspObject = { target, callback }; - if (null == this._listener[cmd]) { - this._listener[cmd] = [rspObject]; - } - else { - let index = this.getNetListenersIndex(cmd, rspObject); - if (-1 == index) { - this._listener[cmd]!.push(rspObject); - } - } - return true; - } - - /** - * 删除一个监听中指定子回调 - * @param cmd 命令字串 - * @param callback 回调方法 - * @param target 目标对象 - */ - removeResponeHandler(cmd: string, callback: NetCallFunc, target?: any) { - if (null != this._listener[cmd] && callback != null) { - let index = this.getNetListenersIndex(cmd, { target, callback }); - if (-1 != index) { - this._listener[cmd]!.splice(index, 1); - } - } - } - - /** - * 清除所有监听或指定命令的监听 - * @param cmd 命令字串(默认不填为清除所有) - */ - cleanListeners(cmd: string = "") { - if (cmd == "") { - this._listener = {} - } - else { - delete this._listener[cmd]; - } - } - - protected getNetListenersIndex(cmd: string, rspObject: CallbackObject): number { - let index = -1; - for (let i = 0; i < this._listener[cmd]!.length; i++) { - let iterator = this._listener[cmd]![i]; - if (iterator.callback == rspObject.callback - && iterator.target == rspObject.target) { - index = i; - break; - } - } - return index; - } - - /********************** 心跳、超时相关处理 *********************/ - protected resetReceiveMsgTimer() { - if (this._receiveMsgTimer !== null) { - clearTimeout(this._receiveMsgTimer); - } - - this._receiveMsgTimer = setTimeout(() => { - warn("接收消息定时器关闭网络连接"); - this._socket!.close(); - }, this._receiveTime); - } - - protected resetHearbeatTimer() { - if (this._keepAliveTimer !== null) { - clearTimeout(this._keepAliveTimer); - } - - this._keepAliveTimer = setTimeout(() => { - Logger.instance.logNet("网络节点保持活跃发送心跳信息"); - this.send(this._protocolHelper!.getHearbeat()); - }, this._heartTime); - } - - protected clearTimer() { - if (this._receiveMsgTimer !== null) { - clearTimeout(this._receiveMsgTimer); - } - if (this._keepAliveTimer !== null) { - clearTimeout(this._keepAliveTimer); - } - if (this._reconnectTimer !== null) { - clearTimeout(this._reconnectTimer); - } - } - - /** 是否自动重连接 */ - isAutoReconnect() { - return this._autoReconnect != 0; - } - - /** 拒绝重新连接 */ - rejectReconnect() { - this._autoReconnect = 0; - this.clearTimer(); - } -} \ No newline at end of file diff --git a/assets/libs/network/NetNode.ts.meta b/assets/libs/network/NetNode.ts.meta deleted file mode 100644 index 5127f31..0000000 --- a/assets/libs/network/NetNode.ts.meta +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "57f0f07d-d243-4150-9f7c-cb2bbe8f18f1", - "files": [], - "subMetas": {}, - "userData": { - "simulateGlobals": [] - } -} diff --git a/assets/libs/network/NetProtocolPako.ts b/assets/libs/network/NetProtocolPako.ts deleted file mode 100644 index fb0fa9c..0000000 --- a/assets/libs/network/NetProtocolPako.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - * @Author: dgflash - * @Date: 2022-04-21 13:45:51 - * @LastEditors: dgflash - * @LastEditTime: 2022-04-21 13:51:33 - */ -import { IProtocolHelper, IRequestProtocol, IResponseProtocol, NetData } from "./NetInterface"; - -var unzip = function (str: string) { - let charData = str.split('').map(function (x) { - return x.charCodeAt(0); - }); - let binData = new Uint8Array(charData); - //@ts-ignore - let data = pako.inflate(binData, { to: 'string' }); - return data; -} - -var zip = function (str: string) { - //@ts-ignore - let binaryString = pako.gzip(str, { to: 'string' }); - return binaryString; -} - -/** Pako.js 数据压缩协议 */ -export class NetProtocolPako implements IProtocolHelper { - getHeadlen(): number { - return 0; - } - - getHearbeat(): NetData { - return ""; - } - - getPackageLen(msg: NetData): number { - return msg.toString().length; - } - - checkResponsePackage(respProtocol: IResponseProtocol): boolean { - return true; - } - - handlerResponsePackage(respProtocol: IResponseProtocol): boolean { - if (respProtocol.code == 1) { - if (respProtocol.isCompress) { - respProtocol.data = unzip(respProtocol.data); - } - respProtocol.data = JSON.parse(respProtocol.data); - - return true; - } - else { - return false; - } - } - - handlerRequestPackage(reqProtocol: IRequestProtocol): string { - var rspCmd = reqProtocol.cmd; - reqProtocol.callback = rspCmd; - if (reqProtocol.isCompress) { - reqProtocol.data = zip(reqProtocol.data); - } - return rspCmd; - } - - getPackageId(respProtocol: IResponseProtocol): string { - return respProtocol.callback!; - } -} \ No newline at end of file diff --git a/assets/libs/network/NetProtocolPako.ts.meta b/assets/libs/network/NetProtocolPako.ts.meta deleted file mode 100644 index f35e285..0000000 --- a/assets/libs/network/NetProtocolPako.ts.meta +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "88ae0948-8390-4559-bd4e-d44f3f12dc22", - "files": [], - "subMetas": {}, - "userData": {} -} diff --git a/assets/libs/network/WebSock.ts b/assets/libs/network/WebSock.ts deleted file mode 100644 index 32521c1..0000000 --- a/assets/libs/network/WebSock.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* - * @Author: dgflash - * @Date: 2021-07-03 16:13:17 - * @LastEditors: dgflash - * @LastEditTime: 2022-09-09 17:42:19 - */ -import { Logger } from "../../core/common/log/Logger"; -import { ISocket, MessageFunc, NetData } from "./NetInterface"; - -type Connected = (event: any) => void; - -/** - * WebSocket 封装 - * 1. 连接/断开相关接口 - * 2. 网络异常回调 - * 3. 数据发送与接收 - */ -export class WebSock implements ISocket { - private _ws: WebSocket | null = null; // websocket对象 - - /** 网络连接成功事件 */ - onConnected: ((this: WebSocket, ev: Event) => any) | null = null; - /** 接受到网络数据事件 */ - onMessage: MessageFunc | null = null; - /** 网络错误事件 */ - onError: ((this: WebSocket, ev: Event) => any) | null = null; - /** 网络断开事件 */ - onClosed: ((this: WebSocket, ev: CloseEvent) => any) | null = null; - - /** 请求连接 */ - connect(options: any) { - if (this._ws) { - if (this._ws.readyState === WebSocket.CONNECTING) { - Logger.logNet("websocket connecting, wait for a moment...") - return false; - } - } - - let url = null; - if (options.url) { - url = options.url; - } - else { - let ip = options.ip; - let port = options.port; - let protocol = options.protocol; - url = `${protocol}://${ip}:${port}`; - } - - this._ws = new WebSocket(url); - this._ws.binaryType = options.binaryType ? options.binaryType : "arraybuffer"; - this._ws.onmessage = (event) => { - let onMessage: MessageFunc = this.onMessage!; - onMessage(event.data); - }; - this._ws.onopen = this.onConnected; - this._ws.onerror = this.onError; - this._ws.onclose = this.onClosed; - return true; - } - - /** - * 发送数据 - * @param buffer 网络数据 - */ - send(buffer: NetData): number { - if (this._ws && this._ws.readyState == WebSocket.OPEN) { - this._ws.send(buffer); - return 1; - } - return -1; - } - - /** - * 网络断开 - * @param code 关闭码 - * @param reason 关闭原因 - */ - close(code?: number, reason?: string) { - if (this._ws) { - this._ws.close(code, reason); - } - } -} \ No newline at end of file diff --git a/assets/libs/network/WebSock.ts.meta b/assets/libs/network/WebSock.ts.meta deleted file mode 100644 index 711d773..0000000 --- a/assets/libs/network/WebSock.ts.meta +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "70df255b-214f-41eb-a16b-fa8a7c14a269", - "files": [], - "subMetas": {}, - "userData": { - "simulateGlobals": [] - } -} diff --git a/assets/libs/network/protocol.meta b/assets/libs/network/protocol.meta deleted file mode 100644 index 0d5da65..0000000 --- a/assets/libs/network/protocol.meta +++ /dev/null @@ -1,12 +0,0 @@ -{ - "ver": "1.2.0", - "importer": "directory", - "imported": true, - "uuid": "922e2501-4a6b-4f54-852c-28e24c3fc5b8", - "files": [], - "subMetas": {}, - "userData": { - "compressionType": {}, - "isRemoteBundle": {} - } -} diff --git a/assets/libs/network/protocol/pako.min.js b/assets/libs/network/protocol/pako.min.js deleted file mode 100644 index 6b4a335..0000000 --- a/assets/libs/network/protocol/pako.min.js +++ /dev/null @@ -1,3424 +0,0 @@ -!(function(t) { - if ('object' == typeof exports && 'undefined' != typeof module) - module.exports = t(); - else if ('function' == typeof define && define.amd) define([], t); - else { - ('undefined' != typeof window - ? window - : 'undefined' != typeof global - ? global - : 'undefined' != typeof self - ? self - : this - ).pako = t(); - } -})(function() { - return (function r(s, o, l) { - function h(e, t) { - if (!o[e]) { - if (!s[e]) { - var a = 'function' == typeof require && require; - if (!t && a) return a(e, !0); - if (d) return d(e, !0); - var i = new Error("Cannot find module '" + e + "'"); - throw ((i.code = 'MODULE_NOT_FOUND'), i); - } - var n = (o[e] = { exports: {} }); - s[e][0].call( - n.exports, - function(t) { - return h(s[e][1][t] || t); - }, - n, - n.exports, - r, - s, - o, - l - ); - } - return o[e].exports; - } - for ( - var d = 'function' == typeof require && require, t = 0; - t < l.length; - t++ - ) - h(l[t]); - return h; - })( - { - 1: [ - function(t, e, a) { - 'use strict'; - var s = t('./zlib/deflate'), - o = t('./utils/common'), - l = t('./utils/strings'), - n = t('./zlib/messages'), - r = t('./zlib/zstream'), - h = Object.prototype.toString, - d = 0, - f = -1, - _ = 0, - u = 8; - function c(t) { - if (!(this instanceof c)) return new c(t); - this.options = o.assign( - { - level: f, - method: u, - chunkSize: 16384, - windowBits: 15, - memLevel: 8, - strategy: _, - to: '' - }, - t || {} - ); - var e = this.options; - e.raw && 0 < e.windowBits - ? (e.windowBits = -e.windowBits) - : e.gzip && - 0 < e.windowBits && - e.windowBits < 16 && - (e.windowBits += 16), - (this.err = 0), - (this.msg = ''), - (this.ended = !1), - (this.chunks = []), - (this.strm = new r()), - (this.strm.avail_out = 0); - var a = s.deflateInit2( - this.strm, - e.level, - e.method, - e.windowBits, - e.memLevel, - e.strategy - ); - if (a !== d) throw new Error(n[a]); - if ( - (e.header && s.deflateSetHeader(this.strm, e.header), - e.dictionary) - ) { - var i; - if ( - ((i = - 'string' == typeof e.dictionary - ? l.string2buf(e.dictionary) - : '[object ArrayBuffer]' === h.call(e.dictionary) - ? new Uint8Array(e.dictionary) - : e.dictionary), - (a = s.deflateSetDictionary(this.strm, i)) !== d) - ) - throw new Error(n[a]); - this._dict_set = !0; - } - } - function i(t, e) { - var a = new c(e); - if ((a.push(t, !0), a.err)) throw a.msg || n[a.err]; - return a.result; - } - (c.prototype.push = function(t, e) { - var a, - i, - n = this.strm, - r = this.options.chunkSize; - if (this.ended) return !1; - (i = e === ~~e ? e : !0 === e ? 4 : 0), - 'string' == typeof t - ? (n.input = l.string2buf(t)) - : '[object ArrayBuffer]' === h.call(t) - ? (n.input = new Uint8Array(t)) - : (n.input = t), - (n.next_in = 0), - (n.avail_in = n.input.length); - do { - if ( - (0 === n.avail_out && - ((n.output = new o.Buf8(r)), - (n.next_out = 0), - (n.avail_out = r)), - 1 !== (a = s.deflate(n, i)) && a !== d) - ) - return this.onEnd(a), !(this.ended = !0); - (0 !== n.avail_out && - (0 !== n.avail_in || (4 !== i && 2 !== i))) || - ('string' === this.options.to - ? this.onData( - l.buf2binstring(o.shrinkBuf(n.output, n.next_out)) - ) - : this.onData(o.shrinkBuf(n.output, n.next_out))); - } while ((0 < n.avail_in || 0 === n.avail_out) && 1 !== a); - return 4 === i - ? ((a = s.deflateEnd(this.strm)), - this.onEnd(a), - (this.ended = !0), - a === d) - : 2 !== i || (this.onEnd(d), !(n.avail_out = 0)); - }), - (c.prototype.onData = function(t) { - this.chunks.push(t); - }), - (c.prototype.onEnd = function(t) { - t === d && - ('string' === this.options.to - ? (this.result = this.chunks.join('')) - : (this.result = o.flattenChunks(this.chunks))), - (this.chunks = []), - (this.err = t), - (this.msg = this.strm.msg); - }), - (a.Deflate = c), - (a.deflate = i), - (a.deflateRaw = function(t, e) { - return ((e = e || {}).raw = !0), i(t, e); - }), - (a.gzip = function(t, e) { - return ((e = e || {}).gzip = !0), i(t, e); - }); - }, - { - './utils/common': 3, - './utils/strings': 4, - './zlib/deflate': 8, - './zlib/messages': 13, - './zlib/zstream': 15 - } - ], - 2: [ - function(t, e, a) { - 'use strict'; - var f = t('./zlib/inflate'), - _ = t('./utils/common'), - u = t('./utils/strings'), - c = t('./zlib/constants'), - i = t('./zlib/messages'), - n = t('./zlib/zstream'), - r = t('./zlib/gzheader'), - b = Object.prototype.toString; - function s(t) { - if (!(this instanceof s)) return new s(t); - this.options = _.assign( - { chunkSize: 16384, windowBits: 0, to: '' }, - t || {} - ); - var e = this.options; - e.raw && - 0 <= e.windowBits && - e.windowBits < 16 && - ((e.windowBits = -e.windowBits), - 0 === e.windowBits && (e.windowBits = -15)), - !(0 <= e.windowBits && e.windowBits < 16) || - (t && t.windowBits) || - (e.windowBits += 32), - 15 < e.windowBits && - e.windowBits < 48 && - 0 == (15 & e.windowBits) && - (e.windowBits |= 15), - (this.err = 0), - (this.msg = ''), - (this.ended = !1), - (this.chunks = []), - (this.strm = new n()), - (this.strm.avail_out = 0); - var a = f.inflateInit2(this.strm, e.windowBits); - if (a !== c.Z_OK) throw new Error(i[a]); - if ( - ((this.header = new r()), - f.inflateGetHeader(this.strm, this.header), - e.dictionary && - ('string' == typeof e.dictionary - ? (e.dictionary = u.string2buf(e.dictionary)) - : '[object ArrayBuffer]' === b.call(e.dictionary) && - (e.dictionary = new Uint8Array(e.dictionary)), - e.raw && - (a = f.inflateSetDictionary(this.strm, e.dictionary)) !== - c.Z_OK)) - ) - throw new Error(i[a]); - } - function o(t, e) { - var a = new s(e); - if ((a.push(t, !0), a.err)) throw a.msg || i[a.err]; - return a.result; - } - (s.prototype.push = function(t, e) { - var a, - i, - n, - r, - s, - o = this.strm, - l = this.options.chunkSize, - h = this.options.dictionary, - d = !1; - if (this.ended) return !1; - (i = e === ~~e ? e : !0 === e ? c.Z_FINISH : c.Z_NO_FLUSH), - 'string' == typeof t - ? (o.input = u.binstring2buf(t)) - : '[object ArrayBuffer]' === b.call(t) - ? (o.input = new Uint8Array(t)) - : (o.input = t), - (o.next_in = 0), - (o.avail_in = o.input.length); - do { - if ( - (0 === o.avail_out && - ((o.output = new _.Buf8(l)), - (o.next_out = 0), - (o.avail_out = l)), - (a = f.inflate(o, c.Z_NO_FLUSH)) === c.Z_NEED_DICT && - h && - (a = f.inflateSetDictionary(this.strm, h)), - a === c.Z_BUF_ERROR && !0 === d && ((a = c.Z_OK), (d = !1)), - a !== c.Z_STREAM_END && a !== c.Z_OK) - ) - return this.onEnd(a), !(this.ended = !0); - o.next_out && - ((0 !== o.avail_out && - a !== c.Z_STREAM_END && - (0 !== o.avail_in || - (i !== c.Z_FINISH && i !== c.Z_SYNC_FLUSH))) || - ('string' === this.options.to - ? ((n = u.utf8border(o.output, o.next_out)), - (r = o.next_out - n), - (s = u.buf2string(o.output, n)), - (o.next_out = r), - (o.avail_out = l - r), - r && _.arraySet(o.output, o.output, n, r, 0), - this.onData(s)) - : this.onData(_.shrinkBuf(o.output, o.next_out)))), - 0 === o.avail_in && 0 === o.avail_out && (d = !0); - } while ( - (0 < o.avail_in || 0 === o.avail_out) && - a !== c.Z_STREAM_END - ); - return ( - a === c.Z_STREAM_END && (i = c.Z_FINISH), - i === c.Z_FINISH - ? ((a = f.inflateEnd(this.strm)), - this.onEnd(a), - (this.ended = !0), - a === c.Z_OK) - : i !== c.Z_SYNC_FLUSH || - (this.onEnd(c.Z_OK), !(o.avail_out = 0)) - ); - }), - (s.prototype.onData = function(t) { - this.chunks.push(t); - }), - (s.prototype.onEnd = function(t) { - t === c.Z_OK && - ('string' === this.options.to - ? (this.result = this.chunks.join('')) - : (this.result = _.flattenChunks(this.chunks))), - (this.chunks = []), - (this.err = t), - (this.msg = this.strm.msg); - }), - (a.Inflate = s), - (a.inflate = o), - (a.inflateRaw = function(t, e) { - return ((e = e || {}).raw = !0), o(t, e); - }), - (a.ungzip = o); - }, - { - './utils/common': 3, - './utils/strings': 4, - './zlib/constants': 6, - './zlib/gzheader': 9, - './zlib/inflate': 11, - './zlib/messages': 13, - './zlib/zstream': 15 - } - ], - 3: [ - function(t, e, a) { - 'use strict'; - var i = - 'undefined' != typeof Uint8Array && - 'undefined' != typeof Uint16Array && - 'undefined' != typeof Int32Array; - (a.assign = function(t) { - for ( - var e, a, i = Array.prototype.slice.call(arguments, 1); - i.length; - - ) { - var n = i.shift(); - if (n) { - if ('object' != typeof n) - throw new TypeError(n + 'must be non-object'); - for (var r in n) - (e = n), - (a = r), - Object.prototype.hasOwnProperty.call(e, a) && (t[r] = n[r]); - } - } - return t; - }), - (a.shrinkBuf = function(t, e) { - return t.length === e - ? t - : t.subarray - ? t.subarray(0, e) - : ((t.length = e), t); - }); - var n = { - arraySet: function(t, e, a, i, n) { - if (e.subarray && t.subarray) t.set(e.subarray(a, a + i), n); - else for (var r = 0; r < i; r++) t[n + r] = e[a + r]; - }, - flattenChunks: function(t) { - var e, a, i, n, r, s; - for (e = i = 0, a = t.length; e < a; e++) i += t[e].length; - for (s = new Uint8Array(i), e = n = 0, a = t.length; e < a; e++) - (r = t[e]), s.set(r, n), (n += r.length); - return s; - } - }, - r = { - arraySet: function(t, e, a, i, n) { - for (var r = 0; r < i; r++) t[n + r] = e[a + r]; - }, - flattenChunks: function(t) { - return [].concat.apply([], t); - } - }; - (a.setTyped = function(t) { - t - ? ((a.Buf8 = Uint8Array), - (a.Buf16 = Uint16Array), - (a.Buf32 = Int32Array), - a.assign(a, n)) - : ((a.Buf8 = Array), - (a.Buf16 = Array), - (a.Buf32 = Array), - a.assign(a, r)); - }), - a.setTyped(i); - }, - {} - ], - 4: [ - function(t, e, a) { - 'use strict'; - var l = t('./common'), - n = !0, - r = !0; - try { - String.fromCharCode.apply(null, [0]); - } catch (t) { - n = !1; - } - try { - String.fromCharCode.apply(null, new Uint8Array(1)); - } catch (t) { - r = !1; - } - for (var h = new l.Buf8(256), i = 0; i < 256; i++) - h[i] = - 252 <= i - ? 6 - : 248 <= i - ? 5 - : 240 <= i - ? 4 - : 224 <= i - ? 3 - : 192 <= i - ? 2 - : 1; - function d(t, e) { - if (e < 65534 && ((t.subarray && r) || (!t.subarray && n))) - return String.fromCharCode.apply(null, l.shrinkBuf(t, e)); - for (var a = '', i = 0; i < e; i++) a += String.fromCharCode(t[i]); - return a; - } - (h[254] = h[254] = 1), - (a.string2buf = function(t) { - var e, - a, - i, - n, - r, - s = t.length, - o = 0; - for (n = 0; n < s; n++) - 55296 == (64512 & (a = t.charCodeAt(n))) && - n + 1 < s && - 56320 == (64512 & (i = t.charCodeAt(n + 1))) && - ((a = 65536 + ((a - 55296) << 10) + (i - 56320)), n++), - (o += a < 128 ? 1 : a < 2048 ? 2 : a < 65536 ? 3 : 4); - for (e = new l.Buf8(o), n = r = 0; r < o; n++) - 55296 == (64512 & (a = t.charCodeAt(n))) && - n + 1 < s && - 56320 == (64512 & (i = t.charCodeAt(n + 1))) && - ((a = 65536 + ((a - 55296) << 10) + (i - 56320)), n++), - a < 128 - ? (e[r++] = a) - : (a < 2048 - ? (e[r++] = 192 | (a >>> 6)) - : (a < 65536 - ? (e[r++] = 224 | (a >>> 12)) - : ((e[r++] = 240 | (a >>> 18)), - (e[r++] = 128 | ((a >>> 12) & 63))), - (e[r++] = 128 | ((a >>> 6) & 63))), - (e[r++] = 128 | (63 & a))); - return e; - }), - (a.buf2binstring = function(t) { - return d(t, t.length); - }), - (a.binstring2buf = function(t) { - for ( - var e = new l.Buf8(t.length), a = 0, i = e.length; - a < i; - a++ - ) - e[a] = t.charCodeAt(a); - return e; - }), - (a.buf2string = function(t, e) { - var a, - i, - n, - r, - s = e || t.length, - o = new Array(2 * s); - for (a = i = 0; a < s; ) - if ((n = t[a++]) < 128) o[i++] = n; - else if (4 < (r = h[n])) (o[i++] = 65533), (a += r - 1); - else { - for (n &= 2 === r ? 31 : 3 === r ? 15 : 7; 1 < r && a < s; ) - (n = (n << 6) | (63 & t[a++])), r--; - 1 < r - ? (o[i++] = 65533) - : n < 65536 - ? (o[i++] = n) - : ((n -= 65536), - (o[i++] = 55296 | ((n >> 10) & 1023)), - (o[i++] = 56320 | (1023 & n))); - } - return d(o, i); - }), - (a.utf8border = function(t, e) { - var a; - for ( - (e = e || t.length) > t.length && (e = t.length), a = e - 1; - 0 <= a && 128 == (192 & t[a]); - - ) - a--; - return a < 0 ? e : 0 === a ? e : a + h[t[a]] > e ? a : e; - }); - }, - { './common': 3 } - ], - 5: [ - function(t, e, a) { - 'use strict'; - e.exports = function(t, e, a, i) { - for ( - var n = (65535 & t) | 0, r = ((t >>> 16) & 65535) | 0, s = 0; - 0 !== a; - - ) { - for ( - a -= s = 2e3 < a ? 2e3 : a; - (r = (r + (n = (n + e[i++]) | 0)) | 0), --s; - - ); - (n %= 65521), (r %= 65521); - } - return n | (r << 16) | 0; - }; - }, - {} - ], - 6: [ - function(t, e, a) { - 'use strict'; - e.exports = { - Z_NO_FLUSH: 0, - Z_PARTIAL_FLUSH: 1, - Z_SYNC_FLUSH: 2, - Z_FULL_FLUSH: 3, - Z_FINISH: 4, - Z_BLOCK: 5, - Z_TREES: 6, - Z_OK: 0, - Z_STREAM_END: 1, - Z_NEED_DICT: 2, - Z_ERRNO: -1, - Z_STREAM_ERROR: -2, - Z_DATA_ERROR: -3, - Z_BUF_ERROR: -5, - Z_NO_COMPRESSION: 0, - Z_BEST_SPEED: 1, - Z_BEST_COMPRESSION: 9, - Z_DEFAULT_COMPRESSION: -1, - Z_FILTERED: 1, - Z_HUFFMAN_ONLY: 2, - Z_RLE: 3, - Z_FIXED: 4, - Z_DEFAULT_STRATEGY: 0, - Z_BINARY: 0, - Z_TEXT: 1, - Z_UNKNOWN: 2, - Z_DEFLATED: 8 - }; - }, - {} - ], - 7: [ - function(t, e, a) { - 'use strict'; - var o = (function() { - for (var t, e = [], a = 0; a < 256; a++) { - t = a; - for (var i = 0; i < 8; i++) - t = 1 & t ? 3988292384 ^ (t >>> 1) : t >>> 1; - e[a] = t; - } - return e; - })(); - e.exports = function(t, e, a, i) { - var n = o, - r = i + a; - t ^= -1; - for (var s = i; s < r; s++) t = (t >>> 8) ^ n[255 & (t ^ e[s])]; - return -1 ^ t; - }; - }, - {} - ], - 8: [ - function(t, e, a) { - 'use strict'; - var l, - _ = t('../utils/common'), - h = t('./trees'), - u = t('./adler32'), - c = t('./crc32'), - i = t('./messages'), - d = 0, - f = 4, - b = 0, - g = -2, - m = -1, - w = 4, - n = 2, - p = 8, - v = 9, - r = 286, - s = 30, - o = 19, - k = 2 * r + 1, - y = 15, - x = 3, - z = 258, - B = z + x + 1, - S = 42, - E = 113, - A = 1, - Z = 2, - R = 3, - C = 4; - function N(t, e) { - return (t.msg = i[e]), e; - } - function O(t) { - return (t << 1) - (4 < t ? 9 : 0); - } - function D(t) { - for (var e = t.length; 0 <= --e; ) t[e] = 0; - } - function I(t) { - var e = t.state, - a = e.pending; - a > t.avail_out && (a = t.avail_out), - 0 !== a && - (_.arraySet( - t.output, - e.pending_buf, - e.pending_out, - a, - t.next_out - ), - (t.next_out += a), - (e.pending_out += a), - (t.total_out += a), - (t.avail_out -= a), - (e.pending -= a), - 0 === e.pending && (e.pending_out = 0)); - } - function U(t, e) { - h._tr_flush_block( - t, - 0 <= t.block_start ? t.block_start : -1, - t.strstart - t.block_start, - e - ), - (t.block_start = t.strstart), - I(t.strm); - } - function T(t, e) { - t.pending_buf[t.pending++] = e; - } - function F(t, e) { - (t.pending_buf[t.pending++] = (e >>> 8) & 255), - (t.pending_buf[t.pending++] = 255 & e); - } - function L(t, e) { - var a, - i, - n = t.max_chain_length, - r = t.strstart, - s = t.prev_length, - o = t.nice_match, - l = t.strstart > t.w_size - B ? t.strstart - (t.w_size - B) : 0, - h = t.window, - d = t.w_mask, - f = t.prev, - _ = t.strstart + z, - u = h[r + s - 1], - c = h[r + s]; - t.prev_length >= t.good_match && (n >>= 2), - o > t.lookahead && (o = t.lookahead); - do { - if ( - h[(a = e) + s] === c && - h[a + s - 1] === u && - h[a] === h[r] && - h[++a] === h[r + 1] - ) { - (r += 2), a++; - do {} while ( - h[++r] === h[++a] && - h[++r] === h[++a] && - h[++r] === h[++a] && - h[++r] === h[++a] && - h[++r] === h[++a] && - h[++r] === h[++a] && - h[++r] === h[++a] && - h[++r] === h[++a] && - r < _ - ); - if (((i = z - (_ - r)), (r = _ - z), s < i)) { - if (((t.match_start = e), o <= (s = i))) break; - (u = h[r + s - 1]), (c = h[r + s]); - } - } - } while ((e = f[e & d]) > l && 0 != --n); - return s <= t.lookahead ? s : t.lookahead; - } - function H(t) { - var e, - a, - i, - n, - r, - s, - o, - l, - h, - d, - f = t.w_size; - do { - if ( - ((n = t.window_size - t.lookahead - t.strstart), - t.strstart >= f + (f - B)) - ) { - for ( - _.arraySet(t.window, t.window, f, f, 0), - t.match_start -= f, - t.strstart -= f, - t.block_start -= f, - e = a = t.hash_size; - (i = t.head[--e]), (t.head[e] = f <= i ? i - f : 0), --a; - - ); - for ( - e = a = f; - (i = t.prev[--e]), (t.prev[e] = f <= i ? i - f : 0), --a; - - ); - n += f; - } - if (0 === t.strm.avail_in) break; - if ( - ((s = t.strm), - (o = t.window), - (l = t.strstart + t.lookahead), - (h = n), - (d = void 0), - (d = s.avail_in), - h < d && (d = h), - (a = - 0 === d - ? 0 - : ((s.avail_in -= d), - _.arraySet(o, s.input, s.next_in, d, l), - 1 === s.state.wrap - ? (s.adler = u(s.adler, o, d, l)) - : 2 === s.state.wrap && (s.adler = c(s.adler, o, d, l)), - (s.next_in += d), - (s.total_in += d), - d)), - (t.lookahead += a), - t.lookahead + t.insert >= x) - ) - for ( - r = t.strstart - t.insert, - t.ins_h = t.window[r], - t.ins_h = - ((t.ins_h << t.hash_shift) ^ t.window[r + 1]) & - t.hash_mask; - t.insert && - ((t.ins_h = - ((t.ins_h << t.hash_shift) ^ t.window[r + x - 1]) & - t.hash_mask), - (t.prev[r & t.w_mask] = t.head[t.ins_h]), - (t.head[t.ins_h] = r), - r++, - t.insert--, - !(t.lookahead + t.insert < x)); - - ); - } while (t.lookahead < B && 0 !== t.strm.avail_in); - } - function j(t, e) { - for (var a, i; ; ) { - if (t.lookahead < B) { - if ((H(t), t.lookahead < B && e === d)) return A; - if (0 === t.lookahead) break; - } - if ( - ((a = 0), - t.lookahead >= x && - ((t.ins_h = - ((t.ins_h << t.hash_shift) ^ t.window[t.strstart + x - 1]) & - t.hash_mask), - (a = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h]), - (t.head[t.ins_h] = t.strstart)), - 0 !== a && - t.strstart - a <= t.w_size - B && - (t.match_length = L(t, a)), - t.match_length >= x) - ) - if ( - ((i = h._tr_tally( - t, - t.strstart - t.match_start, - t.match_length - x - )), - (t.lookahead -= t.match_length), - t.match_length <= t.max_lazy_match && t.lookahead >= x) - ) { - for ( - t.match_length--; - t.strstart++, - (t.ins_h = - ((t.ins_h << t.hash_shift) ^ - t.window[t.strstart + x - 1]) & - t.hash_mask), - (a = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h]), - (t.head[t.ins_h] = t.strstart), - 0 != --t.match_length; - - ); - t.strstart++; - } else - (t.strstart += t.match_length), - (t.match_length = 0), - (t.ins_h = t.window[t.strstart]), - (t.ins_h = - ((t.ins_h << t.hash_shift) ^ t.window[t.strstart + 1]) & - t.hash_mask); - else - (i = h._tr_tally(t, 0, t.window[t.strstart])), - t.lookahead--, - t.strstart++; - if (i && (U(t, !1), 0 === t.strm.avail_out)) return A; - } - return ( - (t.insert = t.strstart < x - 1 ? t.strstart : x - 1), - e === f - ? (U(t, !0), 0 === t.strm.avail_out ? R : C) - : t.last_lit && (U(t, !1), 0 === t.strm.avail_out) - ? A - : Z - ); - } - function K(t, e) { - for (var a, i, n; ; ) { - if (t.lookahead < B) { - if ((H(t), t.lookahead < B && e === d)) return A; - if (0 === t.lookahead) break; - } - if ( - ((a = 0), - t.lookahead >= x && - ((t.ins_h = - ((t.ins_h << t.hash_shift) ^ t.window[t.strstart + x - 1]) & - t.hash_mask), - (a = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h]), - (t.head[t.ins_h] = t.strstart)), - (t.prev_length = t.match_length), - (t.prev_match = t.match_start), - (t.match_length = x - 1), - 0 !== a && - t.prev_length < t.max_lazy_match && - t.strstart - a <= t.w_size - B && - ((t.match_length = L(t, a)), - t.match_length <= 5 && - (1 === t.strategy || - (t.match_length === x && - 4096 < t.strstart - t.match_start)) && - (t.match_length = x - 1)), - t.prev_length >= x && t.match_length <= t.prev_length) - ) { - for ( - n = t.strstart + t.lookahead - x, - i = h._tr_tally( - t, - t.strstart - 1 - t.prev_match, - t.prev_length - x - ), - t.lookahead -= t.prev_length - 1, - t.prev_length -= 2; - ++t.strstart <= n && - ((t.ins_h = - ((t.ins_h << t.hash_shift) ^ - t.window[t.strstart + x - 1]) & - t.hash_mask), - (a = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h]), - (t.head[t.ins_h] = t.strstart)), - 0 != --t.prev_length; - - ); - if ( - ((t.match_available = 0), - (t.match_length = x - 1), - t.strstart++, - i && (U(t, !1), 0 === t.strm.avail_out)) - ) - return A; - } else if (t.match_available) { - if ( - ((i = h._tr_tally(t, 0, t.window[t.strstart - 1])) && - U(t, !1), - t.strstart++, - t.lookahead--, - 0 === t.strm.avail_out) - ) - return A; - } else (t.match_available = 1), t.strstart++, t.lookahead--; - } - return ( - t.match_available && - ((i = h._tr_tally(t, 0, t.window[t.strstart - 1])), - (t.match_available = 0)), - (t.insert = t.strstart < x - 1 ? t.strstart : x - 1), - e === f - ? (U(t, !0), 0 === t.strm.avail_out ? R : C) - : t.last_lit && (U(t, !1), 0 === t.strm.avail_out) - ? A - : Z - ); - } - function M(t, e, a, i, n) { - (this.good_length = t), - (this.max_lazy = e), - (this.nice_length = a), - (this.max_chain = i), - (this.func = n); - } - function P() { - (this.strm = null), - (this.status = 0), - (this.pending_buf = null), - (this.pending_buf_size = 0), - (this.pending_out = 0), - (this.pending = 0), - (this.wrap = 0), - (this.gzhead = null), - (this.gzindex = 0), - (this.method = p), - (this.last_flush = -1), - (this.w_size = 0), - (this.w_bits = 0), - (this.w_mask = 0), - (this.window = null), - (this.window_size = 0), - (this.prev = null), - (this.head = null), - (this.ins_h = 0), - (this.hash_size = 0), - (this.hash_bits = 0), - (this.hash_mask = 0), - (this.hash_shift = 0), - (this.block_start = 0), - (this.match_length = 0), - (this.prev_match = 0), - (this.match_available = 0), - (this.strstart = 0), - (this.match_start = 0), - (this.lookahead = 0), - (this.prev_length = 0), - (this.max_chain_length = 0), - (this.max_lazy_match = 0), - (this.level = 0), - (this.strategy = 0), - (this.good_match = 0), - (this.nice_match = 0), - (this.dyn_ltree = new _.Buf16(2 * k)), - (this.dyn_dtree = new _.Buf16(2 * (2 * s + 1))), - (this.bl_tree = new _.Buf16(2 * (2 * o + 1))), - D(this.dyn_ltree), - D(this.dyn_dtree), - D(this.bl_tree), - (this.l_desc = null), - (this.d_desc = null), - (this.bl_desc = null), - (this.bl_count = new _.Buf16(y + 1)), - (this.heap = new _.Buf16(2 * r + 1)), - D(this.heap), - (this.heap_len = 0), - (this.heap_max = 0), - (this.depth = new _.Buf16(2 * r + 1)), - D(this.depth), - (this.l_buf = 0), - (this.lit_bufsize = 0), - (this.last_lit = 0), - (this.d_buf = 0), - (this.opt_len = 0), - (this.static_len = 0), - (this.matches = 0), - (this.insert = 0), - (this.bi_buf = 0), - (this.bi_valid = 0); - } - function Y(t) { - var e; - return t && t.state - ? ((t.total_in = t.total_out = 0), - (t.data_type = n), - ((e = t.state).pending = 0), - (e.pending_out = 0), - e.wrap < 0 && (e.wrap = -e.wrap), - (e.status = e.wrap ? S : E), - (t.adler = 2 === e.wrap ? 0 : 1), - (e.last_flush = d), - h._tr_init(e), - b) - : N(t, g); - } - function q(t) { - var e, - a = Y(t); - return ( - a === b && - (((e = t.state).window_size = 2 * e.w_size), - D(e.head), - (e.max_lazy_match = l[e.level].max_lazy), - (e.good_match = l[e.level].good_length), - (e.nice_match = l[e.level].nice_length), - (e.max_chain_length = l[e.level].max_chain), - (e.strstart = 0), - (e.block_start = 0), - (e.lookahead = 0), - (e.insert = 0), - (e.match_length = e.prev_length = x - 1), - (e.match_available = 0), - (e.ins_h = 0)), - a - ); - } - function G(t, e, a, i, n, r) { - if (!t) return g; - var s = 1; - if ( - (e === m && (e = 6), - i < 0 ? ((s = 0), (i = -i)) : 15 < i && ((s = 2), (i -= 16)), - n < 1 || - v < n || - a !== p || - i < 8 || - 15 < i || - e < 0 || - 9 < e || - r < 0 || - w < r) - ) - return N(t, g); - 8 === i && (i = 9); - var o = new P(); - return ( - ((t.state = o).strm = t), - (o.wrap = s), - (o.gzhead = null), - (o.w_bits = i), - (o.w_size = 1 << o.w_bits), - (o.w_mask = o.w_size - 1), - (o.hash_bits = n + 7), - (o.hash_size = 1 << o.hash_bits), - (o.hash_mask = o.hash_size - 1), - (o.hash_shift = ~~((o.hash_bits + x - 1) / x)), - (o.window = new _.Buf8(2 * o.w_size)), - (o.head = new _.Buf16(o.hash_size)), - (o.prev = new _.Buf16(o.w_size)), - (o.lit_bufsize = 1 << (n + 6)), - (o.pending_buf_size = 4 * o.lit_bufsize), - (o.pending_buf = new _.Buf8(o.pending_buf_size)), - (o.d_buf = 1 * o.lit_bufsize), - (o.l_buf = 3 * o.lit_bufsize), - (o.level = e), - (o.strategy = r), - (o.method = a), - q(t) - ); - } - (l = [ - new M(0, 0, 0, 0, function(t, e) { - var a = 65535; - for ( - a > t.pending_buf_size - 5 && (a = t.pending_buf_size - 5); - ; - - ) { - if (t.lookahead <= 1) { - if ((H(t), 0 === t.lookahead && e === d)) return A; - if (0 === t.lookahead) break; - } - (t.strstart += t.lookahead), (t.lookahead = 0); - var i = t.block_start + a; - if ( - (0 === t.strstart || t.strstart >= i) && - ((t.lookahead = t.strstart - i), - (t.strstart = i), - U(t, !1), - 0 === t.strm.avail_out) - ) - return A; - if ( - t.strstart - t.block_start >= t.w_size - B && - (U(t, !1), 0 === t.strm.avail_out) - ) - return A; - } - return ( - (t.insert = 0), - e === f - ? (U(t, !0), 0 === t.strm.avail_out ? R : C) - : (t.strstart > t.block_start && (U(t, !1), t.strm.avail_out), - A) - ); - }), - new M(4, 4, 8, 4, j), - new M(4, 5, 16, 8, j), - new M(4, 6, 32, 32, j), - new M(4, 4, 16, 16, K), - new M(8, 16, 32, 32, K), - new M(8, 16, 128, 128, K), - new M(8, 32, 128, 256, K), - new M(32, 128, 258, 1024, K), - new M(32, 258, 258, 4096, K) - ]), - (a.deflateInit = function(t, e) { - return G(t, e, p, 15, 8, 0); - }), - (a.deflateInit2 = G), - (a.deflateReset = q), - (a.deflateResetKeep = Y), - (a.deflateSetHeader = function(t, e) { - return t && t.state - ? 2 !== t.state.wrap - ? g - : ((t.state.gzhead = e), b) - : g; - }), - (a.deflate = function(t, e) { - var a, i, n, r; - if (!t || !t.state || 5 < e || e < 0) return t ? N(t, g) : g; - if ( - ((i = t.state), - !t.output || - (!t.input && 0 !== t.avail_in) || - (666 === i.status && e !== f)) - ) - return N(t, 0 === t.avail_out ? -5 : g); - if ( - ((i.strm = t), - (a = i.last_flush), - (i.last_flush = e), - i.status === S) - ) - if (2 === i.wrap) - (t.adler = 0), - T(i, 31), - T(i, 139), - T(i, 8), - i.gzhead - ? (T( - i, - (i.gzhead.text ? 1 : 0) + - (i.gzhead.hcrc ? 2 : 0) + - (i.gzhead.extra ? 4 : 0) + - (i.gzhead.name ? 8 : 0) + - (i.gzhead.comment ? 16 : 0) - ), - T(i, 255 & i.gzhead.time), - T(i, (i.gzhead.time >> 8) & 255), - T(i, (i.gzhead.time >> 16) & 255), - T(i, (i.gzhead.time >> 24) & 255), - T( - i, - 9 === i.level - ? 2 - : 2 <= i.strategy || i.level < 2 - ? 4 - : 0 - ), - T(i, 255 & i.gzhead.os), - i.gzhead.extra && - i.gzhead.extra.length && - (T(i, 255 & i.gzhead.extra.length), - T(i, (i.gzhead.extra.length >> 8) & 255)), - i.gzhead.hcrc && - (t.adler = c(t.adler, i.pending_buf, i.pending, 0)), - (i.gzindex = 0), - (i.status = 69)) - : (T(i, 0), - T(i, 0), - T(i, 0), - T(i, 0), - T(i, 0), - T( - i, - 9 === i.level - ? 2 - : 2 <= i.strategy || i.level < 2 - ? 4 - : 0 - ), - T(i, 3), - (i.status = E)); - else { - var s = (p + ((i.w_bits - 8) << 4)) << 8; - (s |= - (2 <= i.strategy || i.level < 2 - ? 0 - : i.level < 6 - ? 1 - : 6 === i.level - ? 2 - : 3) << 6), - 0 !== i.strstart && (s |= 32), - (s += 31 - (s % 31)), - (i.status = E), - F(i, s), - 0 !== i.strstart && - (F(i, t.adler >>> 16), F(i, 65535 & t.adler)), - (t.adler = 1); - } - if (69 === i.status) - if (i.gzhead.extra) { - for ( - n = i.pending; - i.gzindex < (65535 & i.gzhead.extra.length) && - (i.pending !== i.pending_buf_size || - (i.gzhead.hcrc && - i.pending > n && - (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), - I(t), - (n = i.pending), - i.pending !== i.pending_buf_size)); - - ) - T(i, 255 & i.gzhead.extra[i.gzindex]), i.gzindex++; - i.gzhead.hcrc && - i.pending > n && - (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), - i.gzindex === i.gzhead.extra.length && - ((i.gzindex = 0), (i.status = 73)); - } else i.status = 73; - if (73 === i.status) - if (i.gzhead.name) { - n = i.pending; - do { - if ( - i.pending === i.pending_buf_size && - (i.gzhead.hcrc && - i.pending > n && - (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), - I(t), - (n = i.pending), - i.pending === i.pending_buf_size) - ) { - r = 1; - break; - } - T( - i, - (r = - i.gzindex < i.gzhead.name.length - ? 255 & i.gzhead.name.charCodeAt(i.gzindex++) - : 0) - ); - } while (0 !== r); - i.gzhead.hcrc && - i.pending > n && - (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), - 0 === r && ((i.gzindex = 0), (i.status = 91)); - } else i.status = 91; - if (91 === i.status) - if (i.gzhead.comment) { - n = i.pending; - do { - if ( - i.pending === i.pending_buf_size && - (i.gzhead.hcrc && - i.pending > n && - (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), - I(t), - (n = i.pending), - i.pending === i.pending_buf_size) - ) { - r = 1; - break; - } - T( - i, - (r = - i.gzindex < i.gzhead.comment.length - ? 255 & i.gzhead.comment.charCodeAt(i.gzindex++) - : 0) - ); - } while (0 !== r); - i.gzhead.hcrc && - i.pending > n && - (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), - 0 === r && (i.status = 103); - } else i.status = 103; - if ( - (103 === i.status && - (i.gzhead.hcrc - ? (i.pending + 2 > i.pending_buf_size && I(t), - i.pending + 2 <= i.pending_buf_size && - (T(i, 255 & t.adler), - T(i, (t.adler >> 8) & 255), - (t.adler = 0), - (i.status = E))) - : (i.status = E)), - 0 !== i.pending) - ) { - if ((I(t), 0 === t.avail_out)) return (i.last_flush = -1), b; - } else if (0 === t.avail_in && O(e) <= O(a) && e !== f) - return N(t, -5); - if (666 === i.status && 0 !== t.avail_in) return N(t, -5); - if ( - 0 !== t.avail_in || - 0 !== i.lookahead || - (e !== d && 666 !== i.status) - ) { - var o = - 2 === i.strategy - ? (function(t, e) { - for (var a; ; ) { - if (0 === t.lookahead && (H(t), 0 === t.lookahead)) { - if (e === d) return A; - break; - } - if ( - ((t.match_length = 0), - (a = h._tr_tally(t, 0, t.window[t.strstart])), - t.lookahead--, - t.strstart++, - a && (U(t, !1), 0 === t.strm.avail_out)) - ) - return A; - } - return ( - (t.insert = 0), - e === f - ? (U(t, !0), 0 === t.strm.avail_out ? R : C) - : t.last_lit && (U(t, !1), 0 === t.strm.avail_out) - ? A - : Z - ); - })(i, e) - : 3 === i.strategy - ? (function(t, e) { - for (var a, i, n, r, s = t.window; ; ) { - if (t.lookahead <= z) { - if ((H(t), t.lookahead <= z && e === d)) return A; - if (0 === t.lookahead) break; - } - if ( - ((t.match_length = 0), - t.lookahead >= x && - 0 < t.strstart && - (i = s[(n = t.strstart - 1)]) === s[++n] && - i === s[++n] && - i === s[++n]) - ) { - r = t.strstart + z; - do {} while ( - i === s[++n] && - i === s[++n] && - i === s[++n] && - i === s[++n] && - i === s[++n] && - i === s[++n] && - i === s[++n] && - i === s[++n] && - n < r - ); - (t.match_length = z - (r - n)), - t.match_length > t.lookahead && - (t.match_length = t.lookahead); - } - if ( - (t.match_length >= x - ? ((a = h._tr_tally(t, 1, t.match_length - x)), - (t.lookahead -= t.match_length), - (t.strstart += t.match_length), - (t.match_length = 0)) - : ((a = h._tr_tally(t, 0, t.window[t.strstart])), - t.lookahead--, - t.strstart++), - a && (U(t, !1), 0 === t.strm.avail_out)) - ) - return A; - } - return ( - (t.insert = 0), - e === f - ? (U(t, !0), 0 === t.strm.avail_out ? R : C) - : t.last_lit && (U(t, !1), 0 === t.strm.avail_out) - ? A - : Z - ); - })(i, e) - : l[i.level].func(i, e); - if ( - ((o !== R && o !== C) || (i.status = 666), o === A || o === R) - ) - return 0 === t.avail_out && (i.last_flush = -1), b; - if ( - o === Z && - (1 === e - ? h._tr_align(i) - : 5 !== e && - (h._tr_stored_block(i, 0, 0, !1), - 3 === e && - (D(i.head), - 0 === i.lookahead && - ((i.strstart = 0), - (i.block_start = 0), - (i.insert = 0)))), - I(t), - 0 === t.avail_out) - ) - return (i.last_flush = -1), b; - } - return e !== f - ? b - : i.wrap <= 0 - ? 1 - : (2 === i.wrap - ? (T(i, 255 & t.adler), - T(i, (t.adler >> 8) & 255), - T(i, (t.adler >> 16) & 255), - T(i, (t.adler >> 24) & 255), - T(i, 255 & t.total_in), - T(i, (t.total_in >> 8) & 255), - T(i, (t.total_in >> 16) & 255), - T(i, (t.total_in >> 24) & 255)) - : (F(i, t.adler >>> 16), F(i, 65535 & t.adler)), - I(t), - 0 < i.wrap && (i.wrap = -i.wrap), - 0 !== i.pending ? b : 1); - }), - (a.deflateEnd = function(t) { - var e; - return t && t.state - ? (e = t.state.status) !== S && - 69 !== e && - 73 !== e && - 91 !== e && - 103 !== e && - e !== E && - 666 !== e - ? N(t, g) - : ((t.state = null), e === E ? N(t, -3) : b) - : g; - }), - (a.deflateSetDictionary = function(t, e) { - var a, - i, - n, - r, - s, - o, - l, - h, - d = e.length; - if (!t || !t.state) return g; - if ( - 2 === (r = (a = t.state).wrap) || - (1 === r && a.status !== S) || - a.lookahead - ) - return g; - for ( - 1 === r && (t.adler = u(t.adler, e, d, 0)), - a.wrap = 0, - d >= a.w_size && - (0 === r && - (D(a.head), - (a.strstart = 0), - (a.block_start = 0), - (a.insert = 0)), - (h = new _.Buf8(a.w_size)), - _.arraySet(h, e, d - a.w_size, a.w_size, 0), - (e = h), - (d = a.w_size)), - s = t.avail_in, - o = t.next_in, - l = t.input, - t.avail_in = d, - t.next_in = 0, - t.input = e, - H(a); - a.lookahead >= x; - - ) { - for ( - i = a.strstart, n = a.lookahead - (x - 1); - (a.ins_h = - ((a.ins_h << a.hash_shift) ^ a.window[i + x - 1]) & - a.hash_mask), - (a.prev[i & a.w_mask] = a.head[a.ins_h]), - (a.head[a.ins_h] = i), - i++, - --n; - - ); - (a.strstart = i), (a.lookahead = x - 1), H(a); - } - return ( - (a.strstart += a.lookahead), - (a.block_start = a.strstart), - (a.insert = a.lookahead), - (a.lookahead = 0), - (a.match_length = a.prev_length = x - 1), - (a.match_available = 0), - (t.next_in = o), - (t.input = l), - (t.avail_in = s), - (a.wrap = r), - b - ); - }), - (a.deflateInfo = 'pako deflate (from Nodeca project)'); - }, - { - '../utils/common': 3, - './adler32': 5, - './crc32': 7, - './messages': 13, - './trees': 14 - } - ], - 9: [ - function(t, e, a) { - 'use strict'; - e.exports = function() { - (this.text = 0), - (this.time = 0), - (this.xflags = 0), - (this.os = 0), - (this.extra = null), - (this.extra_len = 0), - (this.name = ''), - (this.comment = ''), - (this.hcrc = 0), - (this.done = !1); - }; - }, - {} - ], - 10: [ - function(t, e, a) { - 'use strict'; - e.exports = function(t, e) { - var a, - i, - n, - r, - s, - o, - l, - h, - d, - f, - _, - u, - c, - b, - g, - m, - w, - p, - v, - k, - y, - x, - z, - B, - S; - (a = t.state), - (i = t.next_in), - (B = t.input), - (n = i + (t.avail_in - 5)), - (r = t.next_out), - (S = t.output), - (s = r - (e - t.avail_out)), - (o = r + (t.avail_out - 257)), - (l = a.dmax), - (h = a.wsize), - (d = a.whave), - (f = a.wnext), - (_ = a.window), - (u = a.hold), - (c = a.bits), - (b = a.lencode), - (g = a.distcode), - (m = (1 << a.lenbits) - 1), - (w = (1 << a.distbits) - 1); - t: do { - c < 15 && - ((u += B[i++] << c), (c += 8), (u += B[i++] << c), (c += 8)), - (p = b[u & m]); - e: for (;;) { - if ( - ((u >>>= v = p >>> 24), - (c -= v), - 0 === (v = (p >>> 16) & 255)) - ) - S[r++] = 65535 & p; - else { - if (!(16 & v)) { - if (0 == (64 & v)) { - p = b[(65535 & p) + (u & ((1 << v) - 1))]; - continue e; - } - if (32 & v) { - a.mode = 12; - break t; - } - (t.msg = 'invalid literal/length code'), (a.mode = 30); - break t; - } - (k = 65535 & p), - (v &= 15) && - (c < v && ((u += B[i++] << c), (c += 8)), - (k += u & ((1 << v) - 1)), - (u >>>= v), - (c -= v)), - c < 15 && - ((u += B[i++] << c), - (c += 8), - (u += B[i++] << c), - (c += 8)), - (p = g[u & w]); - a: for (;;) { - if ( - ((u >>>= v = p >>> 24), - (c -= v), - !(16 & (v = (p >>> 16) & 255))) - ) { - if (0 == (64 & v)) { - p = g[(65535 & p) + (u & ((1 << v) - 1))]; - continue a; - } - (t.msg = 'invalid distance code'), (a.mode = 30); - break t; - } - if ( - ((y = 65535 & p), - c < (v &= 15) && - ((u += B[i++] << c), - (c += 8) < v && ((u += B[i++] << c), (c += 8))), - l < (y += u & ((1 << v) - 1))) - ) { - (t.msg = 'invalid distance too far back'), (a.mode = 30); - break t; - } - if (((u >>>= v), (c -= v), (v = r - s) < y)) { - if (d < (v = y - v) && a.sane) { - (t.msg = 'invalid distance too far back'), - (a.mode = 30); - break t; - } - if (((z = _), (x = 0) === f)) { - if (((x += h - v), v < k)) { - for (k -= v; (S[r++] = _[x++]), --v; ); - (x = r - y), (z = S); - } - } else if (f < v) { - if (((x += h + f - v), (v -= f) < k)) { - for (k -= v; (S[r++] = _[x++]), --v; ); - if (((x = 0), f < k)) { - for (k -= v = f; (S[r++] = _[x++]), --v; ); - (x = r - y), (z = S); - } - } - } else if (((x += f - v), v < k)) { - for (k -= v; (S[r++] = _[x++]), --v; ); - (x = r - y), (z = S); - } - for (; 2 < k; ) - (S[r++] = z[x++]), - (S[r++] = z[x++]), - (S[r++] = z[x++]), - (k -= 3); - k && ((S[r++] = z[x++]), 1 < k && (S[r++] = z[x++])); - } else { - for ( - x = r - y; - (S[r++] = S[x++]), - (S[r++] = S[x++]), - (S[r++] = S[x++]), - 2 < (k -= 3); - - ); - k && ((S[r++] = S[x++]), 1 < k && (S[r++] = S[x++])); - } - break; - } - } - break; - } - } while (i < n && r < o); - (i -= k = c >> 3), - (u &= (1 << (c -= k << 3)) - 1), - (t.next_in = i), - (t.next_out = r), - (t.avail_in = i < n ? n - i + 5 : 5 - (i - n)), - (t.avail_out = r < o ? o - r + 257 : 257 - (r - o)), - (a.hold = u), - (a.bits = c); - }; - }, - {} - ], - 11: [ - function(t, e, a) { - 'use strict'; - var Z = t('../utils/common'), - R = t('./adler32'), - C = t('./crc32'), - N = t('./inffast'), - O = t('./inftrees'), - D = 1, - I = 2, - U = 0, - T = -2, - F = 1, - i = 852, - n = 592; - function L(t) { - return ( - ((t >>> 24) & 255) + - ((t >>> 8) & 65280) + - ((65280 & t) << 8) + - ((255 & t) << 24) - ); - } - function r() { - (this.mode = 0), - (this.last = !1), - (this.wrap = 0), - (this.havedict = !1), - (this.flags = 0), - (this.dmax = 0), - (this.check = 0), - (this.total = 0), - (this.head = null), - (this.wbits = 0), - (this.wsize = 0), - (this.whave = 0), - (this.wnext = 0), - (this.window = null), - (this.hold = 0), - (this.bits = 0), - (this.length = 0), - (this.offset = 0), - (this.extra = 0), - (this.lencode = null), - (this.distcode = null), - (this.lenbits = 0), - (this.distbits = 0), - (this.ncode = 0), - (this.nlen = 0), - (this.ndist = 0), - (this.have = 0), - (this.next = null), - (this.lens = new Z.Buf16(320)), - (this.work = new Z.Buf16(288)), - (this.lendyn = null), - (this.distdyn = null), - (this.sane = 0), - (this.back = 0), - (this.was = 0); - } - function s(t) { - var e; - return t && t.state - ? ((e = t.state), - (t.total_in = t.total_out = e.total = 0), - (t.msg = ''), - e.wrap && (t.adler = 1 & e.wrap), - (e.mode = F), - (e.last = 0), - (e.havedict = 0), - (e.dmax = 32768), - (e.head = null), - (e.hold = 0), - (e.bits = 0), - (e.lencode = e.lendyn = new Z.Buf32(i)), - (e.distcode = e.distdyn = new Z.Buf32(n)), - (e.sane = 1), - (e.back = -1), - U) - : T; - } - function o(t) { - var e; - return t && t.state - ? (((e = t.state).wsize = 0), (e.whave = 0), (e.wnext = 0), s(t)) - : T; - } - function l(t, e) { - var a, i; - return t && t.state - ? ((i = t.state), - e < 0 - ? ((a = 0), (e = -e)) - : ((a = 1 + (e >> 4)), e < 48 && (e &= 15)), - e && (e < 8 || 15 < e) - ? T - : (null !== i.window && i.wbits !== e && (i.window = null), - (i.wrap = a), - (i.wbits = e), - o(t))) - : T; - } - function h(t, e) { - var a, i; - return t - ? ((i = new r()), - ((t.state = i).window = null), - (a = l(t, e)) !== U && (t.state = null), - a) - : T; - } - var d, - f, - _ = !0; - function H(t) { - if (_) { - var e; - for (d = new Z.Buf32(512), f = new Z.Buf32(32), e = 0; e < 144; ) - t.lens[e++] = 8; - for (; e < 256; ) t.lens[e++] = 9; - for (; e < 280; ) t.lens[e++] = 7; - for (; e < 288; ) t.lens[e++] = 8; - for ( - O(D, t.lens, 0, 288, d, 0, t.work, { bits: 9 }), e = 0; - e < 32; - - ) - t.lens[e++] = 5; - O(I, t.lens, 0, 32, f, 0, t.work, { bits: 5 }), (_ = !1); - } - (t.lencode = d), - (t.lenbits = 9), - (t.distcode = f), - (t.distbits = 5); - } - function j(t, e, a, i) { - var n, - r = t.state; - return ( - null === r.window && - ((r.wsize = 1 << r.wbits), - (r.wnext = 0), - (r.whave = 0), - (r.window = new Z.Buf8(r.wsize))), - i >= r.wsize - ? (Z.arraySet(r.window, e, a - r.wsize, r.wsize, 0), - (r.wnext = 0), - (r.whave = r.wsize)) - : (i < (n = r.wsize - r.wnext) && (n = i), - Z.arraySet(r.window, e, a - i, n, r.wnext), - (i -= n) - ? (Z.arraySet(r.window, e, a - i, i, 0), - (r.wnext = i), - (r.whave = r.wsize)) - : ((r.wnext += n), - r.wnext === r.wsize && (r.wnext = 0), - r.whave < r.wsize && (r.whave += n))), - 0 - ); - } - (a.inflateReset = o), - (a.inflateReset2 = l), - (a.inflateResetKeep = s), - (a.inflateInit = function(t) { - return h(t, 15); - }), - (a.inflateInit2 = h), - (a.inflate = function(t, e) { - var a, - i, - n, - r, - s, - o, - l, - h, - d, - f, - _, - u, - c, - b, - g, - m, - w, - p, - v, - k, - y, - x, - z, - B, - S = 0, - E = new Z.Buf8(4), - A = [ - 16, - 17, - 18, - 0, - 8, - 7, - 9, - 6, - 10, - 5, - 11, - 4, - 12, - 3, - 13, - 2, - 14, - 1, - 15 - ]; - if (!t || !t.state || !t.output || (!t.input && 0 !== t.avail_in)) - return T; - 12 === (a = t.state).mode && (a.mode = 13), - (s = t.next_out), - (n = t.output), - (l = t.avail_out), - (r = t.next_in), - (i = t.input), - (o = t.avail_in), - (h = a.hold), - (d = a.bits), - (f = o), - (_ = l), - (x = U); - t: for (;;) - switch (a.mode) { - case F: - if (0 === a.wrap) { - a.mode = 13; - break; - } - for (; d < 16; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if (2 & a.wrap && 35615 === h) { - (E[(a.check = 0)] = 255 & h), - (E[1] = (h >>> 8) & 255), - (a.check = C(a.check, E, 2, 0)), - (d = h = 0), - (a.mode = 2); - break; - } - if ( - ((a.flags = 0), - a.head && (a.head.done = !1), - !(1 & a.wrap) || (((255 & h) << 8) + (h >> 8)) % 31) - ) { - (t.msg = 'incorrect header check'), (a.mode = 30); - break; - } - if (8 != (15 & h)) { - (t.msg = 'unknown compression method'), (a.mode = 30); - break; - } - if (((d -= 4), (y = 8 + (15 & (h >>>= 4))), 0 === a.wbits)) - a.wbits = y; - else if (y > a.wbits) { - (t.msg = 'invalid window size'), (a.mode = 30); - break; - } - (a.dmax = 1 << y), - (t.adler = a.check = 1), - (a.mode = 512 & h ? 10 : 12), - (d = h = 0); - break; - case 2: - for (; d < 16; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if (((a.flags = h), 8 != (255 & a.flags))) { - (t.msg = 'unknown compression method'), (a.mode = 30); - break; - } - if (57344 & a.flags) { - (t.msg = 'unknown header flags set'), (a.mode = 30); - break; - } - a.head && (a.head.text = (h >> 8) & 1), - 512 & a.flags && - ((E[0] = 255 & h), - (E[1] = (h >>> 8) & 255), - (a.check = C(a.check, E, 2, 0))), - (d = h = 0), - (a.mode = 3); - case 3: - for (; d < 32; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - a.head && (a.head.time = h), - 512 & a.flags && - ((E[0] = 255 & h), - (E[1] = (h >>> 8) & 255), - (E[2] = (h >>> 16) & 255), - (E[3] = (h >>> 24) & 255), - (a.check = C(a.check, E, 4, 0))), - (d = h = 0), - (a.mode = 4); - case 4: - for (; d < 16; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - a.head && ((a.head.xflags = 255 & h), (a.head.os = h >> 8)), - 512 & a.flags && - ((E[0] = 255 & h), - (E[1] = (h >>> 8) & 255), - (a.check = C(a.check, E, 2, 0))), - (d = h = 0), - (a.mode = 5); - case 5: - if (1024 & a.flags) { - for (; d < 16; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (a.length = h), - a.head && (a.head.extra_len = h), - 512 & a.flags && - ((E[0] = 255 & h), - (E[1] = (h >>> 8) & 255), - (a.check = C(a.check, E, 2, 0))), - (d = h = 0); - } else a.head && (a.head.extra = null); - a.mode = 6; - case 6: - if ( - 1024 & a.flags && - (o < (u = a.length) && (u = o), - u && - (a.head && - ((y = a.head.extra_len - a.length), - a.head.extra || - (a.head.extra = new Array(a.head.extra_len)), - Z.arraySet(a.head.extra, i, r, u, y)), - 512 & a.flags && (a.check = C(a.check, i, u, r)), - (o -= u), - (r += u), - (a.length -= u)), - a.length) - ) - break t; - (a.length = 0), (a.mode = 7); - case 7: - if (2048 & a.flags) { - if (0 === o) break t; - for ( - u = 0; - (y = i[r + u++]), - a.head && - y && - a.length < 65536 && - (a.head.name += String.fromCharCode(y)), - y && u < o; - - ); - if ( - (512 & a.flags && (a.check = C(a.check, i, u, r)), - (o -= u), - (r += u), - y) - ) - break t; - } else a.head && (a.head.name = null); - (a.length = 0), (a.mode = 8); - case 8: - if (4096 & a.flags) { - if (0 === o) break t; - for ( - u = 0; - (y = i[r + u++]), - a.head && - y && - a.length < 65536 && - (a.head.comment += String.fromCharCode(y)), - y && u < o; - - ); - if ( - (512 & a.flags && (a.check = C(a.check, i, u, r)), - (o -= u), - (r += u), - y) - ) - break t; - } else a.head && (a.head.comment = null); - a.mode = 9; - case 9: - if (512 & a.flags) { - for (; d < 16; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if (h !== (65535 & a.check)) { - (t.msg = 'header crc mismatch'), (a.mode = 30); - break; - } - d = h = 0; - } - a.head && - ((a.head.hcrc = (a.flags >> 9) & 1), (a.head.done = !0)), - (t.adler = a.check = 0), - (a.mode = 12); - break; - case 10: - for (; d < 32; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (t.adler = a.check = L(h)), (d = h = 0), (a.mode = 11); - case 11: - if (0 === a.havedict) - return ( - (t.next_out = s), - (t.avail_out = l), - (t.next_in = r), - (t.avail_in = o), - (a.hold = h), - (a.bits = d), - 2 - ); - (t.adler = a.check = 1), (a.mode = 12); - case 12: - if (5 === e || 6 === e) break t; - case 13: - if (a.last) { - (h >>>= 7 & d), (d -= 7 & d), (a.mode = 27); - break; - } - for (; d < 3; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - switch (((a.last = 1 & h), (d -= 1), 3 & (h >>>= 1))) { - case 0: - a.mode = 14; - break; - case 1: - if ((H(a), (a.mode = 20), 6 !== e)) break; - (h >>>= 2), (d -= 2); - break t; - case 2: - a.mode = 17; - break; - case 3: - (t.msg = 'invalid block type'), (a.mode = 30); - } - (h >>>= 2), (d -= 2); - break; - case 14: - for (h >>>= 7 & d, d -= 7 & d; d < 32; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if ((65535 & h) != ((h >>> 16) ^ 65535)) { - (t.msg = 'invalid stored block lengths'), (a.mode = 30); - break; - } - if ( - ((a.length = 65535 & h), - (d = h = 0), - (a.mode = 15), - 6 === e) - ) - break t; - case 15: - a.mode = 16; - case 16: - if ((u = a.length)) { - if ((o < u && (u = o), l < u && (u = l), 0 === u)) - break t; - Z.arraySet(n, i, r, u, s), - (o -= u), - (r += u), - (l -= u), - (s += u), - (a.length -= u); - break; - } - a.mode = 12; - break; - case 17: - for (; d < 14; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if ( - ((a.nlen = 257 + (31 & h)), - (h >>>= 5), - (d -= 5), - (a.ndist = 1 + (31 & h)), - (h >>>= 5), - (d -= 5), - (a.ncode = 4 + (15 & h)), - (h >>>= 4), - (d -= 4), - 286 < a.nlen || 30 < a.ndist) - ) { - (t.msg = 'too many length or distance symbols'), - (a.mode = 30); - break; - } - (a.have = 0), (a.mode = 18); - case 18: - for (; a.have < a.ncode; ) { - for (; d < 3; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (a.lens[A[a.have++]] = 7 & h), (h >>>= 3), (d -= 3); - } - for (; a.have < 19; ) a.lens[A[a.have++]] = 0; - if ( - ((a.lencode = a.lendyn), - (a.lenbits = 7), - (z = { bits: a.lenbits }), - (x = O(0, a.lens, 0, 19, a.lencode, 0, a.work, z)), - (a.lenbits = z.bits), - x) - ) { - (t.msg = 'invalid code lengths set'), (a.mode = 30); - break; - } - (a.have = 0), (a.mode = 19); - case 19: - for (; a.have < a.nlen + a.ndist; ) { - for ( - ; - (m = - ((S = a.lencode[h & ((1 << a.lenbits) - 1)]) >>> 16) & - 255), - (w = 65535 & S), - !((g = S >>> 24) <= d); - - ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if (w < 16) (h >>>= g), (d -= g), (a.lens[a.have++] = w); - else { - if (16 === w) { - for (B = g + 2; d < B; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if (((h >>>= g), (d -= g), 0 === a.have)) { - (t.msg = 'invalid bit length repeat'), - (a.mode = 30); - break; - } - (y = a.lens[a.have - 1]), - (u = 3 + (3 & h)), - (h >>>= 2), - (d -= 2); - } else if (17 === w) { - for (B = g + 3; d < B; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (d -= g), - (y = 0), - (u = 3 + (7 & (h >>>= g))), - (h >>>= 3), - (d -= 3); - } else { - for (B = g + 7; d < B; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (d -= g), - (y = 0), - (u = 11 + (127 & (h >>>= g))), - (h >>>= 7), - (d -= 7); - } - if (a.have + u > a.nlen + a.ndist) { - (t.msg = 'invalid bit length repeat'), (a.mode = 30); - break; - } - for (; u--; ) a.lens[a.have++] = y; - } - } - if (30 === a.mode) break; - if (0 === a.lens[256]) { - (t.msg = 'invalid code -- missing end-of-block'), - (a.mode = 30); - break; - } - if ( - ((a.lenbits = 9), - (z = { bits: a.lenbits }), - (x = O(D, a.lens, 0, a.nlen, a.lencode, 0, a.work, z)), - (a.lenbits = z.bits), - x) - ) { - (t.msg = 'invalid literal/lengths set'), (a.mode = 30); - break; - } - if ( - ((a.distbits = 6), - (a.distcode = a.distdyn), - (z = { bits: a.distbits }), - (x = O( - I, - a.lens, - a.nlen, - a.ndist, - a.distcode, - 0, - a.work, - z - )), - (a.distbits = z.bits), - x) - ) { - (t.msg = 'invalid distances set'), (a.mode = 30); - break; - } - if (((a.mode = 20), 6 === e)) break t; - case 20: - a.mode = 21; - case 21: - if (6 <= o && 258 <= l) { - (t.next_out = s), - (t.avail_out = l), - (t.next_in = r), - (t.avail_in = o), - (a.hold = h), - (a.bits = d), - N(t, _), - (s = t.next_out), - (n = t.output), - (l = t.avail_out), - (r = t.next_in), - (i = t.input), - (o = t.avail_in), - (h = a.hold), - (d = a.bits), - 12 === a.mode && (a.back = -1); - break; - } - for ( - a.back = 0; - (m = - ((S = a.lencode[h & ((1 << a.lenbits) - 1)]) >>> 16) & - 255), - (w = 65535 & S), - !((g = S >>> 24) <= d); - - ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if (m && 0 == (240 & m)) { - for ( - p = g, v = m, k = w; - (m = - ((S = - a.lencode[ - k + ((h & ((1 << (p + v)) - 1)) >> p) - ]) >>> - 16) & - 255), - (w = 65535 & S), - !(p + (g = S >>> 24) <= d); - - ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (h >>>= p), (d -= p), (a.back += p); - } - if ( - ((h >>>= g), - (d -= g), - (a.back += g), - (a.length = w), - 0 === m) - ) { - a.mode = 26; - break; - } - if (32 & m) { - (a.back = -1), (a.mode = 12); - break; - } - if (64 & m) { - (t.msg = 'invalid literal/length code'), (a.mode = 30); - break; - } - (a.extra = 15 & m), (a.mode = 22); - case 22: - if (a.extra) { - for (B = a.extra; d < B; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (a.length += h & ((1 << a.extra) - 1)), - (h >>>= a.extra), - (d -= a.extra), - (a.back += a.extra); - } - (a.was = a.length), (a.mode = 23); - case 23: - for ( - ; - (m = - ((S = a.distcode[h & ((1 << a.distbits) - 1)]) >>> 16) & - 255), - (w = 65535 & S), - !((g = S >>> 24) <= d); - - ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if (0 == (240 & m)) { - for ( - p = g, v = m, k = w; - (m = - ((S = - a.distcode[ - k + ((h & ((1 << (p + v)) - 1)) >> p) - ]) >>> - 16) & - 255), - (w = 65535 & S), - !(p + (g = S >>> 24) <= d); - - ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (h >>>= p), (d -= p), (a.back += p); - } - if (((h >>>= g), (d -= g), (a.back += g), 64 & m)) { - (t.msg = 'invalid distance code'), (a.mode = 30); - break; - } - (a.offset = w), (a.extra = 15 & m), (a.mode = 24); - case 24: - if (a.extra) { - for (B = a.extra; d < B; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - (a.offset += h & ((1 << a.extra) - 1)), - (h >>>= a.extra), - (d -= a.extra), - (a.back += a.extra); - } - if (a.offset > a.dmax) { - (t.msg = 'invalid distance too far back'), (a.mode = 30); - break; - } - a.mode = 25; - case 25: - if (0 === l) break t; - if (((u = _ - l), a.offset > u)) { - if ((u = a.offset - u) > a.whave && a.sane) { - (t.msg = 'invalid distance too far back'), - (a.mode = 30); - break; - } - u > a.wnext - ? ((u -= a.wnext), (c = a.wsize - u)) - : (c = a.wnext - u), - u > a.length && (u = a.length), - (b = a.window); - } else (b = n), (c = s - a.offset), (u = a.length); - for ( - l < u && (u = l), l -= u, a.length -= u; - (n[s++] = b[c++]), --u; - - ); - 0 === a.length && (a.mode = 21); - break; - case 26: - if (0 === l) break t; - (n[s++] = a.length), l--, (a.mode = 21); - break; - case 27: - if (a.wrap) { - for (; d < 32; ) { - if (0 === o) break t; - o--, (h |= i[r++] << d), (d += 8); - } - if ( - ((_ -= l), - (t.total_out += _), - (a.total += _), - _ && - (t.adler = a.check = a.flags - ? C(a.check, n, _, s - _) - : R(a.check, n, _, s - _)), - (_ = l), - (a.flags ? h : L(h)) !== a.check) - ) { - (t.msg = 'incorrect data check'), (a.mode = 30); - break; - } - d = h = 0; - } - a.mode = 28; - case 28: - if (a.wrap && a.flags) { - for (; d < 32; ) { - if (0 === o) break t; - o--, (h += i[r++] << d), (d += 8); - } - if (h !== (4294967295 & a.total)) { - (t.msg = 'incorrect length check'), (a.mode = 30); - break; - } - d = h = 0; - } - a.mode = 29; - case 29: - x = 1; - break t; - case 30: - x = -3; - break t; - case 31: - return -4; - case 32: - default: - return T; - } - return ( - (t.next_out = s), - (t.avail_out = l), - (t.next_in = r), - (t.avail_in = o), - (a.hold = h), - (a.bits = d), - (a.wsize || - (_ !== t.avail_out && - a.mode < 30 && - (a.mode < 27 || 4 !== e))) && - j(t, t.output, t.next_out, _ - t.avail_out) - ? ((a.mode = 31), -4) - : ((f -= t.avail_in), - (_ -= t.avail_out), - (t.total_in += f), - (t.total_out += _), - (a.total += _), - a.wrap && - _ && - (t.adler = a.check = a.flags - ? C(a.check, n, _, t.next_out - _) - : R(a.check, n, _, t.next_out - _)), - (t.data_type = - a.bits + - (a.last ? 64 : 0) + - (12 === a.mode ? 128 : 0) + - (20 === a.mode || 15 === a.mode ? 256 : 0)), - ((0 === f && 0 === _) || 4 === e) && x === U && (x = -5), - x) - ); - }), - (a.inflateEnd = function(t) { - if (!t || !t.state) return T; - var e = t.state; - return e.window && (e.window = null), (t.state = null), U; - }), - (a.inflateGetHeader = function(t, e) { - var a; - return t && t.state - ? 0 == (2 & (a = t.state).wrap) - ? T - : (((a.head = e).done = !1), U) - : T; - }), - (a.inflateSetDictionary = function(t, e) { - var a, - i = e.length; - return t && t.state - ? 0 !== (a = t.state).wrap && 11 !== a.mode - ? T - : 11 === a.mode && R(1, e, i, 0) !== a.check - ? -3 - : j(t, e, i, i) - ? ((a.mode = 31), -4) - : ((a.havedict = 1), U) - : T; - }), - (a.inflateInfo = 'pako inflate (from Nodeca project)'); - }, - { - '../utils/common': 3, - './adler32': 5, - './crc32': 7, - './inffast': 10, - './inftrees': 12 - } - ], - 12: [ - function(t, e, a) { - 'use strict'; - var D = t('../utils/common'), - I = [ - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 13, - 15, - 17, - 19, - 23, - 27, - 31, - 35, - 43, - 51, - 59, - 67, - 83, - 99, - 115, - 131, - 163, - 195, - 227, - 258, - 0, - 0 - ], - U = [ - 16, - 16, - 16, - 16, - 16, - 16, - 16, - 16, - 17, - 17, - 17, - 17, - 18, - 18, - 18, - 18, - 19, - 19, - 19, - 19, - 20, - 20, - 20, - 20, - 21, - 21, - 21, - 21, - 16, - 72, - 78 - ], - T = [ - 1, - 2, - 3, - 4, - 5, - 7, - 9, - 13, - 17, - 25, - 33, - 49, - 65, - 97, - 129, - 193, - 257, - 385, - 513, - 769, - 1025, - 1537, - 2049, - 3073, - 4097, - 6145, - 8193, - 12289, - 16385, - 24577, - 0, - 0 - ], - F = [ - 16, - 16, - 16, - 16, - 17, - 17, - 18, - 18, - 19, - 19, - 20, - 20, - 21, - 21, - 22, - 22, - 23, - 23, - 24, - 24, - 25, - 25, - 26, - 26, - 27, - 27, - 28, - 28, - 29, - 29, - 64, - 64 - ]; - e.exports = function(t, e, a, i, n, r, s, o) { - var l, - h, - d, - f, - _, - u, - c, - b, - g, - m = o.bits, - w = 0, - p = 0, - v = 0, - k = 0, - y = 0, - x = 0, - z = 0, - B = 0, - S = 0, - E = 0, - A = null, - Z = 0, - R = new D.Buf16(16), - C = new D.Buf16(16), - N = null, - O = 0; - for (w = 0; w <= 15; w++) R[w] = 0; - for (p = 0; p < i; p++) R[e[a + p]]++; - for (y = m, k = 15; 1 <= k && 0 === R[k]; k--); - if ((k < y && (y = k), 0 === k)) - return (n[r++] = 20971520), (n[r++] = 20971520), (o.bits = 1), 0; - for (v = 1; v < k && 0 === R[v]; v++); - for (y < v && (y = v), w = B = 1; w <= 15; w++) - if (((B <<= 1), (B -= R[w]) < 0)) return -1; - if (0 < B && (0 === t || 1 !== k)) return -1; - for (C[1] = 0, w = 1; w < 15; w++) C[w + 1] = C[w] + R[w]; - for (p = 0; p < i; p++) 0 !== e[a + p] && (s[C[e[a + p]]++] = p); - if ( - (0 === t - ? ((A = N = s), (u = 19)) - : 1 === t - ? ((A = I), (Z -= 257), (N = U), (O -= 257), (u = 256)) - : ((A = T), (N = F), (u = -1)), - (w = v), - (_ = r), - (z = p = E = 0), - (d = -1), - (f = (S = 1 << (x = y)) - 1), - (1 === t && 852 < S) || (2 === t && 592 < S)) - ) - return 1; - for (;;) { - for ( - c = w - z, - s[p] < u - ? ((b = 0), (g = s[p])) - : s[p] > u - ? ((b = N[O + s[p]]), (g = A[Z + s[p]])) - : ((b = 96), (g = 0)), - l = 1 << (w - z), - v = h = 1 << x; - (n[_ + (E >> z) + (h -= l)] = (c << 24) | (b << 16) | g | 0), - 0 !== h; - - ); - for (l = 1 << (w - 1); E & l; ) l >>= 1; - if ( - (0 !== l ? ((E &= l - 1), (E += l)) : (E = 0), p++, 0 == --R[w]) - ) { - if (w === k) break; - w = e[a + s[p]]; - } - if (y < w && (E & f) !== d) { - for ( - 0 === z && (z = y), _ += v, B = 1 << (x = w - z); - x + z < k && !((B -= R[x + z]) <= 0); - - ) - x++, (B <<= 1); - if ( - ((S += 1 << x), (1 === t && 852 < S) || (2 === t && 592 < S)) - ) - return 1; - n[(d = E & f)] = (y << 24) | (x << 16) | (_ - r) | 0; - } - } - return ( - 0 !== E && (n[_ + E] = ((w - z) << 24) | (64 << 16) | 0), - (o.bits = y), - 0 - ); - }; - }, - { '../utils/common': 3 } - ], - 13: [ - function(t, e, a) { - 'use strict'; - e.exports = { - 2: 'need dictionary', - 1: 'stream end', - 0: '', - '-1': 'file error', - '-2': 'stream error', - '-3': 'data error', - '-4': 'insufficient memory', - '-5': 'buffer error', - '-6': 'incompatible version' - }; - }, - {} - ], - 14: [ - function(t, e, a) { - 'use strict'; - var l = t('../utils/common'), - o = 0, - h = 1; - function i(t) { - for (var e = t.length; 0 <= --e; ) t[e] = 0; - } - var d = 0, - s = 29, - f = 256, - _ = f + 1 + s, - u = 30, - c = 19, - g = 2 * _ + 1, - m = 15, - n = 16, - b = 7, - w = 256, - p = 16, - v = 17, - k = 18, - y = [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 1, - 1, - 2, - 2, - 2, - 2, - 3, - 3, - 3, - 3, - 4, - 4, - 4, - 4, - 5, - 5, - 5, - 5, - 0 - ], - x = [ - 0, - 0, - 0, - 0, - 1, - 1, - 2, - 2, - 3, - 3, - 4, - 4, - 5, - 5, - 6, - 6, - 7, - 7, - 8, - 8, - 9, - 9, - 10, - 10, - 11, - 11, - 12, - 12, - 13, - 13 - ], - z = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7], - B = [ - 16, - 17, - 18, - 0, - 8, - 7, - 9, - 6, - 10, - 5, - 11, - 4, - 12, - 3, - 13, - 2, - 14, - 1, - 15 - ], - S = new Array(2 * (_ + 2)); - i(S); - var E = new Array(2 * u); - i(E); - var A = new Array(512); - i(A); - var Z = new Array(256); - i(Z); - var R = new Array(s); - i(R); - var C, - N, - O, - D = new Array(u); - function I(t, e, a, i, n) { - (this.static_tree = t), - (this.extra_bits = e), - (this.extra_base = a), - (this.elems = i), - (this.max_length = n), - (this.has_stree = t && t.length); - } - function r(t, e) { - (this.dyn_tree = t), (this.max_code = 0), (this.stat_desc = e); - } - function U(t) { - return t < 256 ? A[t] : A[256 + (t >>> 7)]; - } - function T(t, e) { - (t.pending_buf[t.pending++] = 255 & e), - (t.pending_buf[t.pending++] = (e >>> 8) & 255); - } - function F(t, e, a) { - t.bi_valid > n - a - ? ((t.bi_buf |= (e << t.bi_valid) & 65535), - T(t, t.bi_buf), - (t.bi_buf = e >> (n - t.bi_valid)), - (t.bi_valid += a - n)) - : ((t.bi_buf |= (e << t.bi_valid) & 65535), (t.bi_valid += a)); - } - function L(t, e, a) { - F(t, a[2 * e], a[2 * e + 1]); - } - function H(t, e) { - for (var a = 0; (a |= 1 & t), (t >>>= 1), (a <<= 1), 0 < --e; ); - return a >>> 1; - } - function j(t, e, a) { - var i, - n, - r = new Array(m + 1), - s = 0; - for (i = 1; i <= m; i++) r[i] = s = (s + a[i - 1]) << 1; - for (n = 0; n <= e; n++) { - var o = t[2 * n + 1]; - 0 !== o && (t[2 * n] = H(r[o]++, o)); - } - } - function K(t) { - var e; - for (e = 0; e < _; e++) t.dyn_ltree[2 * e] = 0; - for (e = 0; e < u; e++) t.dyn_dtree[2 * e] = 0; - for (e = 0; e < c; e++) t.bl_tree[2 * e] = 0; - (t.dyn_ltree[2 * w] = 1), - (t.opt_len = t.static_len = 0), - (t.last_lit = t.matches = 0); - } - function M(t) { - 8 < t.bi_valid - ? T(t, t.bi_buf) - : 0 < t.bi_valid && (t.pending_buf[t.pending++] = t.bi_buf), - (t.bi_buf = 0), - (t.bi_valid = 0); - } - function P(t, e, a, i) { - var n = 2 * e, - r = 2 * a; - return t[n] < t[r] || (t[n] === t[r] && i[e] <= i[a]); - } - function Y(t, e, a) { - for ( - var i = t.heap[a], n = a << 1; - n <= t.heap_len && - (n < t.heap_len && P(e, t.heap[n + 1], t.heap[n], t.depth) && n++, - !P(e, i, t.heap[n], t.depth)); - - ) - (t.heap[a] = t.heap[n]), (a = n), (n <<= 1); - t.heap[a] = i; - } - function q(t, e, a) { - var i, - n, - r, - s, - o = 0; - if (0 !== t.last_lit) - for ( - ; - (i = - (t.pending_buf[t.d_buf + 2 * o] << 8) | - t.pending_buf[t.d_buf + 2 * o + 1]), - (n = t.pending_buf[t.l_buf + o]), - o++, - 0 === i - ? L(t, n, e) - : (L(t, (r = Z[n]) + f + 1, e), - 0 !== (s = y[r]) && F(t, (n -= R[r]), s), - L(t, (r = U(--i)), a), - 0 !== (s = x[r]) && F(t, (i -= D[r]), s)), - o < t.last_lit; - - ); - L(t, w, e); - } - function G(t, e) { - var a, - i, - n, - r = e.dyn_tree, - s = e.stat_desc.static_tree, - o = e.stat_desc.has_stree, - l = e.stat_desc.elems, - h = -1; - for (t.heap_len = 0, t.heap_max = g, a = 0; a < l; a++) - 0 !== r[2 * a] - ? ((t.heap[++t.heap_len] = h = a), (t.depth[a] = 0)) - : (r[2 * a + 1] = 0); - for (; t.heap_len < 2; ) - (r[2 * (n = t.heap[++t.heap_len] = h < 2 ? ++h : 0)] = 1), - (t.depth[n] = 0), - t.opt_len--, - o && (t.static_len -= s[2 * n + 1]); - for (e.max_code = h, a = t.heap_len >> 1; 1 <= a; a--) Y(t, r, a); - for ( - n = l; - (a = t.heap[1]), - (t.heap[1] = t.heap[t.heap_len--]), - Y(t, r, 1), - (i = t.heap[1]), - (t.heap[--t.heap_max] = a), - (t.heap[--t.heap_max] = i), - (r[2 * n] = r[2 * a] + r[2 * i]), - (t.depth[n] = - (t.depth[a] >= t.depth[i] ? t.depth[a] : t.depth[i]) + 1), - (r[2 * a + 1] = r[2 * i + 1] = n), - (t.heap[1] = n++), - Y(t, r, 1), - 2 <= t.heap_len; - - ); - (t.heap[--t.heap_max] = t.heap[1]), - (function(t, e) { - var a, - i, - n, - r, - s, - o, - l = e.dyn_tree, - h = e.max_code, - d = e.stat_desc.static_tree, - f = e.stat_desc.has_stree, - _ = e.stat_desc.extra_bits, - u = e.stat_desc.extra_base, - c = e.stat_desc.max_length, - b = 0; - for (r = 0; r <= m; r++) t.bl_count[r] = 0; - for ( - l[2 * t.heap[t.heap_max] + 1] = 0, a = t.heap_max + 1; - a < g; - a++ - ) - c < (r = l[2 * l[2 * (i = t.heap[a]) + 1] + 1] + 1) && - ((r = c), b++), - (l[2 * i + 1] = r), - h < i || - (t.bl_count[r]++, - (s = 0), - u <= i && (s = _[i - u]), - (o = l[2 * i]), - (t.opt_len += o * (r + s)), - f && (t.static_len += o * (d[2 * i + 1] + s))); - if (0 !== b) { - do { - for (r = c - 1; 0 === t.bl_count[r]; ) r--; - t.bl_count[r]--, - (t.bl_count[r + 1] += 2), - t.bl_count[c]--, - (b -= 2); - } while (0 < b); - for (r = c; 0 !== r; r--) - for (i = t.bl_count[r]; 0 !== i; ) - h < (n = t.heap[--a]) || - (l[2 * n + 1] !== r && - ((t.opt_len += (r - l[2 * n + 1]) * l[2 * n]), - (l[2 * n + 1] = r)), - i--); - } - })(t, e), - j(r, h, t.bl_count); - } - function X(t, e, a) { - var i, - n, - r = -1, - s = e[1], - o = 0, - l = 7, - h = 4; - for ( - 0 === s && ((l = 138), (h = 3)), - e[2 * (a + 1) + 1] = 65535, - i = 0; - i <= a; - i++ - ) - (n = s), - (s = e[2 * (i + 1) + 1]), - (++o < l && n === s) || - (o < h - ? (t.bl_tree[2 * n] += o) - : 0 !== n - ? (n !== r && t.bl_tree[2 * n]++, t.bl_tree[2 * p]++) - : o <= 10 - ? t.bl_tree[2 * v]++ - : t.bl_tree[2 * k]++, - (r = n), - (o = 0) === s - ? ((l = 138), (h = 3)) - : n === s - ? ((l = 6), (h = 3)) - : ((l = 7), (h = 4))); - } - function W(t, e, a) { - var i, - n, - r = -1, - s = e[1], - o = 0, - l = 7, - h = 4; - for (0 === s && ((l = 138), (h = 3)), i = 0; i <= a; i++) - if (((n = s), (s = e[2 * (i + 1) + 1]), !(++o < l && n === s))) { - if (o < h) for (; L(t, n, t.bl_tree), 0 != --o; ); - else - 0 !== n - ? (n !== r && (L(t, n, t.bl_tree), o--), - L(t, p, t.bl_tree), - F(t, o - 3, 2)) - : o <= 10 - ? (L(t, v, t.bl_tree), F(t, o - 3, 3)) - : (L(t, k, t.bl_tree), F(t, o - 11, 7)); - (r = n), - (o = 0) === s - ? ((l = 138), (h = 3)) - : n === s - ? ((l = 6), (h = 3)) - : ((l = 7), (h = 4)); - } - } - i(D); - var J = !1; - function Q(t, e, a, i) { - var n, r, s, o; - F(t, (d << 1) + (i ? 1 : 0), 3), - (r = e), - (s = a), - (o = !0), - M((n = t)), - o && (T(n, s), T(n, ~s)), - l.arraySet(n.pending_buf, n.window, r, s, n.pending), - (n.pending += s); - } - (a._tr_init = function(t) { - J || - ((function() { - var t, - e, - a, - i, - n, - r = new Array(m + 1); - for (i = a = 0; i < s - 1; i++) - for (R[i] = a, t = 0; t < 1 << y[i]; t++) Z[a++] = i; - for (Z[a - 1] = i, i = n = 0; i < 16; i++) - for (D[i] = n, t = 0; t < 1 << x[i]; t++) A[n++] = i; - for (n >>= 7; i < u; i++) - for (D[i] = n << 7, t = 0; t < 1 << (x[i] - 7); t++) - A[256 + n++] = i; - for (e = 0; e <= m; e++) r[e] = 0; - for (t = 0; t <= 143; ) (S[2 * t + 1] = 8), t++, r[8]++; - for (; t <= 255; ) (S[2 * t + 1] = 9), t++, r[9]++; - for (; t <= 279; ) (S[2 * t + 1] = 7), t++, r[7]++; - for (; t <= 287; ) (S[2 * t + 1] = 8), t++, r[8]++; - for (j(S, _ + 1, r), t = 0; t < u; t++) - (E[2 * t + 1] = 5), (E[2 * t] = H(t, 5)); - (C = new I(S, y, f + 1, _, m)), - (N = new I(E, x, 0, u, m)), - (O = new I(new Array(0), z, 0, c, b)); - })(), - (J = !0)), - (t.l_desc = new r(t.dyn_ltree, C)), - (t.d_desc = new r(t.dyn_dtree, N)), - (t.bl_desc = new r(t.bl_tree, O)), - (t.bi_buf = 0), - (t.bi_valid = 0), - K(t); - }), - (a._tr_stored_block = Q), - (a._tr_flush_block = function(t, e, a, i) { - var n, - r, - s = 0; - 0 < t.level - ? (2 === t.strm.data_type && - (t.strm.data_type = (function(t) { - var e, - a = 4093624447; - for (e = 0; e <= 31; e++, a >>>= 1) - if (1 & a && 0 !== t.dyn_ltree[2 * e]) return o; - if ( - 0 !== t.dyn_ltree[18] || - 0 !== t.dyn_ltree[20] || - 0 !== t.dyn_ltree[26] - ) - return h; - for (e = 32; e < f; e++) - if (0 !== t.dyn_ltree[2 * e]) return h; - return o; - })(t)), - G(t, t.l_desc), - G(t, t.d_desc), - (s = (function(t) { - var e; - for ( - X(t, t.dyn_ltree, t.l_desc.max_code), - X(t, t.dyn_dtree, t.d_desc.max_code), - G(t, t.bl_desc), - e = c - 1; - 3 <= e && 0 === t.bl_tree[2 * B[e] + 1]; - e-- - ); - return (t.opt_len += 3 * (e + 1) + 5 + 5 + 4), e; - })(t)), - (n = (t.opt_len + 3 + 7) >>> 3), - (r = (t.static_len + 3 + 7) >>> 3) <= n && (n = r)) - : (n = r = a + 5), - a + 4 <= n && -1 !== e - ? Q(t, e, a, i) - : 4 === t.strategy || r === n - ? (F(t, 2 + (i ? 1 : 0), 3), q(t, S, E)) - : (F(t, 4 + (i ? 1 : 0), 3), - (function(t, e, a, i) { - var n; - for ( - F(t, e - 257, 5), F(t, a - 1, 5), F(t, i - 4, 4), n = 0; - n < i; - n++ - ) - F(t, t.bl_tree[2 * B[n] + 1], 3); - W(t, t.dyn_ltree, e - 1), W(t, t.dyn_dtree, a - 1); - })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, s + 1), - q(t, t.dyn_ltree, t.dyn_dtree)), - K(t), - i && M(t); - }), - (a._tr_tally = function(t, e, a) { - return ( - (t.pending_buf[t.d_buf + 2 * t.last_lit] = (e >>> 8) & 255), - (t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e), - (t.pending_buf[t.l_buf + t.last_lit] = 255 & a), - t.last_lit++, - 0 === e - ? t.dyn_ltree[2 * a]++ - : (t.matches++, - e--, - t.dyn_ltree[2 * (Z[a] + f + 1)]++, - t.dyn_dtree[2 * U(e)]++), - t.last_lit === t.lit_bufsize - 1 - ); - }), - (a._tr_align = function(t) { - var e; - F(t, 2, 3), - L(t, w, S), - 16 === (e = t).bi_valid - ? (T(e, e.bi_buf), (e.bi_buf = 0), (e.bi_valid = 0)) - : 8 <= e.bi_valid && - ((e.pending_buf[e.pending++] = 255 & e.bi_buf), - (e.bi_buf >>= 8), - (e.bi_valid -= 8)); - }); - }, - { '../utils/common': 3 } - ], - 15: [ - function(t, e, a) { - 'use strict'; - e.exports = function() { - (this.input = null), - (this.next_in = 0), - (this.avail_in = 0), - (this.total_in = 0), - (this.output = null), - (this.next_out = 0), - (this.avail_out = 0), - (this.total_out = 0), - (this.msg = ''), - (this.state = null), - (this.data_type = 2), - (this.adler = 0); - }; - }, - {} - ], - '/': [ - function(t, e, a) { - 'use strict'; - var i = {}; - (0, t('./lib/utils/common').assign)( - i, - t('./lib/deflate'), - t('./lib/inflate'), - t('./lib/zlib/constants') - ), - (e.exports = i); - }, - { - './lib/deflate': 1, - './lib/inflate': 2, - './lib/utils/common': 3, - './lib/zlib/constants': 6 - } - ] - }, - {}, - [] - )('/'); -}); diff --git a/assets/libs/network/protocol/pako.min.js.meta b/assets/libs/network/protocol/pako.min.js.meta deleted file mode 100644 index 19c0b67..0000000 --- a/assets/libs/network/protocol/pako.min.js.meta +++ /dev/null @@ -1,17 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "javascript", - "imported": true, - "uuid": "60e799a8-4bb9-4e3d-8b8c-ab86909f9eb8", - "files": [ - ".js" - ], - "subMetas": {}, - "userData": { - "isPlugin": true, - "loadPluginInWeb": true, - "loadPluginInNative": false, - "loadPluginInEditor": false, - "loadPluginInMiniGame": true - } -} -- Gitee From dc19ee9025326e42f10e9ba1c52c399fc0d4bd8c Mon Sep 17 00:00:00 2001 From: dgflash Date: Wed, 23 Jul 2025 10:11:55 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9ResLoader.loadBundle?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5=E6=97=B6=E8=BF=94=E5=9B=9E?= =?UTF-8?q?null=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=8A=A5=E9=94=99=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/common/loader/ResLoader.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assets/core/common/loader/ResLoader.ts b/assets/core/common/loader/ResLoader.ts index 50b856c..85098b1 100644 --- a/assets/core/common/loader/ResLoader.ts +++ b/assets/core/common/loader/ResLoader.ts @@ -1,4 +1,4 @@ -import { __private, AnimationClip, Asset, AssetManager, assetManager, AudioClip, error, Font, ImageAsset, js, JsonAsset, Material, Mesh, Prefab, resources, sp, SpriteFrame, Texture2D, warn } from "cc"; +import { __private, AnimationClip, Asset, AssetManager, assetManager, AudioClip, Font, ImageAsset, js, JsonAsset, Material, Mesh, Prefab, resources, sp, SpriteFrame, Texture2D, warn } from "cc"; export type AssetType = __private.__types_globals__Constructor | null; export type Paths = string | string[]; @@ -120,11 +120,12 @@ oops.res.loadRemote(this.url, opt, onComplete); * @example await oops.res.loadBundle(name); */ - loadBundle(name: string) { + loadBundle(name: string): Promise { return new Promise((resolve, reject) => { assetManager.loadBundle(name, (err, bundle: AssetManager.Bundle) => { if (err) { - return error(err); + resolve(null!); + return; } resolve(bundle); }); -- Gitee From 501b20ee1d5a72a0ceece43b7dd216094a9f2a70 Mon Sep 17 00:00:00 2001 From: dgflash Date: Fri, 25 Jul 2025 23:30:35 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/gui/language/LanguagePack.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/assets/libs/gui/language/LanguagePack.ts b/assets/libs/gui/language/LanguagePack.ts index f2e56bf..53bfadf 100644 --- a/assets/libs/gui/language/LanguagePack.ts +++ b/assets/libs/gui/language/LanguagePack.ts @@ -42,35 +42,35 @@ export class LanguagePack { } /** 多语言Excel配置表数据 */ - private loadTable(lang: string) { + private loadTable(lang: string): Promise { return new Promise(async (resolve, reject) => { let json = await JsonUtil.loadAsync("Language"); if (json) { LanguageData.language.set(LanguageDataType.Excel, json); Logger.instance.logConfig("config/game/Language", "下载语言包 table 资源"); } - resolve(null); + resolve(); }); } /** 纹理多语言资源 */ - private loadTexture(lang: string) { + private loadTexture(lang: string): Promise { return new Promise((resolve, reject) => { const path = `${LanguageData.path_texture}/${lang}`; resLoader.loadDir(path, (err: any, assets: any) => { if (err) { error(err); - resolve(null); + resolve(); return; } Logger.instance.logConfig(path, "下载语言包 textures 资源"); - resolve(null); + resolve(); }); }); } /** Json格式多语言资源 */ - private loadJson(lang: string) { + private loadJson(lang: string): Promise { return new Promise(async (resolve, reject) => { const path = `${LanguageData.path_json}/${lang}`; const jsonAsset = await resLoader.loadAsync(path, JsonAsset); @@ -79,30 +79,30 @@ export class LanguagePack { Logger.instance.logConfig(path, "下载语言包 json 资源"); } else { - resolve(null); + resolve(); return; } resLoader.load(path, TTFFont, (err: Error | null, font: TTFFont) => { if (err == null) Logger.instance.logConfig(path, "下载语言包 ttf 资源"); LanguageData.font = font; - resolve(null); + resolve(); }); }); } /** SPINE动画多语言资源 */ - private loadSpine(lang: string) { + private loadSpine(lang: string): Promise { return new Promise(async (resolve, reject) => { const path = `${LanguageData.path_spine}/${lang}`; resLoader.loadDir(path, (err: any, assets: any) => { if (err) { error(err); - resolve(null); + resolve(); return; } Logger.instance.logConfig(path, "下载语言包 spine 资源"); - resolve(null); + resolve(); }) }); } -- Gitee From 91786493f7b3fafee8c9fb19db160d4c94991368 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 26 Jul 2025 12:45:37 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BC=A0=E7=AA=97=E5=8F=A3=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F=E5=BC=80=E5=85=B3=201=E3=80=81?= =?UTF-8?q?=E7=9C=81=E5=8E=BBUIID=E6=9E=9A=E4=B8=BE=E9=85=8D=E7=BD=AE=202?= =?UTF-8?q?=E3=80=81=E6=AF=8F=E4=B8=AA=E6=A8=A1=E5=9D=97=E7=9A=84=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E9=85=8D=E7=BD=AE=E5=8F=AF=E4=BB=A3=E7=A0=81=E5=88=86?= =?UTF-8?q?=E7=A6=BB=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/Defines.ts | 3 +- assets/core/gui/layer/DelegateComponent.ts | 5 - assets/core/gui/layer/LayerEnum.ts | 7 + assets/core/gui/layer/LayerManager.ts | 211 +++++++++------------ assets/core/gui/layer/LayerUI.ts | 5 +- assets/core/gui/layer/UIConfig.ts | 9 +- assets/module/common/ModuleUtil.ts | 6 +- 7 files changed, 110 insertions(+), 136 deletions(-) diff --git a/assets/core/gui/layer/Defines.ts b/assets/core/gui/layer/Defines.ts index b6808a4..18e6235 100644 --- a/assets/core/gui/layer/Defines.ts +++ b/assets/core/gui/layer/Defines.ts @@ -5,6 +5,7 @@ * @LastEditTime: 2023-01-09 11:52:38 */ import { Node } from "cc"; +import { Uiid } from "./LayerEnum"; import { UIConfig } from "./UIConfig"; /*** 界面回调参数对象定义 */ @@ -39,7 +40,7 @@ export interface UICallbacks { /** 本类型仅供gui模块内部使用,请勿在功能逻辑中使用 */ export class ViewParams { /** 界面唯一编号 */ - uiid: number = -1; + uiid: string = null!; /** 界面配置 */ config: UIConfig = null!; /** 传递给打开界面的参数 */ diff --git a/assets/core/gui/layer/DelegateComponent.ts b/assets/core/gui/layer/DelegateComponent.ts index bd20420..36a12b7 100644 --- a/assets/core/gui/layer/DelegateComponent.ts +++ b/assets/core/gui/layer/DelegateComponent.ts @@ -96,11 +96,6 @@ export class DelegateComponent extends Component { // 释放界面相关资源 oops.res.release(vp.config.prefab, vp.config.bundle); - // 释放自动递增编号的界面配置 - if (vp.config.auto) { - oops.gui.setConfig(vp.uiid, null!); - } - oops.log.logView(`【界面管理】释放【${vp.config.prefab}】界面资源`); } else { diff --git a/assets/core/gui/layer/LayerEnum.ts b/assets/core/gui/layer/LayerEnum.ts index 5f13ebc..5ded033 100644 --- a/assets/core/gui/layer/LayerEnum.ts +++ b/assets/core/gui/layer/LayerEnum.ts @@ -1,3 +1,10 @@ +import { UIConfig } from "./UIConfig"; + +/** 界面编号 */ +export type Uiid = number | string | UIConfig; +/** 界面配置集合 */ +export type UIConfigMap = { [key: string]: UIConfig } + /** 屏幕适配类型 */ export enum ScreenAdapterType { /** 自动适配 */ diff --git a/assets/core/gui/layer/LayerManager.ts b/assets/core/gui/layer/LayerManager.ts index 4dc08a3..67dae73 100644 --- a/assets/core/gui/layer/LayerManager.ts +++ b/assets/core/gui/layer/LayerManager.ts @@ -1,27 +1,15 @@ import { Camera, Layers, Node, ResolutionPolicy, SafeArea, Widget, screen, view, warn } from "cc"; +import { resLoader } from "../../common/loader/ResLoader"; import { oops } from "../../Oops"; import { UICallbacks } from "./Defines"; import { DelegateComponent } from "./DelegateComponent"; import { LayerDialog } from "./LayerDialog"; -import { LayerType, LayerTypeCls } from "./LayerEnum"; +import { LayerType, LayerTypeCls, UIConfigMap, Uiid } from "./LayerEnum"; import { LayerNotify } from "./LayerNotify"; import { LayerPopUp } from "./LayerPopup"; import { LayerUI } from "./LayerUI"; import { UIConfig } from "./UIConfig"; -/** 自动生成界面编号最小值 */ -const uiidMin = 1000000; -/** 自动生成界面编号最大值 */ -const uiidMax = 9999999; -var uiid: number = uiidMin; // 当前自动递增界面编号 - -/** 自动获取界面唯一编号 */ -function getUiid(): number { - if (uiid == uiidMax) uiid = uiidMin; - uiid++; - return uiid; -} - /** 界面层级管理器 */ export class LayerManager { /** 界面根节点 */ @@ -43,7 +31,7 @@ export class LayerManager { /** 消息提示控制器,请使用show方法来显示 */ private notify!: LayerNotify; /** UI配置 */ - private configs: { [key: number]: UIConfig } = {}; + private configs: UIConfigMap = {}; /** 界面层集合 - 无自定义类型 */ private uiLayers: Map = new Map(); /** 界面层组件集合 */ @@ -148,7 +136,7 @@ export class LayerManager { * 初始化所有UI的配置对象 * @param configs 配置对象 */ - init(configs: { [key: number]: UIConfig }): void { + init(configs: UIConfigMap): void { this.configs = configs; } @@ -183,16 +171,28 @@ export class LayerManager { this.notify.waitClose(); } - /** - * 设置界面配置 - * @param uiid 要设置的界面id - * @param config 要设置的配置 - */ - setConfig(uiid: number, config: UIConfig): void { - if (config) - this.configs[uiid] = config; - else - delete this.configs[uiid]; + private getInfo(uiid: Uiid): { key: string; config: UIConfig } { + let key = ""; + let config: UIConfig = null!; + + // 确定 key 和 config + if (typeof uiid === 'object') { + if (uiid.bundle == null) uiid.bundle = resLoader.defaultBundleName; + key = uiid.bundle + "_" + uiid.prefab; + config = this.configs[key]; + if (config == null) { + config = uiid; + this.configs[key] = uiid; + } + } + else { + key = uiid.toString(); + config = this.configs[uiid]; + if (config == null) { + console.error(`打开编号为【${uiid}】的界面失败,配置信息不存在`); + } + } + return { key, config }; } /** @@ -211,16 +211,11 @@ export class LayerManager { }; oops.gui.open(UIID.Loading, null, uic); */ - open(uiid: number, uiArgs: any = null, callbacks?: UICallbacks): void { - const config = this.configs[uiid]; - if (config == null) { - warn(`打开编号为【${uiid}】的界面失败,配置信息不存在`); - return; - } - - let layer = this.uiLayers.get(config.layer); + open(uiid: Uiid, uiArgs: any = null, callbacks?: UICallbacks): void { + let info = this.getInfo(uiid); + let layer = this.uiLayers.get(info.config.layer); if (layer) { - layer.add(uiid, config, uiArgs, callbacks); + layer.add(info.key, info.config, uiArgs, callbacks); } else { console.error(`打开编号为【${uiid}】的界面失败,界面层不存在`); @@ -234,7 +229,7 @@ export class LayerManager { * @example * var node = await oops.gui.openAsync(UIID.Loading); */ - async openAsync(uiid: number, uiArgs: any = null): Promise { + async openAsync(uiid: Uiid, uiArgs: any = null): Promise { return new Promise((resolve, reject) => { const callbacks: UICallbacks = { onAdded: (node: Node, params: any) => { @@ -249,18 +244,53 @@ export class LayerManager { } /** - * 通过界面配置打开一个界面 - * @param config 界面配置数据 - * @returns + * 移除指定标识的窗口 + * @param uiid 窗口唯一标识 + * @param isDestroy 移除后是否释放(默认释放内存) + * @example + * oops.gui.remove(UIID.Loading); */ - openAsyncConfig(config: UIConfig): Promise { - return new Promise(async (resolve, reject) => { - let uiid = getUiid(); - config.auto = true; - this.setConfig(uiid, config); - await oops.gui.openAsync(uiid, { uiid: uiid }); - resolve(uiid); - }); + remove(uiid: Uiid, isDestroy: boolean = true) { + let info = this.getInfo(uiid); + let layer = this.uiLayers.get(info.config.layer); + if (layer) { + layer.remove(info.config.prefab, isDestroy); + } + else { + console.error(`移除编号为【${uiid}】的界面失败,界面层不存在`); + } + } + + /** + * 通过界面节点移除 + * @param node 窗口节点 + * @param isDestroy 移除后是否释放资源(默认释放内存) + * @example + * oops.gui.removeByNode(cc.Node); + */ + removeByNode(node: Node, isDestroy: boolean = true) { + if (node instanceof Node) { + let comp = node.getComponent(DelegateComponent); + if (comp && comp.vp) { + // 释放显示的界面 + if (node.parent) { + let uiid = this.configs[comp.vp.uiid]; + this.remove(uiid, isDestroy); + } + // 释放缓存中的界面 + else if (isDestroy) { + let layer = this.uiLayers.get(comp.vp.config.layer); + if (layer) { + // @ts-ignore 注:不对外使用 + layer.removeCache(comp.vp.config.prefab); + } + } + } + else { + warn(`当前删除的 Node 不是通过界面管理器添加的`); + node.destroy(); + } + } } /** @@ -269,14 +299,13 @@ export class LayerManager { * @param openUiId 新打开场景编号 * @param uiArgs 新打开场景参数 */ - replace(removeUiId: number, openUiId: number, uiArgs: any = null) { + replace(removeUiId: Uiid, openUiId: Uiid, uiArgs: any = null) { const callbacks: UICallbacks = { onAdded: (node: Node, params: any) => { this.remove(removeUiId); } }; this.open(openUiId, uiArgs, callbacks); - } /** @@ -285,7 +314,7 @@ export class LayerManager { * @param openUiId 新打开场景编号 * @param uiArgs 新打开场景参数 */ - replaceAsync(removeUiId: number, openUiId: number, uiArgs: any = null): Promise { + replaceAsync(removeUiId: Uiid, openUiId: Uiid, uiArgs: any = null): Promise { return new Promise(async (resolve, reject) => { const node = await this.openAsync(openUiId, uiArgs); if (node) { @@ -304,17 +333,12 @@ export class LayerManager { * @example * oops.gui.has(UIID.Loading); */ - has(uiid: number): boolean { - const config = this.configs[uiid]; - if (config == null) { - warn(`编号为【${uiid}】的界面配置不存在,配置信息不存在`); - return false; - } - - var result = false; - let layer = this.uiLayers.get(config.layer); + has(uiid: Uiid): boolean { + let info = this.getInfo(uiid); + let result = false; + let layer = this.uiLayers.get(info.config.layer); if (layer) { - result = layer.has(config.prefab); + result = layer.has(info.config.prefab); } else { console.error(`验证编号为【${uiid}】的界面失败,界面层不存在`); @@ -329,17 +353,12 @@ export class LayerManager { * @example * oops.gui.has(UIID.Loading); */ - get(uiid: number): Node { - const config = this.configs[uiid]; - if (config == null) { - warn(`编号为【${uiid}】的界面配置不存在,配置信息不存在`); - return null!; - } - + get(uiid: Uiid): Node { + let info = this.getInfo(uiid); let result: Node = null!; - let layer = this.uiLayers.get(config.layer); + let layer = this.uiLayers.get(info.config.layer); if (layer) { - result = layer.get(config.prefab); + result = layer.get(info.config.prefab); } else { console.error(`获取编号为【${uiid}】的界面失败,界面层不存在`); @@ -347,60 +366,6 @@ export class LayerManager { return result; } - /** - * 移除指定标识的窗口 - * @param uiid 窗口唯一标识 - * @param isDestroy 移除后是否释放(默认释放内存) - * @example - * oops.gui.remove(UIID.Loading); - */ - remove(uiid: number, isDestroy: boolean = true) { - const config = this.configs[uiid]; - if (config == null) { - warn(`删除编号为【${uiid}】的界面失败,配置信息不存在`); - return; - } - - let layer = this.uiLayers.get(config.layer); - if (layer) { - layer.remove(config.prefab, isDestroy); - } - else { - console.error(`移除编号为【${uiid}】的界面失败,界面层不存在`); - } - } - - /** - * 通过界面节点移除 - * @param node 窗口节点 - * @param isDestroy 移除后是否释放资源(默认释放内存) - * @example - * oops.gui.removeByNode(cc.Node); - */ - removeByNode(node: Node, isDestroy: boolean = true) { - if (node instanceof Node) { - let comp = node.getComponent(DelegateComponent); - if (comp && comp.vp) { - // 释放显示的界面 - if (node.parent) { - this.remove(comp.vp.uiid, isDestroy); - } - // 释放缓存中的界面 - else if (isDestroy) { - let layer = this.uiLayers.get(comp.vp.config.layer); - if (layer) { - // @ts-ignore 注:不对外使用 - layer.removeCache(comp.vp.config.prefab); - } - } - } - else { - warn(`当前删除的 Node 不是通过界面管理器添加`); - node.destroy(); - } - } - } - /** * 清除所有窗口 * @param isDestroy 移除后是否释放 diff --git a/assets/core/gui/layer/LayerUI.ts b/assets/core/gui/layer/LayerUI.ts index 52c2ccf..926fc09 100644 --- a/assets/core/gui/layer/LayerUI.ts +++ b/assets/core/gui/layer/LayerUI.ts @@ -3,6 +3,7 @@ import { Collection } from "db://oops-framework/libs/collection/Collection"; import { oops } from "../../Oops"; import { UICallbacks, ViewParams } from "./Defines"; import { DelegateComponent } from "./DelegateComponent"; +import { Uiid } from "./LayerEnum"; import { UIConfig } from "./UIConfig"; /** 界面层对象 */ @@ -35,7 +36,7 @@ export class LayerUI extends Node { * @param callbacks 回调函数对象,可选 * @returns ture为成功,false为失败 */ - add(uiid: number, config: UIConfig, params?: any, callbacks?: UICallbacks) { + add(uiid: Uiid, config: UIConfig, params?: any, callbacks?: UICallbacks) { if (this.ui_nodes.has(config.prefab)) { console.warn(`路径为【${config.prefab}】的预制重复加载`); return; @@ -45,7 +46,7 @@ export class LayerUI extends Node { let vp = this.ui_cache.get(config.prefab); if (vp == null) { vp = new ViewParams(); - vp.uiid = uiid; + vp.uiid = uiid.toString(); vp.config = config; } this.ui_nodes.set(config.prefab, vp); diff --git a/assets/core/gui/layer/UIConfig.ts b/assets/core/gui/layer/UIConfig.ts index 50ee756..b66f4cd 100644 --- a/assets/core/gui/layer/UIConfig.ts +++ b/assets/core/gui/layer/UIConfig.ts @@ -10,16 +10,19 @@ export enum UIID { Netinstable } -// 打开界面方式的配置数据 +// 打开界面方式1 export var UIConfigData: { [key: number]: UIConfig } = { [UIID.Loading]: { layer: LayerType.UI, prefab: "loading/prefab/loading", bundle: "resources" }, [UIID.Netinstable]: { layer: LayerType.PopUp, prefab: "common/prefab/netinstable" }, [UIID.Window]: { layer: LayerType.Dialog, prefab: "common/prefab/window" } } + +// 打开界面方式2 +export class InitializeUIConfig { + static Loading = { layer: LayerType.UI, prefab: "gui/loading/loading" } +} */ export interface UIConfig { - /** 是否为自动生成的界面编号 */ - auto?: boolean, /** -----公共属性----- */ /** 远程包名 */ bundle?: string; diff --git a/assets/module/common/ModuleUtil.ts b/assets/module/common/ModuleUtil.ts index 3ec7dae..ac3bfdf 100644 --- a/assets/module/common/ModuleUtil.ts +++ b/assets/module/common/ModuleUtil.ts @@ -3,6 +3,8 @@ import { oops } from "../../core/Oops"; import { resLoader } from "../../core/common/loader/ResLoader"; import { UICallbacks } from "../../core/gui/layer/Defines"; import { DelegateComponent } from "../../core/gui/layer/DelegateComponent"; +import { Uiid } from "../../core/gui/layer/LayerEnum"; +import { UIConfig } from "../../core/gui/layer/UIConfig"; import { ViewUtil } from "../../core/utils/ViewUtil"; import { ecs } from "../../libs/ecs/ECS"; import { CompType } from "../../libs/ecs/ECSModel"; @@ -43,7 +45,7 @@ export class ModuleUtil { static addViewUiAsync( ent: ecs.Entity, ctor: __private.__types_globals__Constructor | __private.__types_globals__AbstractedConstructor, - uiId: number, + uiId: number | UIConfig, uiArgs: any = null): Promise { return new Promise((resolve, reject) => { const uic: UICallbacks = { @@ -88,7 +90,7 @@ export class ModuleUtil { * @param isDestroy 是否释放界面缓存(默认为释放界面缓存) * @param onRemoved 窗口关闭完成事件 */ - static removeViewUi(ent: ecs.Entity, ctor: CompType, uiId: number, isDestroy: boolean = true, onRemoved?: Function) { + static removeViewUi(ent: ecs.Entity, ctor: CompType, uiId: Uiid, isDestroy: boolean = true, onRemoved?: Function) { const node = oops.gui.get(uiId); if (!node) { if (onRemoved) onRemoved(); -- Gitee From 297421dbec93fb48c95b8a3cb7204c9e510408de Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 26 Jul 2025 21:25:45 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E5=BA=9F=E5=BC=83List=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/collection/List.ts | 155 --------------------------------- 1 file changed, 155 deletions(-) delete mode 100644 assets/libs/collection/List.ts diff --git a/assets/libs/collection/List.ts b/assets/libs/collection/List.ts deleted file mode 100644 index f1e6ba6..0000000 --- a/assets/libs/collection/List.ts +++ /dev/null @@ -1,155 +0,0 @@ -/** 列表 */ -export class List { - private element: Array; - - /** 是否保证元素的唯一性 */ - private only: boolean = false; - - /** 元素数量(内部再增删时会修改这个参数,外部只做计算和绑定使用,切记不可做赋值操作) */ - count: number = 0; - - constructor(only: boolean = true) { - this.only = only; - this.element = []; - } - - /** - * 添加到末尾(注意如果保证唯一性,那么重复时就直接返回) - * @param value - */ - push(value: T): boolean { - if (this.only) { - let index: number = this.element.indexOf(value); - if (index >= 0) { - return false; - } - } - this.element.push(value); - this.count = this.element.length; - return true; - } - - /** - * 添加到列表头部(注意如果保证唯一性,那么重复时就直接返回) - * @param value - * @returns - */ - unshift(value: T): boolean { - if (this.only) { - let index: number = this.element.indexOf(value); - if (index >= 0) { - return false; - } - } - this.element.unshift(value); - this.count = this.element.length; - return true; - } - - /** - * 获取并删除最后一个元素 - * @returns - */ - pop(): T { - if (this.element.length > 0) { - const result = this.element.pop(); - this.count = this.element.length; - return result!; - } - return null!; - } - - /** - * 获取并删除第一个元素 - * @returns - */ - shift(): T { - if (this.element.length > 0) { - const result = this.element.shift(); - this.count = this.element.length; - return result!; - } - return null!; - } - - /** - * 删除指定索引的元素 - * @param index - */ - removeAt(index: number): T { - if (index >= this.element.length) { - throw new Error("删除索引超出范围!"); - } - const result = this.element[index]; - this.element.splice(index, 1); - this.count = this.element.length; - return result; - } - - /** - * 删除元素 - * @param value - */ - remove(value: T): void { - let index: number = this.element.indexOf(value); - if (index < 0) { - throw new Error("要删除的内容不在列表中!" + value); - } - const result = this.element[index]; - this.element.splice(index, 1); - this.count = this.element.length; - } - - /** 移除所有元素 */ - clear(): void { - this.count = 0; - this.element.length = 0; - } - - /** - * 判断是否包含 - * @param value - * @returns - */ - has(value: T): boolean { - return this.find(value) >= 0; - } - - /** - * 查找元素下标 - * @param value - * @returns - */ - find(value: T): number { - return this.element.indexOf(value); - } - - /** - * 查找元素下标 - * @param predicate - * @returns - */ - findIndex(predicate: (value: T, index: number, obj: T[]) => unknown): number { - let index = this.element.findIndex(predicate); - return index; - } - - /** - * 获取指定元素 - * @param index - * @returns - */ - get(index: number): T { - if (index >= this.element.length) { - throw new Error("超出索引范围:" + index + "/" + this.element.length); - } - return this.element[index]; - } - - /** - * 源列表数据(注意不要直接进行增删操作,而是通过List.push....等接口进行操作) - */ - get elements(): Array { - return this.element; - } -} \ No newline at end of file -- Gitee From e2f4bb3d683576e0fd4a2cb7bd33e468956de5cf Mon Sep 17 00:00:00 2001 From: wxh <1053066913@qq.com> Date: Sun, 27 Jul 2025 16:37:35 +0800 Subject: [PATCH 07/16] =?UTF-8?q?Add:=20ArrayUtil=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=BF=9E=E7=BB=AD=E6=95=B0=E5=AD=97=E6=95=B0=E7=BB=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/utils/ArrayUtil.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/assets/core/utils/ArrayUtil.ts b/assets/core/utils/ArrayUtil.ts index 6add054..1d7eb75 100644 --- a/assets/core/utils/ArrayUtil.ts +++ b/assets/core/utils/ArrayUtil.ts @@ -103,4 +103,14 @@ export class ArrayUtil { static getRandomValueInArray(array: any[]): any { return array[Math.floor(Math.random() * array.length)]; } + + /** + * 获取连续数字数组, 范围在[start, end]之间 + * @param start 开始数字 + * @param end 结束数字 + * @example getNumsBetween(1, 10) => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + */ + static getNumsBetween(start: number, end: number): number[] { + return Array.from({ length: end - start + 1 }, (_, i) => start + i); + } } -- Gitee From c857db03869c09748c69b85b6f97a172923bbc80 Mon Sep 17 00:00:00 2001 From: dgflash Date: Thu, 31 Jul 2025 09:49:05 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E9=9F=B3=E4=B9=90=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8F=AF=E6=89=A9=E5=B1=95=E7=9A=84=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/common/audio/AudioEffectPool.ts | 68 +++++---- assets/core/common/audio/AudioManager.ts | 147 +++----------------- assets/core/common/audio/AudioMusic.ts | 84 +++++++---- assets/core/common/audio/IAudio.ts | 10 ++ assets/core/common/audio/IAudio.ts.meta | 9 ++ assets/module/common/GameComponent.ts | 54 +++---- 6 files changed, 164 insertions(+), 208 deletions(-) create mode 100644 assets/core/common/audio/IAudio.ts create mode 100644 assets/core/common/audio/IAudio.ts.meta diff --git a/assets/core/common/audio/AudioEffectPool.ts b/assets/core/common/audio/AudioEffectPool.ts index 5c740e7..34e1a32 100644 --- a/assets/core/common/audio/AudioEffectPool.ts +++ b/assets/core/common/audio/AudioEffectPool.ts @@ -2,6 +2,7 @@ import { AudioClip, Node, NodePool } from "cc"; import { oops } from "../../Oops"; import { resLoader } from "../loader/ResLoader"; import { AudioEffect } from "./AudioEffect"; +import { IAudioParams } from "./IAudio"; const AE_ID_MAX = 30000; @@ -9,10 +10,10 @@ const AE_ID_MAX = 30000; export class AudioEffectPool { private _switch: boolean = true; /** 音效开关 */ - public get switch(): boolean { + get switch(): boolean { return this._switch; } - public set switch(value: boolean) { + set switch(value: boolean) { this._switch = value; if (value) this.stop(); } @@ -52,10 +53,21 @@ export class AudioEffectPool { * @param onPlayComplete 播放完成回调 * @returns */ - async load(url: string | AudioClip, bundleName: string = resLoader.defaultBundleName, onPlayComplete?: Function): Promise { + async loadAndPlay(url: string | AudioClip, params?: IAudioParams): Promise { return new Promise(async (resolve, reject) => { if (!this.switch) return resolve(-1); + let bundleName = resLoader.defaultBundleName; + let loop = false; + let volume = this.volume; + let onPlayComplete: Function = null!; + if (params) { + if (params.bundle != null) bundleName = params.bundle; + if (params.loop != null) loop = params.loop; + if (params.volume != null) volume = params.volume; + if (params.onPlayComplete != null) onPlayComplete = params.onPlayComplete; + } + // 创建音效资源 let clip: AudioClip; if (url instanceof AudioClip) { @@ -63,6 +75,8 @@ export class AudioEffectPool { } else { clip = resLoader.get(url, AudioClip, bundleName)!; + + // 加载音效资源 if (clip == null) { let urls = this.res.get(bundleName); if (urls == null) { @@ -101,22 +115,24 @@ export class AudioEffectPool { node.name = "AudioEffect"; node.parent = oops.audio.node; ae = node.addComponent(AudioEffect)!; + ae.onComplete = () => { + this.put(aeid, url, bundleName); // 播放完回收对象 + onPlayComplete && onPlayComplete(aeid, url, bundleName); + // console.log(`【音效】回收,池中剩余音效播放器【${this.pool.size()}】`); + }; } else { node = this.pool.get()!; ae = node.getComponent(AudioEffect)!; } - ae.onComplete = () => { - this.put(aeid, url, bundleName); // 播放完回收对象 - onPlayComplete && onPlayComplete(); - // console.log(`【音效】回收,池中剩余音效播放器【${this.pool.size()}】`); - }; // 记录正在播放的音效播放器 this.effects.set(key, ae); - ae.volume = this.volume; + ae.loop = loop; ae.clip = clip; + ae.volume = volume; + ae.currentTime = 0; ae.play(); resolve(aeid); @@ -147,23 +163,6 @@ export class AudioEffectPool { } } - /** 释放所有音效资源与对象池中播放器 */ - release() { - // 释放正在播放的音效 - this.effects.forEach(ae => { - ae.node.destroy(); - }); - this.effects.clear(); - - // 释放音效资源 - this.res.forEach((urls: string[], bundleName: string) => { - urls.forEach(url => resLoader.release(url, bundleName)); - }); - - // 释放池中播放器 - this.pool.clear(); - } - /** 停止播放所有音效 */ stop() { this.effects.forEach(ae => { @@ -188,4 +187,21 @@ export class AudioEffectPool { ae.pause(); }); } + + /** 释放所有音效资源与对象池中播放器 */ + release() { + // 释放正在播放的音效 + this.effects.forEach(ae => { + ae.node.destroy(); + }); + this.effects.clear(); + + // 释放音效资源 + this.res.forEach((urls: string[], bundleName: string) => { + urls.forEach(url => resLoader.release(url, bundleName)); + }); + + // 释放池中播放器 + this.pool.clear(); + } } \ No newline at end of file diff --git a/assets/core/common/audio/AudioManager.ts b/assets/core/common/audio/AudioManager.ts index 670fa3c..3eee464 100644 --- a/assets/core/common/audio/AudioManager.ts +++ b/assets/core/common/audio/AudioManager.ts @@ -2,6 +2,7 @@ import { AudioClip, Component } from "cc"; import { oops } from "../../Oops"; import { AudioEffectPool } from "./AudioEffectPool"; import { AudioMusic } from "./AudioMusic"; +import { IAudioParams } from "./IAudio"; const LOCAL_STORE_KEY = "game_audio"; @@ -19,100 +20,15 @@ export class AudioManager extends Component { effect: AudioEffectPool = new AudioEffectPool(); /** 音乐管理状态数据 */ - private local_data: any = {}; - - /** - * 设置背景音乐播放完成回调 - * @param callback 背景音乐播放完成回调 - */ - setMusicComplete(callback: Function | null = null) { - this.music.onComplete = callback; - } - - /** - * 播放背景音乐 - * @param url 资源地址 - * @param callback 音乐播放完成事件 - * @param bundleName 资源包名 - */ - playMusic(url: string, callback?: Function, bundleName?: string) { - if (this.music.switch) { - this.music.loop = false; - this.music.load(url, callback, bundleName).then(); - } - } - - /** 循环播放背景音乐 */ - playMusicLoop(url: string, bundleName?: string) { - if (this.music.switch) { - this.music.loop = true; - this.music.load(url, null!, bundleName).then(); - } - } - - /** 停止背景音乐播放 */ - stopMusic() { - if (this.music.switch && this.music.playing) { - this.music.stop(); - } - } - - /** - * 获取背景音乐播放进度 - */ - get progressMusic(): number { - return this.music.progress; - } - - /** - * 设置背景乐播放进度 - * @param value 播放进度值 - */ - set progressMusic(value: number) { - this.music.progress = value; - } - - /** - * 获取背景音乐音量 - */ - get volumeMusic(): number { - return this.music.volume; - } - - /** - * 设置背景音乐音量 - * @param value 音乐音量值 - */ - set volumeMusic(value: number) { - this.music.volume = value; - this.save(); - } - - /** - * 获取背景音乐开关值 - */ - get switchMusic(): boolean { - return this.music.switch; - } - - /** - * 设置背景音乐开关值 - * @param value 开关值 - */ - set switchMusic(value: boolean) { - this.music.switch = value; - if (!value) this.music.stop(); - this.save(); - } + private localData: any = {}; /** * 播放音效 * @param url 资源地址 - * @param callback 加载完成回调 - * @param bundleName 资源包名 + * @param params 音效参数 */ - playEffect(url: string | AudioClip, bundleName?: string, onPlayComplete?: Function): Promise { - return this.effect.load(url, bundleName, onPlayComplete); + playEffect(url: string | AudioClip, params?: IAudioParams): Promise { + return this.effect.loadAndPlay(url, params); } /** 回收音效播放器 */ @@ -120,35 +36,6 @@ export class AudioManager extends Component { this.effect.put(aeid, url, bundleName); } - /** 获取音效音量 */ - get volumeEffect(): number { - return this.effect.volume; - } - - /** - * 设置获取音效音量 - * @param value 音效音量值 - */ - set volumeEffect(value: number) { - this.effect.volume = value; - this.save(); - } - - /** 获取音效开关值 */ - get switchEffect(): boolean { - return this.effect.switch; - } - - /** - * 设置音效开关值 - * @param value 音效开关值 - */ - set switchEffect(value: boolean) { - this.effect.switch = value; - if (!value) this.effect.stop(); - this.save(); - } - /** 恢复当前暂停的音乐与音效播放 */ resumeAll() { if (!this.music.playing && this.music.progress > 0) this.music.play(); @@ -169,20 +56,20 @@ export class AudioManager extends Component { /** 保存音乐音效的音量、开关配置数据到本地 */ save() { - this.local_data.volume_music = this.music.volume; - this.local_data.volume_effect = this.effect.volume; - this.local_data.switch_music = this.music.switch; - this.local_data.switch_effect = this.effect.switch; + this.localData.volume_music = this.music.volume; + this.localData.volume_effect = this.effect.volume; + this.localData.switch_music = this.music.switch; + this.localData.switch_effect = this.effect.switch; - oops.storage.set(LOCAL_STORE_KEY, this.local_data); + oops.storage.set(LOCAL_STORE_KEY, this.localData); } /** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */ load() { this.music = this.getComponent(AudioMusic) || this.addComponent(AudioMusic)!; - this.local_data = oops.storage.getJson(LOCAL_STORE_KEY); - if (this.local_data) { + this.localData = oops.storage.getJson(LOCAL_STORE_KEY); + if (this.localData) { try { this.setState(); } @@ -196,14 +83,14 @@ export class AudioManager extends Component { } private setState() { - this.music.volume = this.local_data.volume_music; - this.effect.volume = this.local_data.volume_effect; - this.music.switch = this.local_data.switch_music; - this.effect.switch = this.local_data.switch_effect; + this.music.volume = this.localData.volume_music; + this.effect.volume = this.localData.volume_effect; + this.music.switch = this.localData.switch_music; + this.effect.switch = this.localData.switch_effect; } private setStateDefault() { - this.local_data = {}; + this.localData = {}; this.music.volume = 1; this.effect.volume = 1; this.music.switch = true; diff --git a/assets/core/common/audio/AudioMusic.ts b/assets/core/common/audio/AudioMusic.ts index 8b1b395..0f30441 100644 --- a/assets/core/common/audio/AudioMusic.ts +++ b/assets/core/common/audio/AudioMusic.ts @@ -6,8 +6,9 @@ */ import { AudioClip, AudioSource, _decorator } from 'cc'; import { resLoader } from '../loader/ResLoader'; +import { IAudioParams } from './IAudio'; -const { ccclass, menu } = _decorator; +const { ccclass } = _decorator; /** * 背景音乐 @@ -15,25 +16,20 @@ const { ccclass, menu } = _decorator; */ @ccclass('AudioMusic') export class AudioMusic extends AudioSource { - /** 背景音乐开关 */ - switch: boolean = true; - /** 背景音乐播放完成回调 */ - onComplete: Function | null = null; - private _progress: number = 0; private _isLoading: boolean = false; - private _nextBundleName: string = null!; // 下一个音乐资源包 - private _nextUrl: string = null!; // 下一个播放音乐 + private _nextUrl: string = null!; + private _nextParams: IAudioParams = null!; + private _params: IAudioParams = null!; - start() { - // this.node.on(AudioSource.EventType.STARTED, this.onAudioStarted, this); - this.node.on(AudioSource.EventType.ENDED, this.onAudioEnded, this); + /** 背景音乐开关 */ + private _switch: boolean = true; + get switch(): boolean { + return this._switch; } - - // private onAudioStarted() { } - - private onAudioEnded() { - this.onComplete && this.onComplete(); + set switch(value: boolean) { + this._switch = value; + if (!value) this.stop(); } /** 获取音乐播放进度 */ @@ -51,34 +47,59 @@ export class AudioMusic extends AudioSource { this.currentTime = value * this.duration; } + start() { + // this.node.on(AudioSource.EventType.STARTED, this.onAudioStarted, this); + this.node.on(AudioSource.EventType.ENDED, this.onAudioEnded, this); + } + + // private onAudioStarted() { } + + private onAudioEnded() { + if (this._params && this._params.onPlayComplete) { + this._params.onPlayComplete(); + } + } + /** * 加载音乐并播放 * @param url 音乐资源地址 - * @param callback 加载完成回调 - * @param bundleName 资源包名 + * @param params 背景音乐资源播放参数 */ - async load(url: string, callback?: Function, bundleName: string = resLoader.defaultBundleName) { + async loadAndPlay(url: string, params?: IAudioParams) { + if (!this.switch) return; // 禁止播放音乐 + // 下一个加载的背景音乐资源 if (this._isLoading) { - this._nextBundleName = bundleName; this._nextUrl = url; + this._nextParams = params!; return; } + let bundleName = resLoader.defaultBundleName; + let loop = false; + let volume = this.volume; + let onPlayComplete: Function = null!; + if (params) { + this._params = params! + if (params.bundle != null) bundleName = params.bundle; + if (params.loop != null) loop = params.loop; + if (params.volume != null) volume = params.volume; + if (params.onPlayComplete != null) onPlayComplete = params.onPlayComplete; + }; + this._isLoading = true; - var data: AudioClip = await resLoader.loadAsync(bundleName, url, AudioClip); - if (data) { + var clip: AudioClip = await resLoader.loadAsync(bundleName, url, AudioClip); + if (clip) { this._isLoading = false; // 处理等待加载的背景音乐 if (this._nextUrl != null) { // 加载等待播放的背景音乐 - this.load(this._nextUrl, callback, this._nextBundleName); - this._nextBundleName = this._nextUrl = null!; + this.loadAndPlay(this._nextUrl, this._nextParams); + this._nextUrl = null!; + this._nextParams = null!; } else { - callback && callback(); - // 正在播放的时候先关闭 if (this.playing) { this.stop(); @@ -88,12 +109,21 @@ export class AudioMusic extends AudioSource { this.release(); // 播放背景音乐 - this.clip = data; + this.clip = clip; + this.loop = loop; + this.volume = volume; + this.currentTime = 0; this.play(); } } } + stop(): void { + if (this.switch && this.playing) { + super.stop(); + } + } + /** 释放当前背景音乐资源 */ release() { if (this.clip) { diff --git a/assets/core/common/audio/IAudio.ts b/assets/core/common/audio/IAudio.ts new file mode 100644 index 0000000..68b5ecf --- /dev/null +++ b/assets/core/common/audio/IAudio.ts @@ -0,0 +1,10 @@ +export interface IAudioParams { + /** 资源包名 */ + bundle?: string, + /** 是否循环播放 */ + loop?: boolean; + /** 音效音量 */ + volume?: number; + /** 播放完成事件 */ + onPlayComplete?: Function; +} \ No newline at end of file diff --git a/assets/core/common/audio/IAudio.ts.meta b/assets/core/common/audio/IAudio.ts.meta new file mode 100644 index 0000000..158a088 --- /dev/null +++ b/assets/core/common/audio/IAudio.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "82ec630f-ea0b-4e37-a671-1b4555a756db", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/module/common/GameComponent.ts b/assets/module/common/GameComponent.ts index 68f02c5..4a0e35e 100644 --- a/assets/module/common/GameComponent.ts +++ b/assets/module/common/GameComponent.ts @@ -6,6 +6,7 @@ */ import { Asset, Button, Component, EventHandler, EventKeyboard, EventTouch, Input, Node, Prefab, Sprite, SpriteFrame, __private, _decorator, input, isValid } from "cc"; import { oops } from "../../core/Oops"; +import { IAudioParams } from "../../core/common/audio/IAudio"; import { EventDispatcher } from "../../core/common/event/EventDispatcher"; import { EventMessage, ListenerFunc } from "../../core/common/event/EventMessage"; import { AssetType, CompleteCallback, Paths, ProgressCallback, resLoader } from "../../core/common/loader/ResLoader"; @@ -339,41 +340,44 @@ export class GameComponent extends Component { /** * 播放背景音乐(不受自动释放资源管理) * @param url 资源地址 - * @param callback 资源加载完成回调 - * @param bundleName 资源包名 + * @param params 背景音乐资源播放参数 */ - playMusic(url: string, callback?: Function, bundleName?: string) { - oops.audio.playMusic(url, callback, bundleName); - } - - /** - * 循环播放背景音乐(不受自动释放资源管理) - * @param url 资源地址 - * @param bundleName 资源包名 - */ - playMusicLoop(url: string, bundleName?: string) { - oops.audio.stopMusic(); - oops.audio.playMusicLoop(url, bundleName); + playMusic(url: string, params?: IAudioParams) { + oops.audio.music.loadAndPlay(url, params); } /** * 播放音效 * @param url 资源地址 - * @param callback 资源加载完成回调 - * @param bundleName 资源包名 + * @param params 音效播放参数 */ - async playEffect(url: string, bundleName?: string) { - if (bundleName == null) bundleName = oops.res.defaultBundleName; - let resId = await oops.audio.playEffect(url, bundleName, () => { - if (!this.isValid) return; + async playEffect(url: string, params?: IAudioParams): Promise { + return new Promise(async (resolve, reject) => { + let bundleName = resLoader.defaultBundleName; + if (params == null) { + params = { bundle: bundleName } + } + else if (params.bundle != null) { + bundleName = params.bundle; + } - const rps = this.resPaths.get(ResType.Audio); - if (rps) { - const key = this.getResKey(bundleName, url); - rps.delete(key); + // 音效播放完,关闭正在播放状态的音乐效果 + params.onPlayComplete = (aeid: number, url: string, bundleName: string) => { + // 音效播放完前,界面被释放 + if (!this.isValid) return; + + // 删除界面音效的播放记录 + const rps = this.resPaths.get(ResType.Audio); + if (rps) { + const key = this.getResKey(bundleName, url, aeid); + rps.delete(key); + } } + + let resId = await oops.audio.playEffect(url, params); + this.addPathToRecord(ResType.Audio, bundleName, url, resId); // 支持界面释放时,立即停止所有音效的播放 + resolve(resId); }); - this.addPathToRecord(ResType.Audio, bundleName, url, resId); } //#endregion -- Gitee From 6d9a8f40502e630468c5e72e0c8e5bfea0174bc6 Mon Sep 17 00:00:00 2001 From: dgflash Date: Thu, 14 Aug 2025 09:16:09 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A1=A5=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/GuiEnum.ts | 1 + assets/core/gui/layer/Defines.ts | 1 - assets/core/gui/layer/LayerDialog.ts | 10 +++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/assets/core/gui/GuiEnum.ts b/assets/core/gui/GuiEnum.ts index c9a3a19..45ef620 100644 --- a/assets/core/gui/GuiEnum.ts +++ b/assets/core/gui/GuiEnum.ts @@ -1,3 +1,4 @@ +/** 框架提示资源路径 */ export enum PromptResType { /** 飘动提示 */ Toast = 'common/prefab/notify', diff --git a/assets/core/gui/layer/Defines.ts b/assets/core/gui/layer/Defines.ts index 18e6235..4cddfe9 100644 --- a/assets/core/gui/layer/Defines.ts +++ b/assets/core/gui/layer/Defines.ts @@ -5,7 +5,6 @@ * @LastEditTime: 2023-01-09 11:52:38 */ import { Node } from "cc"; -import { Uiid } from "./LayerEnum"; import { UIConfig } from "./UIConfig"; /*** 界面回调参数对象定义 */ diff --git a/assets/core/gui/layer/LayerDialog.ts b/assets/core/gui/layer/LayerDialog.ts index 864143f..68b2965 100644 --- a/assets/core/gui/layer/LayerDialog.ts +++ b/assets/core/gui/layer/LayerDialog.ts @@ -11,9 +11,13 @@ import { UIConfig } from "./UIConfig"; /** 模式弹窗数据 */ type DialogParam = { - uiid: number; + /** 弹窗唯一编号 */ + uiid: string; + /** 窗口配置 */ config: UIConfig; + /** 窗口附加参数 */ params?: any; + /** 窗口回调 */ callbacks?: UICallbacks; } @@ -24,7 +28,7 @@ export class LayerDialog extends LayerPopUp { /** 窗口调用参数队列 */ private params: Array = []; - add(uiid: number, config: UIConfig, params?: any, callbacks?: UICallbacks) { + add(uiid: string, config: UIConfig, params?: any, callbacks?: UICallbacks) { // 控制同一时间只能显示一个模式窗口 if (this.ui_nodes.size > 0) { this.params.push({ @@ -40,7 +44,7 @@ export class LayerDialog extends LayerPopUp { } /** 显示模式弹窗 */ - private show(uiid: number, config: UIConfig, params?: any, callbacks?: UICallbacks) { + private show(uiid: string, config: UIConfig, params?: any, callbacks?: UICallbacks) { let vp = this.ui_cache.get(config.prefab); if (vp == null) { vp = new ViewParams(); -- Gitee From 921441191694c82f9a474d46defdc3db81d56c2b Mon Sep 17 00:00:00 2001 From: dgflash Date: Thu, 14 Aug 2025 14:41:49 +0800 Subject: [PATCH 10/16] =?UTF-8?q?1.=E4=BC=98=E5=8C=96MVVM=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E4=BB=A3=E7=A0=81=202.MVVM=E7=BB=84=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=84=9A=E6=9C=AC=E7=BB=91=E5=AE=9A=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=203.VMLabel=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/extension/DateExt.ts | 15 +- assets/libs/model-view/StringFormat.ts | 74 +- assets/libs/model-view/VMCompsEdit.ts | 26 +- assets/libs/model-view/VMCustom.ts | 3 +- assets/libs/model-view/VMEnv.ts | 3 +- assets/libs/model-view/VMEvent.ts | 6 +- assets/libs/model-view/VMLabel.ts | 2 +- assets/libs/model-view/VMModify.ts | 2 +- assets/libs/model-view/VMParent.ts | 6 +- assets/libs/model-view/VMProgress.ts | 2 +- assets/libs/model-view/VMState.ts | 2 +- assets/libs/model-view/ViewModel.ts | 9 +- assets/libs/model-view/ui/BhvRollNumber.ts | 4 +- assets/libs/model-view/ui/BhvSwitchPage.ts | 14 +- assets/libs/network.meta | 9 + assets/libs/network/.network.md | 3 + assets/libs/network/HttpRequest.ts | 317 ++ assets/libs/network/HttpRequest.ts.meta | 9 + assets/libs/network/NetInterface.ts | 92 + assets/libs/network/NetInterface.ts.meta | 11 + assets/libs/network/NetManager.ts | 148 + assets/libs/network/NetManager.ts.meta | 11 + assets/libs/network/NetNode.ts | 491 +++ assets/libs/network/NetNode.ts.meta | 11 + assets/libs/network/NetProtocolPako.ts | 69 + assets/libs/network/NetProtocolPako.ts.meta | 9 + assets/libs/network/WebSock.ts | 84 + assets/libs/network/WebSock.ts.meta | 11 + assets/libs/network/protocol.meta | 12 + assets/libs/network/protocol/pako.min.js | 3424 +++++++++++++++++ assets/libs/network/protocol/pako.min.js.meta | 17 + 31 files changed, 4818 insertions(+), 78 deletions(-) create mode 100644 assets/libs/network.meta create mode 100644 assets/libs/network/.network.md create mode 100644 assets/libs/network/HttpRequest.ts create mode 100644 assets/libs/network/HttpRequest.ts.meta create mode 100644 assets/libs/network/NetInterface.ts create mode 100644 assets/libs/network/NetInterface.ts.meta create mode 100644 assets/libs/network/NetManager.ts create mode 100644 assets/libs/network/NetManager.ts.meta create mode 100644 assets/libs/network/NetNode.ts create mode 100644 assets/libs/network/NetNode.ts.meta create mode 100644 assets/libs/network/NetProtocolPako.ts create mode 100644 assets/libs/network/NetProtocolPako.ts.meta create mode 100644 assets/libs/network/WebSock.ts create mode 100644 assets/libs/network/WebSock.ts.meta create mode 100644 assets/libs/network/protocol.meta create mode 100644 assets/libs/network/protocol/pako.min.js create mode 100644 assets/libs/network/protocol/pako.min.js.meta diff --git a/assets/libs/extension/DateExt.ts b/assets/libs/extension/DateExt.ts index 466ba7c..4120fec 100644 --- a/assets/libs/extension/DateExt.ts +++ b/assets/libs/extension/DateExt.ts @@ -12,14 +12,27 @@ Date.prototype.format = function (format: string): string { const hours: number = this.getHours(); const minutes: number = this.getMinutes(); const seconds: number = this.getSeconds(); + const milliseconds: number = this.getMilliseconds(); - return format + let r = format .replace('yy', year.toString()) .replace('mm', (month < 10 ? '0' : '') + month) .replace('dd', (day < 10 ? '0' : '') + day) .replace('hh', (hours < 10 ? '0' : '') + hours) .replace('mm', (minutes < 10 ? '0' : '') + minutes) .replace('ss', (seconds < 10 ? '0' : '') + seconds); + + if (milliseconds < 10) { + r = r.replace('ms', '00' + milliseconds); + } + else if (milliseconds < 100) { + r = r.replace('ms', '0' + milliseconds); + } + else { + r = r.replace('ms', milliseconds.toString()); + } + + return r; }; export { }; diff --git a/assets/libs/model-view/StringFormat.ts b/assets/libs/model-view/StringFormat.ts index aa31c5a..4e99922 100644 --- a/assets/libs/model-view/StringFormat.ts +++ b/assets/libs/model-view/StringFormat.ts @@ -1,8 +1,6 @@ -/** - * 数值格式化函数, 通过语义解析自动设置值的范围 - * //整数 - * 1:def(0)//显示一个默认值 - */ +import { oops } from "../../core/Oops"; + +/** 数值格式化函数, 通过语义解析自动设置值的范围 */ class StringFormat { deal(value: number | string, format: string): string { if (format === '') return value as string; @@ -21,58 +19,58 @@ class StringFormat { switch (func) { case 'int': res = this.int(value); break; case 'fix': res = this.fix(value, num); break; - case 'kmbt': res = this.KMBT(value); break; + case 'kmbt': res = this.kmbt(value); break; case 'per': res = this.per(value, num); break; case 'sep': res = this.sep(value); break; - default: - break; - } + case 'tstamp': res = this.time_stamp(value); break; + case 'tm': res = this.time_m(value); break; + case 'ts': res = this.time_s(value); break; + case 'tms': res = this.time_ms(value); break; + default: break; + } } else { switch (func) { case 'limit': res = this.limit(value, num); break; - - default: - break; + default: res = value; break; } - res = value; } return res as string; } - // 将数字按分号显示 + /** 将数字按分号显示 */ private sep(value: number) { let num = Math.round(value).toString(); return num.replace(new RegExp('(\\d)(?=(\\d{3})+$)', 'ig'), "$1,"); } - // 将数字按分显示 00:00 显示 (ms制) + /** 将数字按分显示 00:00 显示 (时:分) */ private time_m(value: number) { - //todo + return new Date(value).format('hh:ss'); } - // 将数字按秒显示 00:00:00 显示 (ms制) + /** 将数字按秒显示 00:00:00 显示 (时:分:秒) */ private time_s(value: number) { - //todo + return new Date(value).format('hh:mm:ss'); } - // 将数字按 0:00:00:000 显示 (ms制) + /** 将数字按 0:00:00:000 显示 (时:分:秒:毫秒) */ private time_ms(value: number) { - //todo + return new Date(value).format('hh:mm:ss:ms'); } - // 将时间戳显示为详细的内容 - private timeStamp(value: number) { - //todo - return new Date(value).toString() + /** 将时间戳显示为详细的内容 */ + private time_stamp(value: number) { + return new Date(value).format('yy-mm-dd hh:mm:ss'); } /** [value:int] 将取值0~1 变成 1~100,可以指定修饰的小数位数 */ private per(value: number, fd: number) { - return Math.round(value * 100).toFixed(fd); + let r = value * 100; + return r.toFixed(fd); } /** [value:int] 将取值变成整数 */ @@ -80,7 +78,7 @@ class StringFormat { return Math.round(value); } - /** [value:fix2]数值转换为小数*/ + /** [value:fix2]数值转换为小数 */ private fix(value: number, fd: number) { return value.toFixed(fd) } @@ -91,18 +89,21 @@ class StringFormat { } /** 将数字缩短显示为KMBT单位 大写,目前只支持英文 */ - private KMBT(value: number, lang: string = 'en') { + private kmbt(value: number) { //10^4=万, 10^8=亿,10^12=兆,10^16=京, - let counts = [1000, 1000000, 1000000000, 1000000000000]; - let units = ['', 'K', 'M', 'B', 'T']; + let counts: number[] = null!; + let units: string[] = null!; - switch (lang) { + switch (oops.language.current) { case 'zh': //10^4=万, 10^8=亿,10^12=兆,10^16=京, - let counts = [10000, 100000000, 1000000000000, 10000000000000000]; - let units = ['', '万', '亿', '兆', '京']; + counts = [10000, 100000000, 1000000000000, 10000000000000000]; + units = ['', '万', '亿', '兆', '京']; + break; + case 'en': + counts = [1000, 1000000, 1000000000, 1000000000000]; + units = ['', 'K', 'M', 'B', 'T']; break; - default: break; } @@ -110,12 +111,12 @@ class StringFormat { return this.compressUnit(value, counts, units, 2); } - //压缩任意单位的数字,后缀加上单位文字 + /** 压缩任意单位的数字,后缀加上单位文字 */ private compressUnit(value: any, valueArr: number[], unitArr: string[], fixNum: number = 2): string { let counts = valueArr; let units = unitArr; let res: string = ""; - let index; + let index: number; for (index = 0; index < counts.length; index++) { const e = counts[index]; if (value < e) { @@ -127,11 +128,10 @@ class StringFormat { } break; } - } return res + units[index]; } } -/**格式化处理函数 */ +/** 格式化处理函数 */ export let StringFormatFunction = new StringFormat(); \ No newline at end of file diff --git a/assets/libs/model-view/VMCompsEdit.ts b/assets/libs/model-view/VMCompsEdit.ts index fa7e786..d8c6228 100644 --- a/assets/libs/model-view/VMCompsEdit.ts +++ b/assets/libs/model-view/VMCompsEdit.ts @@ -1,4 +1,4 @@ -import { CCString, Component, Enum, log, Node, _decorator } from "cc"; +import { _decorator, CCString, Component, Enum, log, Node } from "cc"; import { VMEnv } from "./VMEnv"; const { ccclass, property, executeInEditMode, menu, help } = _decorator; @@ -36,10 +36,10 @@ export default class MVCompsEdit extends Component { return this.actionType === ACTION_MODE.SEARCH_COMPONENT; } }) - public get findTrigger() { + get findTrigger() { return false; } - public set findTrigger(v: boolean) { + set findTrigger(v: boolean) { this.setComponents(0); } @@ -50,10 +50,10 @@ export default class MVCompsEdit extends Component { return this.actionType === ACTION_MODE.ENABLE_COMPONENT; } }) - public get enableTrigger() { + get enableTrigger() { return false; } - public set enableTrigger(v: boolean) { + set enableTrigger(v: boolean) { this.setComponents(1); } @@ -64,10 +64,10 @@ export default class MVCompsEdit extends Component { return this.actionType === ACTION_MODE.ENABLE_COMPONENT; } }) - public get disableTrigger() { + get disableTrigger() { return false; } - public set disableTrigger(v: boolean) { + set disableTrigger(v: boolean) { this.setComponents(2); } @@ -88,10 +88,10 @@ export default class MVCompsEdit extends Component { return this.allowDelete && this.actionType === ACTION_MODE.DELETE_COMPONENT; } }) - public get deleteTrigger() { + get deleteTrigger() { return false; } - public set deleteTrigger(v: boolean) { + set deleteTrigger(v: boolean) { this.setComponents(3); } @@ -102,10 +102,10 @@ export default class MVCompsEdit extends Component { return this.actionType === ACTION_MODE.REPLACE_WATCH_PATH; } }) - public get replaceTrigger() { + get replaceTrigger() { return false; } - public set replaceTrigger(v: boolean) { + set replaceTrigger(v: boolean) { this.setComponents(4); } @@ -269,7 +269,7 @@ export default class MVCompsEdit extends Component { getNodePath(node: Node) { let parent = node; - let array = []; + let array: string[] = []; while (parent) { let p = parent.getParent(); if (p) { @@ -282,4 +282,4 @@ export default class MVCompsEdit extends Component { } return array.reverse().join('/'); } -} +} \ No newline at end of file diff --git a/assets/libs/model-view/VMCustom.ts b/assets/libs/model-view/VMCustom.ts index 47ba4bf..5db4230 100644 --- a/assets/libs/model-view/VMCustom.ts +++ b/assets/libs/model-view/VMCustom.ts @@ -18,7 +18,6 @@ const COMP_ARRAY_CHECK = [ ['cc.Toggle', 'isChecked', true] ]; - /** * [VM-Custom] * 自定义数值监听, 可以快速对该节点上任意一个组件上的属性进行双向绑定 @@ -170,4 +169,4 @@ export class VMCustom extends VMBase { this._oldValue = this.getComponentValue(); this.onValueController(newValue, oldValue); } -} +} \ No newline at end of file diff --git a/assets/libs/model-view/VMEnv.ts b/assets/libs/model-view/VMEnv.ts index addb3e8..0992efb 100644 --- a/assets/libs/model-view/VMEnv.ts +++ b/assets/libs/model-view/VMEnv.ts @@ -4,7 +4,6 @@ import { EDITOR } from "cc/env"; export class VMEnv { /** 编辑状态 */ static get editor() { - // @ts-ignore - return EDITOR && !cc.GAME_VIEW; + return EDITOR; } } \ No newline at end of file diff --git a/assets/libs/model-view/VMEvent.ts b/assets/libs/model-view/VMEvent.ts index dbdd1dd..4086d80 100644 --- a/assets/libs/model-view/VMEvent.ts +++ b/assets/libs/model-view/VMEvent.ts @@ -35,7 +35,7 @@ export default class VMEvent extends VMBase { @property({ tooltip: '使用模板模式,可以使用多路径监听' }) - public templateMode: boolean = false; + templateMode: boolean = false; @property({ tooltip: '监听获取值的路径', @@ -65,7 +65,7 @@ export default class VMEvent extends VMBase { tooltip: '过滤模式,会根据条件过滤掉时间的触发', type: Enum(FILTER_MODE) }) - public filterMode: FILTER_MODE = FILTER_MODE.none; + filterMode: FILTER_MODE = FILTER_MODE.none; @property({ visible: function () { @@ -73,7 +73,7 @@ export default class VMEvent extends VMBase { return this.filterMode !== FILTER_MODE.none } }) - public compareValue: string = ''; + compareValue: string = ''; @property([EventHandler]) changeEvents: EventHandler[] = []; diff --git a/assets/libs/model-view/VMLabel.ts b/assets/libs/model-view/VMLabel.ts index b5c89f8..6b4da4e 100644 --- a/assets/libs/model-view/VMLabel.ts +++ b/assets/libs/model-view/VMLabel.ts @@ -186,4 +186,4 @@ export default class VMLabel extends VMBase { return false; } -} +} \ No newline at end of file diff --git a/assets/libs/model-view/VMModify.ts b/assets/libs/model-view/VMModify.ts index 44305ac..cd07d42 100644 --- a/assets/libs/model-view/VMModify.ts +++ b/assets/libs/model-view/VMModify.ts @@ -146,4 +146,4 @@ export default class VMModify extends VMBase { if (int) { a = Math.round(a) } this.VM.setValue(this.watchPath, this.clampValue(a)); } -} +} \ No newline at end of file diff --git a/assets/libs/model-view/VMParent.ts b/assets/libs/model-view/VMParent.ts index a120605..f176b49 100644 --- a/assets/libs/model-view/VMParent.ts +++ b/assets/libs/model-view/VMParent.ts @@ -36,6 +36,8 @@ export default class VMParent extends GameComponent { */ onLoad() { if (this.data == null) return; + this.onBind(); + this.tag = '_temp' + '<' + this.node.uuid.replace('.', '') + '>'; VM.add(this.data, this.tag); // log(VM['_mvs'],this.tag) @@ -47,8 +49,6 @@ export default class VMParent extends GameComponent { this.replaceVMPath(comp, this.tag) } // console.groupEnd() - - this.onBind(); } /**在 onLoad 完成 和 start() 之前调用,你可以在这里进行初始化数据等操作 */ @@ -119,4 +119,4 @@ export default class VMParent extends GameComponent { super.onDestroy(); } -} +} \ No newline at end of file diff --git a/assets/libs/model-view/VMProgress.ts b/assets/libs/model-view/VMProgress.ts index abfe514..d41a043 100644 --- a/assets/libs/model-view/VMProgress.ts +++ b/assets/libs/model-view/VMProgress.ts @@ -95,4 +95,4 @@ export default class VMProgress extends VMCustom { this.setComponentValue(value); } -} +} \ No newline at end of file diff --git a/assets/libs/model-view/VMState.ts b/assets/libs/model-view/VMState.ts index 76bcf04..057a329 100644 --- a/assets/libs/model-view/VMState.ts +++ b/assets/libs/model-view/VMState.ts @@ -295,4 +295,4 @@ export default class VMState extends VMBase { return false; } -} +} \ No newline at end of file diff --git a/assets/libs/model-view/ViewModel.ts b/assets/libs/model-view/ViewModel.ts index c92759f..1d1af9c 100644 --- a/assets/libs/model-view/ViewModel.ts +++ b/assets/libs/model-view/ViewModel.ts @@ -34,7 +34,7 @@ function getValueFromPath(obj: any, path: string, def?: any, tag: string | null /** * ModelViewer 类 */ -class ViewModel{ +class ViewModel { constructor(data: T, tag: string) { new JsonOb(data, this._callback.bind(this)); this.$data = data; @@ -149,6 +149,9 @@ class VMManager { */ getValue(path: string, def?: any): any { path = path.trim(); // 防止空格,自动剔除 + + if (path === '') return ''; + let rs = path.split('.'); if (rs.length < 2) { console.error('Get Value Cant find path:' + path); return; }; let vm = this.get(rs[0]); @@ -215,10 +218,8 @@ class VMManager { } } -// 整数、小数、时间、缩写 - /** * VM管理对象,使用文档: - * https://github.com/wsssheep/cocos_creator_mvvm_tools/blob/master/docs/ViewModelScript.md + * https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12037849&doc_id=2873565 */ export let VM = new VMManager(); \ No newline at end of file diff --git a/assets/libs/model-view/ui/BhvRollNumber.ts b/assets/libs/model-view/ui/BhvRollNumber.ts index 9b33aeb..e39da04 100644 --- a/assets/libs/model-view/ui/BhvRollNumber.ts +++ b/assets/libs/model-view/ui/BhvRollNumber.ts @@ -45,10 +45,10 @@ export class BhvRollNumber extends Component { @property({ tooltip: '滚动的目标值' }) - public get targetValue(): number { + get targetValue(): number { return this._targetValue; } - public set targetValue(v: number) { + set targetValue(v: number) { this._targetValue = v; this.scroll();//数据变动了就开始滚动 } diff --git a/assets/libs/model-view/ui/BhvSwitchPage.ts b/assets/libs/model-view/ui/BhvSwitchPage.ts index ae58d21..244b31d 100644 --- a/assets/libs/model-view/ui/BhvSwitchPage.ts +++ b/assets/libs/model-view/ui/BhvSwitchPage.ts @@ -13,13 +13,13 @@ export class BhvSwitchPage extends Component { @property private _index: number = 0; - public get index(): number { + get index(): number { return this._index; } @property({ type: CCInteger }) - public set index(v: number) { + set index(v: number) { if (this.isChanging) return; v = Math.round(v); let count = this.node.children.length - 1; @@ -49,7 +49,7 @@ export class BhvSwitchPage extends Component { private _isChanging: boolean = false; /**只读,是否在changing 的状态 */ - public get isChanging(): boolean { + get isChanging(): boolean { return this._isChanging; } @@ -85,7 +85,7 @@ export class BhvSwitchPage extends Component { showNode.active = true; } - public next(): boolean { + next(): boolean { if (this.isChanging) { return false; } @@ -95,7 +95,7 @@ export class BhvSwitchPage extends Component { } } - public previous(): boolean { + previous(): boolean { if (this.isChanging) { return false; } @@ -105,7 +105,7 @@ export class BhvSwitchPage extends Component { } } - public setEventIndex(e: any, index: any): boolean { + setEventIndex(e: any, index: any): boolean { if (this.index >= 0 && this.index != null && this.isChanging === false) { this.index = index; return true; @@ -114,4 +114,4 @@ export class BhvSwitchPage extends Component { return false; } } -} +} \ No newline at end of file diff --git a/assets/libs/network.meta b/assets/libs/network.meta new file mode 100644 index 0000000..bafd121 --- /dev/null +++ b/assets/libs/network.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.2.0", + "importer": "directory", + "imported": true, + "uuid": "c378c808-8d92-4f96-9eb6-a122b5f1716f", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/libs/network/.network.md b/assets/libs/network/.network.md new file mode 100644 index 0000000..8ff44c7 --- /dev/null +++ b/assets/libs/network/.network.md @@ -0,0 +1,3 @@ +游戏网络库 +1. Http +2. WebSocket \ No newline at end of file diff --git a/assets/libs/network/HttpRequest.ts b/assets/libs/network/HttpRequest.ts new file mode 100644 index 0000000..3a62b60 --- /dev/null +++ b/assets/libs/network/HttpRequest.ts @@ -0,0 +1,317 @@ +/* + * @Author: dgflash + * @Date: 2022-09-01 18:00:28 + * @LastEditors: dgflash + * @LastEditTime: 2022-09-09 18:10:50 + */ +import { error, warn } from "cc"; + +/** + * 使用流程文档可参考、简化与服务器对接、使用新版API体验,可进入下面地址获取新版本,替换network目录中的内容 + * https://store.cocos.com/app/detail/5877 + */ + +/** 当前请求地址集合 */ +var urls: any = {}; +/** 请求参数 */ +var reqparams: any = {}; + +type HttpCallback = (ret: HttpReturn) => void; + +/** 请求事件 */ +export enum HttpEvent { + /** 断网 */ + NO_NETWORK = "http_request_no_network", + /** 未知错误 */ + UNKNOWN_ERROR = "http_request_unknown_error", + /** 请求超时 */ + TIMEOUT = "http_request_timout" +} + +/** + * HTTP请求返回值 + */ +export class HttpReturn { + /** 是否请求成功 */ + isSucc: boolean = false; + /** 请求返回数据 */ + res?: any; + /** 请求错误数据 */ + err?: any; +} + +/** HTTP请求 */ +export class HttpRequest { + /** 服务器地址 */ + server: string = "http://127.0.0.1/"; + /** 请求超时时间 */ + timeout: number = 10000; + /** 自定义请求头信息 */ + private header: Map = new Map(); + + /** + * 添加自定义请求头信息 + * @param name 信息名 + * @param value 信息值 + */ + addHeader(name: string, value: string) { + this.header.set(name, value); + } + + /** + * HTTP GET请求 + * @param name 协议名 + * @param onComplete 请求完整回调方法 + * @param params 查询参数 + * @example + var param = '{"uid":12345}' + var complete = (ret: HttpReturn) => { + console.log(ret.res); + } + oops.http.getWithParams(name, complete, param); + */ + get(name: string, onComplete: HttpCallback, params: any = null) { + this.sendRequest(name, params, false, onComplete) + } + + /** + * HTTP GET请求 + * @param name 协议名 + * @param params 查询参数 + * @example + var txt = await oops.http.getAsync(name); + if (txt.isSucc) { + console.log(txt.res); + } + */ + getAsync(name: string, params: any = null): Promise { + return new Promise((resolve, reject) => { + this.sendRequest(name, params, false, (ret: HttpReturn) => { + resolve(ret); + }) + }); + } + + /** + * HTTP GET请求非文本格式数据 + * @param name 协议名 + * @param onComplete 请求完整回调方法 + * @param params 查询参数 + */ + getByArraybuffer(name: string, onComplete: HttpCallback, params: any = null) { + this.sendRequest(name, params, false, onComplete, 'arraybuffer', false); + } + + /** + * HTTP GET请求非文本格式数据 + * @param name 协议名 + * @param params 查询参数 + * @returns Promise + */ + getAsyncByArraybuffer(name: string, params: any = null): Promise { + return new Promise((resolve, reject) => { + this.sendRequest(name, params, false, (ret: HttpReturn) => { + resolve(ret); + }, 'arraybuffer', false); + }); + } + + /** + * HTTP POST请求 + * @param name 协议名 + * @param params 查询参数 + * @param onComplete 请求完整回调方法 + * @example + var param = '{"LoginCode":"donggang_dev","Password":"e10adc3949ba59abbe56e057f20f883e"}' + var complete = (ret: HttpReturn) => { + console.log(ret.res); + } + oops.http.post(name, complete, param); + */ + post(name: string, onComplete: HttpCallback, params: any = null) { + this.sendRequest(name, params, true, onComplete); + } + + /** + * HTTP POST请求 + * @param name 协议名 + * @param params 查询参数 + */ + postAsync(name: string, params: any = null): Promise { + return new Promise((resolve, reject) => { + this.sendRequest(name, params, true, (ret: HttpReturn) => { + resolve(ret); + }); + }); + } + + /** + * 取消请求中的请求 + * @param name 协议名 + */ + abort(name: string) { + var xhr = urls[this.server + name]; + if (xhr) { + xhr.abort(); + } + } + + /** + * 获得字符串形式的参数 + * @param params 参数对象 + * @returns 参数字符串 + */ + private getParamString(params: any) { + var result = ""; + for (var name in params) { + let data = params[name]; + if (data instanceof Object) { + for (var key in data) + result += `${key}=${data[key]}&`; + } + else { + result += `${name}=${data}&`; + } + } + return result.substring(0, result.length - 1); + } + + /** + * Http请求 + * @param name(string) 请求地址 + * @param params(JSON) 请求参数 + * @param isPost(boolen) 是否为POST方式 + * @param callback(function) 请求成功回调 + * @param responseType(string) 响应类型 + * @param isOpenTimeout(boolean) 是否触发请求超时错误 + */ + private sendRequest(name: string, + params: any, + isPost: boolean, + onComplete: HttpCallback, + responseType?: string, + isOpenTimeout: boolean = true) { + if (name == null || name == '') { + error("请求地址不能为空"); + return; + } + + var url: string, newUrl: string, paramsStr: string = ""; + if (name.toLocaleLowerCase().indexOf("http") == 0) { + url = name; + } + else { + url = this.server + name; + } + + if (params) { + paramsStr = this.getParamString(params); + if (url.indexOf("?") > -1) + newUrl = url + "&" + paramsStr; + else + newUrl = url + "?" + paramsStr; + } + else { + newUrl = url; + } + + if (urls[newUrl] != null && reqparams[newUrl] == paramsStr) { + warn(`地址【${url}】已正在请求中,不能重复请求`); + return; + } + + var xhr = new XMLHttpRequest(); + + // 防重复请求功能 + urls[newUrl] = xhr; + reqparams[newUrl] = paramsStr; + + if (isPost) { + xhr.open("POST", url); + } + else { + xhr.open("GET", newUrl); + } + + // 添加自定义请求头信息 + for (const [key, value] of this.header) { + xhr.setRequestHeader(key, value); + } + // xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); + // xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8"); + + var data: any = {}; + data.url = url; + data.params = params; + + // 请求超时 + if (isOpenTimeout) { + xhr.timeout = this.timeout; + xhr.ontimeout = () => { + this.deleteCache(newUrl); + + ret.isSucc = false; + ret.err = HttpEvent.TIMEOUT; // 超时 + onComplete(data); + } + } + + // 响应结果 + var ret: HttpReturn = new HttpReturn(); + + xhr.onloadend = () => { + if (xhr.status == 500) { + this.deleteCache(newUrl); + + ret.isSucc = false; + ret.err = HttpEvent.NO_NETWORK; // 断网 + onComplete(ret); + } + } + + xhr.onerror = () => { + this.deleteCache(newUrl); + + ret.isSucc = false; + if (xhr.readyState == 0 || xhr.readyState == 1 || xhr.status == 0) { + ret.err = HttpEvent.NO_NETWORK; // 断网 + } + else { + ret.err = HttpEvent.UNKNOWN_ERROR; // 未知错误 + } + + onComplete(ret); + }; + + xhr.onreadystatechange = () => { + if (xhr.readyState != 4) return; + + this.deleteCache(newUrl); + + if (xhr.status == 200 && onComplete) { + ret.isSucc = true; + if (responseType == 'arraybuffer') { + xhr.responseType = responseType; // 加载非文本格式 + ret.res = xhr.response; + } + else { + ret.res = JSON.parse(xhr.response); + } + onComplete(ret); + } + }; + + // 发送请求 + if (params == null || params == "") { + xhr.send(); + } + else { + xhr.send(paramsStr); + } + } + + private deleteCache(url: string) { + delete urls[url]; + delete reqparams[url]; + } +} \ No newline at end of file diff --git a/assets/libs/network/HttpRequest.ts.meta b/assets/libs/network/HttpRequest.ts.meta new file mode 100644 index 0000000..dc4c2e3 --- /dev/null +++ b/assets/libs/network/HttpRequest.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "806e5b7c-51eb-45cb-8b29-9fcf5d9ee6a7", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/libs/network/NetInterface.ts b/assets/libs/network/NetInterface.ts new file mode 100644 index 0000000..4bf7608 --- /dev/null +++ b/assets/libs/network/NetInterface.ts @@ -0,0 +1,92 @@ +/* + * @Author: dgflash + * @Date: 2022-09-01 18:00:28 + * @LastEditors: dgflash + * @LastEditTime: 2022-09-09 18:31:18 + */ + +/* + * 网络相关接口定义 + */ +export type NetData = (string | ArrayBufferLike | Blob | ArrayBufferView); +export type NetCallFunc = (data: any) => void; + +/** 请求协议 */ +export interface IRequestProtocol { + /** 协议命令编号 */ + cmd: string, + /** 回调方法名 */ + callback?: string, + /** 是否压缩 */ + isCompress: boolean, + /** 渠道编号 */ + channelid: number, + /** 消息内容 */ + data?: any; +} + +/** 响应协议 */ +export interface IResponseProtocol { + /** 响应协议状态码 */ + code: number, + /** 数据是否压缩 */ + isCompress: boolean, + /** 协议数据 */ + data?: any, + /** 协议回调方法名 */ + callback?: string +} + +/** 回调对象 */ +export interface CallbackObject { + target: any, // 回调对象,不为null时调用target.callback(xxx) + callback: NetCallFunc, // 回调函数 +} + +/** 请求对象 */ +export interface RequestObject { + buffer: NetData, // 请求的Buffer + rspCmd: string, // 等待响应指令 + rspObject: CallbackObject | null, // 等待响应的回调对象 +} + +/** 协议辅助接口 */ +export interface IProtocolHelper { + /** 返回包头长度 */ + getHeadlen(): number; + /** 返回一个心跳包 */ + getHearbeat(): NetData; + /** 返回整个包的长度 */ + getPackageLen(msg: NetData): number; + /** 检查包数据是否合法(避免客户端报错崩溃) */ + checkResponsePackage(msg: IResponseProtocol): boolean; + /** 处理请求包数据 */ + handlerRequestPackage(reqProtocol: IRequestProtocol): string; + /** 处理响应包数据 */ + handlerResponsePackage(respProtocol: IResponseProtocol): boolean; + /** 返回包的id或协议类型 */ + getPackageId(msg: IResponseProtocol): string; +} + +export type SocketFunc = (event: any) => void; +export type MessageFunc = (msg: NetData) => void; + +/** Socket接口 */ +export interface ISocket { + onConnected: SocketFunc | null; // 连接回调 + onMessage: MessageFunc | null; // 消息回调 + onError: SocketFunc | null; // 错误回调 + onClosed: SocketFunc | null; // 关闭回调 + + connect(options: any): any; // 连接接口 + send(buffer: NetData): number; // 数据发送接口 + close(code?: number, reason?: string): void; // 关闭接口 +} + +/** 网络提示接口 */ +export interface INetworkTips { + connectTips(isShow: boolean): void; + reconnectTips(isShow: boolean): void; + requestTips(isShow: boolean): void; + responseErrorCode(code: number): void; +} \ No newline at end of file diff --git a/assets/libs/network/NetInterface.ts.meta b/assets/libs/network/NetInterface.ts.meta new file mode 100644 index 0000000..42f5745 --- /dev/null +++ b/assets/libs/network/NetInterface.ts.meta @@ -0,0 +1,11 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "d9f8bf82-57af-45c8-ac27-51d0a33ad69d", + "files": [], + "subMetas": {}, + "userData": { + "simulateGlobals": [] + } +} diff --git a/assets/libs/network/NetManager.ts b/assets/libs/network/NetManager.ts new file mode 100644 index 0000000..b88ca88 --- /dev/null +++ b/assets/libs/network/NetManager.ts @@ -0,0 +1,148 @@ +/* + * @Author: dgflash + * @Date: 2022-09-01 18:00:28 + * @LastEditors: dgflash + * @LastEditTime: 2022-09-09 18:10:50 + */ +import { CallbackObject, IRequestProtocol, NetData } from "./NetInterface"; +import { NetConnectOptions, NetNode } from "./NetNode"; + +/** + * 使用流程文档可参考、简化与服务器对接、使用新版API体验,可进入下面地址获取新版本,替换network目录中的内容 + * https://store.cocos.com/app/detail/5877 + */ + +/* + * 网络节点管理类 + */ +export class NetManager { + private static _instance: NetManager; + protected _channels: { [key: number]: NetNode } = {}; + + /** 网络管理单例对象 */ + static getInstance(): NetManager { + if (!this._instance) { + this._instance = new NetManager(); + } + return this._instance; + } + + /** + * 添加网络节点 + * @param node 网络节点 + * @param channelId 通道编号 + * @example + // 游戏服务器心跳协议 + class GameProtocol extends NetProtocolPako { + // 自定义心跳协议 + getHearbeat(): NetData { + return '{"action":"LoginAction","method":"heart","data":"null","callback":"LoginAction_heart"}'; + } + } + + var net = new NetNodeGame(); + var ws = new WebSock(); // WebSocket 网络连接对象 + var gp = new GameProtocol(); // 网络通讯协议对象 + var gt = new NetGameTips() // 网络提示对象 + net.init(ws, gp, gt); + NetManager.getInstance().setNetNode(net, NetChannelType.Game); + */ + setNetNode(node: NetNode, channelId: number = 0) { + this._channels[channelId] = node; + } + + /** 移除Node */ + removeNetNode(channelId: number) { + delete this._channels[channelId]; + } + + /** + * 网络节点连接服务器 + * @param options 连接参数 + * @param channelId 通道编号 + * @example + var options = { + url: 'ws://127.0.0.1:3000', + autoReconnect: 0 // -1 永久重连,0不自动重连,其他正整数为自动重试次数 + } + NetManager.getInstance().connect(options, NetChannelType.Game); + */ + connect(options: NetConnectOptions, channelId: number = 0): boolean { + if (this._channels[channelId]) { + return this._channels[channelId].connect(options); + } + return false; + } + + /** 节点连接发送数据*/ + send(buf: NetData, force: boolean = false, channelId: number = 0): number { + let node = this._channels[channelId]; + if (node) { + return node!.send(buf, force); + } + return -1; + } + + /** + * 发起请求,并在在结果返回时调用指定好的回调函数 + * @param reqProtocol 请求协议 + * @param rspObject 回调对象 + * @param showTips 是否触发请求提示 + * @param force 是否强制发送 + * @param channelId 通道编号 + * @example + let protocol: IRequestProtocol = { + action: action, + method: method, + data: JSON.stringify(data), + isCompress: this.isCompress, + channelid: netConfig.channelid + } + return this.request(protocol, rspObject, showTips, force); + */ + request(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false, channelId: number = 0) { + let node = this._channels[channelId]; + if (node) { + node.request(reqProtocol, rspObject, showTips, force); + } + } + + /** + * 同request功能一致,但在request之前会先判断队列中是否已有rspCmd,如有重复的则直接返回 + * @param reqProtocol 请求协议 + * @param rspObject 回调对象 + * @param showTips 是否触发请求提示 + * @param force 是否强制发送 + * @param channelId 通道编号 + * @example + let protocol: IRequestProtocol = { + action: action, + method: method, + data: JSON.stringify(data), + isCompress: this.isCompress, + channelid: netConfig.channelid + } + return this.request(protocol, rspObject, showTips, force); + */ + requestUnique(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false, channelId: number = 0): boolean { + let node = this._channels[channelId]; + if (node) { + return node.requestUnique(reqProtocol, rspObject, showTips, force); + } + return false; + } + + /** + * 节点网络断开 + * @param code 关闭码 + * @param reason 关闭原因 + * @param channelId 通道编号 + * @example + * NetManager.getInstance().close(undefined, undefined, NetChannelType.Game); + */ + close(code?: number, reason?: string, channelId: number = 0) { + if (this._channels[channelId]) { + return this._channels[channelId].closeSocket(code, reason); + } + } +} \ No newline at end of file diff --git a/assets/libs/network/NetManager.ts.meta b/assets/libs/network/NetManager.ts.meta new file mode 100644 index 0000000..aa09a64 --- /dev/null +++ b/assets/libs/network/NetManager.ts.meta @@ -0,0 +1,11 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "d8cd57a5-e860-464d-84d6-f8df1bf04b89", + "files": [], + "subMetas": {}, + "userData": { + "simulateGlobals": [] + } +} diff --git a/assets/libs/network/NetNode.ts b/assets/libs/network/NetNode.ts new file mode 100644 index 0000000..76862cf --- /dev/null +++ b/assets/libs/network/NetNode.ts @@ -0,0 +1,491 @@ +import { error, warn } from "cc"; +import { Logger } from "../../core/common/log/Logger"; +import { CallbackObject, INetworkTips, IProtocolHelper, IRequestProtocol, ISocket, NetCallFunc, NetData, RequestObject } from "./NetInterface"; + +/* +* CocosCreator网络节点基类,以及网络相关接口定义 +* 1. 网络连接、断开、请求发送、数据接收等基础功能 +* 2. 心跳机制 +* 3. 断线重连 + 请求重发 +* 4. 调用网络屏蔽层 +*/ + +type ExecuterFunc = (callback: CallbackObject, buffer: NetData) => void; +type CheckFunc = (checkedFunc: VoidFunc) => void; +type VoidFunc = () => void; +type BoolFunc = () => boolean; + +var NetNodeStateStrs = ["已关闭", "连接中", "验证中", "可传输数据"]; + +/** 网络提示类型枚举 */ +export enum NetTipsType { + Connecting, + ReConnecting, + Requesting, +} + +/** 网络状态枚举 */ +export enum NetNodeState { + Closed, // 已关闭 + Connecting, // 连接中 + Checking, // 验证中 + Working, // 可传输数据 +} + +/** 网络连接参数 */ +export interface NetConnectOptions { + host?: string, // 地址 + port?: number, // 端口 + url?: string, // url,与地址+端口二选一 + autoReconnect?: number, // -1 永久重连,0不自动重连,其他正整数为自动重试次数 +} + +/** 网络节点 */ +export class NetNode { + protected _connectOptions: NetConnectOptions | null = null; + protected _autoReconnect: number = 0; + protected _isSocketInit: boolean = false; // Socket是否初始化过 + protected _isSocketOpen: boolean = false; // Socket是否连接成功过 + protected _state: NetNodeState = NetNodeState.Closed; // 节点当前状态 + protected _socket: ISocket | null = null; // Socket对象(可能是原生socket、websocket、wx.socket...) + + protected _networkTips: INetworkTips | null = null; // 网络提示ui对象(请求提示、断线重连提示等) + protected _protocolHelper: IProtocolHelper | null = null; // 包解析对象 + protected _connectedCallback: CheckFunc | null = null; // 连接完成回调 + protected _disconnectCallback: BoolFunc | null = null; // 断线回调 + protected _callbackExecuter: ExecuterFunc | null = null; // 回调执行 + + protected _keepAliveTimer: any = null; // 心跳定时器 + protected _receiveMsgTimer: any = null; // 接收数据定时器 + protected _reconnectTimer: any = null; // 重连定时器 + protected _heartTime: number = 10000; // 心跳间隔 + protected _receiveTime: number = 6000000; // 多久没收到数据断开 + protected _reconnetTimeOut: number = 8000000; // 重连间隔 + protected _requests: RequestObject[] = Array(); // 请求列表 + protected _listener: { [key: string]: CallbackObject[] | null } = {} // 监听者列表 + + /********************** 网络相关处理 *********************/ + init(socket: ISocket, protocol: IProtocolHelper, networkTips: INetworkTips | null = null, execFunc: ExecuterFunc | null = null) { + Logger.instance.logNet(`网络初始化`); + this._socket = socket; + this._protocolHelper = protocol; + this._networkTips = networkTips; + this._callbackExecuter = execFunc ? execFunc : (callback: CallbackObject, buffer: NetData) => { + callback.callback.call(callback.target, buffer); + } + } + + /** + * 请求连接服务器 + * @param options 连接参数 + */ + connect(options: NetConnectOptions): boolean { + if (this._socket && this._state == NetNodeState.Closed) { + if (!this._isSocketInit) { + this.initSocket(); + } + this._state = NetNodeState.Connecting; + if (!this._socket.connect(options)) { + this.updateNetTips(NetTipsType.Connecting, false); + return false; + } + if (this._connectOptions == null && typeof options.autoReconnect == "number") { + this._autoReconnect = options.autoReconnect; + } + this._connectOptions = options; + this.updateNetTips(NetTipsType.Connecting, true); + return true; + } + return false; + } + + protected initSocket() { + if (this._socket) { + this._socket.onConnected = (event) => { this.onConnected(event) }; + this._socket.onMessage = (msg) => { this.onMessage(msg) }; + this._socket.onError = (event) => { this.onError(event) }; + this._socket.onClosed = (event) => { this.onClosed(event) }; + this._isSocketInit = true; + } + } + + protected updateNetTips(tipsType: NetTipsType, isShow: boolean) { + if (this._networkTips) { + if (tipsType == NetTipsType.Requesting) { + this._networkTips.requestTips(isShow); + } + else if (tipsType == NetTipsType.Connecting) { + this._networkTips.connectTips(isShow); + } + else if (tipsType == NetTipsType.ReConnecting) { + this._networkTips.reconnectTips(isShow); + } + } + } + + /** 网络连接成功 */ + protected onConnected(event: any) { + Logger.instance.logNet("网络已连接") + this._isSocketOpen = true; + // 如果设置了鉴权回调,在连接完成后进入鉴权阶段,等待鉴权结束 + if (this._connectedCallback !== null) { + this._state = NetNodeState.Checking; + this._connectedCallback(() => { this.onChecked() }); + } + else { + this.onChecked(); + } + Logger.instance.logNet(`网络已连接当前状态为【${NetNodeStateStrs[this._state]}】`); + } + + /** 连接验证成功,进入工作状态 */ + protected onChecked() { + Logger.instance.logNet("连接验证成功,进入工作状态"); + this._state = NetNodeState.Working; + // 关闭连接或重连中的状态显示 + this.updateNetTips(NetTipsType.Connecting, false); + this.updateNetTips(NetTipsType.ReConnecting, false); + + // 重发待发送信息 + var requests = this._requests.concat(); + if (requests.length > 0) { + Logger.instance.logNet(`请求【${this._requests.length}】个待发送的信息`); + + for (var i = 0; i < requests.length;) { + let req = requests[i]; + this._socket!.send(req.buffer); + if (req.rspObject == null || req.rspCmd != "") { + requests.splice(i, 1); + } + else { + ++i; + } + } + // 如果还有等待返回的请求,启动网络请求层 + this.updateNetTips(NetTipsType.Requesting, this._requests.length > 0); + } + } + + /** 接收到一个完整的消息包 */ + protected onMessage(msg: any): void { + // Logger.logNet(`接受消息状态为【${NetNodeStateStrs[this._state]}】`); + + var json = JSON.parse(msg); + + // 进行头部的校验(实际包长与头部长度是否匹配) + if (!this._protocolHelper!.checkResponsePackage(json)) { + error(`校验接受消息数据异常`); + return; + } + + // 处理相应包数据 + if (!this._protocolHelper!.handlerResponsePackage(json)) { + if (this._networkTips) + this._networkTips.responseErrorCode(json.code); + } + + // 接受到数据,重新定时收数据计时器 + this.resetReceiveMsgTimer(); + // 重置心跳包发送器 + this.resetHearbeatTimer(); + // 触发消息执行 + let rspCmd = this._protocolHelper!.getPackageId(json); + + Logger.instance.logNet(`接受到命令【${rspCmd}】的消息`); + // 优先触发request队列 + if (this._requests.length > 0) { + for (let reqIdx in this._requests) { + let req = this._requests[reqIdx]; + if (req.rspCmd == rspCmd && req.rspObject) { + Logger.instance.logNet(`触发请求命令【${rspCmd}】的回调`); + this._callbackExecuter!(req.rspObject, json.data); + this._requests.splice(parseInt(reqIdx), 1); + break; + } + } + + if (this._requests.length == 0) { + this.updateNetTips(NetTipsType.Requesting, false); + } + else { + Logger.instance.logNet(`请求队列中还有【${this._requests.length}】个请求在等待`); + } + } + + let listeners = this._listener[rspCmd]; + if (null != listeners) { + for (const rsp of listeners) { + Logger.instance.logNet(`触发监听命令【${rspCmd}】的回调`); + this._callbackExecuter!(rsp, json.data); + } + } + } + + protected onError(event: any) { + error(event); + } + + protected onClosed(event: any) { + this.clearTimer(); + + // 执行断线回调,返回false表示不进行重连 + if (this._disconnectCallback && !this._disconnectCallback()) { + Logger.instance.logNet(`断开连接`); + return; + } + + // 自动重连 + if (this.isAutoReconnect()) { + this.updateNetTips(NetTipsType.ReConnecting, true); + this._reconnectTimer = setTimeout(() => { + this._socket!.close(); + this._state = NetNodeState.Closed; + this.connect(this._connectOptions!); + if (this._autoReconnect > 0) { + this._autoReconnect -= 1; + } + }, this._reconnetTimeOut); + } + else { + this._state = NetNodeState.Closed; + } + } + + /** + * 断开网络 + * @param code 关闭码 + * @param reason 关闭原因 + */ + close(code?: number, reason?: string) { + this.clearTimer(); + this._listener = {}; + this._requests.length = 0; + if (this._networkTips) { + this._networkTips.connectTips(false); + this._networkTips.reconnectTips(false); + this._networkTips.requestTips(false); + } + if (this._socket) { + this._socket.close(code, reason); + } + else { + this._state = NetNodeState.Closed; + } + } + + /** + * 只是关闭Socket套接字(仍然重用缓存与当前状态) + * @param code 关闭码 + * @param reason 关闭原因 + */ + closeSocket(code?: number, reason?: string) { + if (this._socket) { + this._socket.close(code, reason); + } + } + + /** + * 发起请求,如果当前处于重连中,进入缓存列表等待重连完成后发送 + * @param buf 网络数据 + * @param force 是否强制发送 + */ + send(buf: NetData, force: boolean = false): number { + if (this._state == NetNodeState.Working || force) { + return this._socket!.send(buf); + } + else if (this._state == NetNodeState.Checking || + this._state == NetNodeState.Connecting) { + this._requests.push({ + buffer: buf, + rspCmd: "", + rspObject: null + }); + Logger.instance.logNet(`当前状态为【${NetNodeStateStrs[this._state]}】,繁忙并缓冲发送数据`); + return 0; + } + else { + error(`当前状态为【${NetNodeStateStrs[this._state]}】,请求错误`); + return -1; + } + } + + /** + * 发起请求,并进入缓存列表 + * @param reqProtocol 请求协议 + * @param rspObject 回调对象 + * @param showTips 是否触发请求提示 + * @param force 是否强制发送 + */ + request(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false) { + var rspCmd = this._protocolHelper!.handlerRequestPackage(reqProtocol); + this.base_request(reqProtocol, rspCmd, rspObject, showTips, force); + } + + /** + * 唯一request,确保没有同一响应的请求(避免一个请求重复发送,netTips界面的屏蔽也是一个好的方法) + * @param reqProtocol 请求协议 + * @param rspObject 回调对象 + * @param showTips 是否触发请求提示 + * @param force 是否强制发送 + */ + requestUnique(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false): boolean { + var rspCmd = this._protocolHelper!.handlerRequestPackage(reqProtocol); + + for (let i = 0; i < this._requests.length; ++i) { + if (this._requests[i].rspCmd == rspCmd) { + Logger.instance.logNet(`命令【${rspCmd}】重复请求`); + return false; + } + } + + this.base_request(reqProtocol, rspCmd, rspObject, showTips, force); + return true; + } + + private base_request(reqProtocol: IRequestProtocol, rspCmd: string, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false) { + var buf: NetData = JSON.stringify(reqProtocol); // 转为二进制流发送 + + if (this._state == NetNodeState.Working || force) { + this._socket!.send(buf); + } + + Logger.instance.logNet(`队列命令为【${rspCmd}】的请求,等待请求数据的回调`); + + // 进入发送缓存列表 + this._requests.push({ + buffer: buf, rspCmd, rspObject + }); + // 启动网络请求层 + if (showTips) { + this.updateNetTips(NetTipsType.Requesting, true); + } + } + + /********************** 回调相关处理 *********************/ + /** + * 设置一个唯一的服务器推送监听 + * @param cmd 命令字串 + * @param callback 回调方法 + * @param target 目标对象 + */ + setResponeHandler(cmd: string, callback: NetCallFunc, target?: any): boolean { + if (callback == null) { + error(`命令为【${cmd}】设置响应处理程序错误`); + return false; + } + this._listener[cmd] = [{ target, callback }]; + return true; + } + + /** + * 可添加多个同类返回消息的监听 + * @param cmd 命令字串 + * @param callback 回调方法 + * @param target 目标对象 + * @returns + */ + addResponeHandler(cmd: string, callback: NetCallFunc, target?: any): boolean { + if (callback == null) { + error(`命令为【${cmd}】添加响应处理程序错误`); + return false; + } + let rspObject = { target, callback }; + if (null == this._listener[cmd]) { + this._listener[cmd] = [rspObject]; + } + else { + let index = this.getNetListenersIndex(cmd, rspObject); + if (-1 == index) { + this._listener[cmd]!.push(rspObject); + } + } + return true; + } + + /** + * 删除一个监听中指定子回调 + * @param cmd 命令字串 + * @param callback 回调方法 + * @param target 目标对象 + */ + removeResponeHandler(cmd: string, callback: NetCallFunc, target?: any) { + if (null != this._listener[cmd] && callback != null) { + let index = this.getNetListenersIndex(cmd, { target, callback }); + if (-1 != index) { + this._listener[cmd]!.splice(index, 1); + } + } + } + + /** + * 清除所有监听或指定命令的监听 + * @param cmd 命令字串(默认不填为清除所有) + */ + cleanListeners(cmd: string = "") { + if (cmd == "") { + this._listener = {} + } + else { + delete this._listener[cmd]; + } + } + + protected getNetListenersIndex(cmd: string, rspObject: CallbackObject): number { + let index = -1; + for (let i = 0; i < this._listener[cmd]!.length; i++) { + let iterator = this._listener[cmd]![i]; + if (iterator.callback == rspObject.callback + && iterator.target == rspObject.target) { + index = i; + break; + } + } + return index; + } + + /********************** 心跳、超时相关处理 *********************/ + protected resetReceiveMsgTimer() { + if (this._receiveMsgTimer !== null) { + clearTimeout(this._receiveMsgTimer); + } + + this._receiveMsgTimer = setTimeout(() => { + warn("接收消息定时器关闭网络连接"); + this._socket!.close(); + }, this._receiveTime); + } + + protected resetHearbeatTimer() { + if (this._keepAliveTimer !== null) { + clearTimeout(this._keepAliveTimer); + } + + this._keepAliveTimer = setTimeout(() => { + Logger.instance.logNet("网络节点保持活跃发送心跳信息"); + this.send(this._protocolHelper!.getHearbeat()); + }, this._heartTime); + } + + protected clearTimer() { + if (this._receiveMsgTimer !== null) { + clearTimeout(this._receiveMsgTimer); + } + if (this._keepAliveTimer !== null) { + clearTimeout(this._keepAliveTimer); + } + if (this._reconnectTimer !== null) { + clearTimeout(this._reconnectTimer); + } + } + + /** 是否自动重连接 */ + isAutoReconnect() { + return this._autoReconnect != 0; + } + + /** 拒绝重新连接 */ + rejectReconnect() { + this._autoReconnect = 0; + this.clearTimer(); + } +} \ No newline at end of file diff --git a/assets/libs/network/NetNode.ts.meta b/assets/libs/network/NetNode.ts.meta new file mode 100644 index 0000000..5127f31 --- /dev/null +++ b/assets/libs/network/NetNode.ts.meta @@ -0,0 +1,11 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "57f0f07d-d243-4150-9f7c-cb2bbe8f18f1", + "files": [], + "subMetas": {}, + "userData": { + "simulateGlobals": [] + } +} diff --git a/assets/libs/network/NetProtocolPako.ts b/assets/libs/network/NetProtocolPako.ts new file mode 100644 index 0000000..3637b8a --- /dev/null +++ b/assets/libs/network/NetProtocolPako.ts @@ -0,0 +1,69 @@ +/* + * @Author: dgflash + * @Date: 2022-04-21 13:45:51 + * @LastEditors: dgflash + * @LastEditTime: 2022-04-21 13:51:33 + */ +import { IProtocolHelper, IRequestProtocol, IResponseProtocol, NetData } from "./NetInterface"; + +var unzip = function (str: string) { + let charData = str.split('').map(function (x) { + return x.charCodeAt(0); + }); + let binData = new Uint8Array(charData); + //@ts-ignore + let data = pako.inflate(binData, { to: 'string' }); + return data; +} + +var zip = function (str: string) { + //@ts-ignore + let binaryString = pako.gzip(str, { to: 'string' }); + return binaryString; +} + +/** Pako.js 数据压缩协议 */ +export class NetProtocolPako implements IProtocolHelper { + getHeadlen(): number { + return 0; + } + + getHearbeat(): NetData { + return ""; + } + + getPackageLen(msg: NetData): number { + return msg.toString().length; + } + + checkResponsePackage(respProtocol: IResponseProtocol): boolean { + return true; + } + + handlerResponsePackage(respProtocol: IResponseProtocol): boolean { + if (respProtocol.code == 1) { + if (respProtocol.isCompress) { + respProtocol.data = unzip(respProtocol.data); + } + respProtocol.data = JSON.parse(respProtocol.data); + + return true; + } + else { + return false; + } + } + + handlerRequestPackage(reqProtocol: IRequestProtocol): string { + var rspCmd = reqProtocol.cmd; + reqProtocol.callback = rspCmd; + if (reqProtocol.isCompress) { + reqProtocol.data = zip(reqProtocol.data); + } + return rspCmd; + } + + getPackageId(respProtocol: IResponseProtocol): string { + return respProtocol.callback!; + } +} \ No newline at end of file diff --git a/assets/libs/network/NetProtocolPako.ts.meta b/assets/libs/network/NetProtocolPako.ts.meta new file mode 100644 index 0000000..f35e285 --- /dev/null +++ b/assets/libs/network/NetProtocolPako.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "88ae0948-8390-4559-bd4e-d44f3f12dc22", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/libs/network/WebSock.ts b/assets/libs/network/WebSock.ts new file mode 100644 index 0000000..1ceaca9 --- /dev/null +++ b/assets/libs/network/WebSock.ts @@ -0,0 +1,84 @@ +/* + * @Author: dgflash + * @Date: 2021-07-03 16:13:17 + * @LastEditors: dgflash + * @LastEditTime: 2022-09-09 17:42:19 + */ +import { Logger } from "../../core/common/log/Logger"; +import { ISocket, MessageFunc, NetData } from "./NetInterface"; + +type Connected = (event: any) => void; + +/** + * WebSocket 封装 + * 1. 连接/断开相关接口 + * 2. 网络异常回调 + * 3. 数据发送与接收 + */ +export class WebSock implements ISocket { + private _ws: WebSocket | null = null; // websocket对象 + + /** 网络连接成功事件 */ + onConnected: ((this: WebSocket, ev: Event) => any) | null = null; + /** 接受到网络数据事件 */ + onMessage: MessageFunc | null = null; + /** 网络错误事件 */ + onError: ((this: WebSocket, ev: Event) => any) | null = null; + /** 网络断开事件 */ + onClosed: ((this: WebSocket, ev: CloseEvent) => any) | null = null; + + /** 请求连接 */ + connect(options: any) { + if (this._ws) { + if (this._ws.readyState === WebSocket.CONNECTING) { + Logger.logNet("websocket connecting, wait for a moment...") + return false; + } + } + + let url = null; + if (options.url) { + url = options.url; + } + else { + let ip = options.ip; + let port = options.port; + let protocol = options.protocol; + url = `${protocol}://${ip}:${port}`; + } + + this._ws = new WebSocket(url); + this._ws.binaryType = options.binaryType ? options.binaryType : "arraybuffer"; + this._ws.onmessage = (event) => { + let onMessage: MessageFunc = this.onMessage!; + onMessage(event.data); + }; + this._ws.onopen = this.onConnected; + this._ws.onerror = this.onError; + this._ws.onclose = this.onClosed; + return true; + } + + /** + * 发送数据 + * @param buffer 网络数据 + */ + send(buffer: NetData): number { + if (this._ws && this._ws.readyState == WebSocket.OPEN) { + this._ws.send(buffer); + return 1; + } + return -1; + } + + /** + * 网络断开 + * @param code 关闭码 + * @param reason 关闭原因 + */ + close(code?: number, reason?: string) { + if (this._ws) { + this._ws.close(code, reason); + } + } +} \ No newline at end of file diff --git a/assets/libs/network/WebSock.ts.meta b/assets/libs/network/WebSock.ts.meta new file mode 100644 index 0000000..711d773 --- /dev/null +++ b/assets/libs/network/WebSock.ts.meta @@ -0,0 +1,11 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "70df255b-214f-41eb-a16b-fa8a7c14a269", + "files": [], + "subMetas": {}, + "userData": { + "simulateGlobals": [] + } +} diff --git a/assets/libs/network/protocol.meta b/assets/libs/network/protocol.meta new file mode 100644 index 0000000..0d5da65 --- /dev/null +++ b/assets/libs/network/protocol.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.2.0", + "importer": "directory", + "imported": true, + "uuid": "922e2501-4a6b-4f54-852c-28e24c3fc5b8", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/libs/network/protocol/pako.min.js b/assets/libs/network/protocol/pako.min.js new file mode 100644 index 0000000..6b4a335 --- /dev/null +++ b/assets/libs/network/protocol/pako.min.js @@ -0,0 +1,3424 @@ +!(function(t) { + if ('object' == typeof exports && 'undefined' != typeof module) + module.exports = t(); + else if ('function' == typeof define && define.amd) define([], t); + else { + ('undefined' != typeof window + ? window + : 'undefined' != typeof global + ? global + : 'undefined' != typeof self + ? self + : this + ).pako = t(); + } +})(function() { + return (function r(s, o, l) { + function h(e, t) { + if (!o[e]) { + if (!s[e]) { + var a = 'function' == typeof require && require; + if (!t && a) return a(e, !0); + if (d) return d(e, !0); + var i = new Error("Cannot find module '" + e + "'"); + throw ((i.code = 'MODULE_NOT_FOUND'), i); + } + var n = (o[e] = { exports: {} }); + s[e][0].call( + n.exports, + function(t) { + return h(s[e][1][t] || t); + }, + n, + n.exports, + r, + s, + o, + l + ); + } + return o[e].exports; + } + for ( + var d = 'function' == typeof require && require, t = 0; + t < l.length; + t++ + ) + h(l[t]); + return h; + })( + { + 1: [ + function(t, e, a) { + 'use strict'; + var s = t('./zlib/deflate'), + o = t('./utils/common'), + l = t('./utils/strings'), + n = t('./zlib/messages'), + r = t('./zlib/zstream'), + h = Object.prototype.toString, + d = 0, + f = -1, + _ = 0, + u = 8; + function c(t) { + if (!(this instanceof c)) return new c(t); + this.options = o.assign( + { + level: f, + method: u, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: _, + to: '' + }, + t || {} + ); + var e = this.options; + e.raw && 0 < e.windowBits + ? (e.windowBits = -e.windowBits) + : e.gzip && + 0 < e.windowBits && + e.windowBits < 16 && + (e.windowBits += 16), + (this.err = 0), + (this.msg = ''), + (this.ended = !1), + (this.chunks = []), + (this.strm = new r()), + (this.strm.avail_out = 0); + var a = s.deflateInit2( + this.strm, + e.level, + e.method, + e.windowBits, + e.memLevel, + e.strategy + ); + if (a !== d) throw new Error(n[a]); + if ( + (e.header && s.deflateSetHeader(this.strm, e.header), + e.dictionary) + ) { + var i; + if ( + ((i = + 'string' == typeof e.dictionary + ? l.string2buf(e.dictionary) + : '[object ArrayBuffer]' === h.call(e.dictionary) + ? new Uint8Array(e.dictionary) + : e.dictionary), + (a = s.deflateSetDictionary(this.strm, i)) !== d) + ) + throw new Error(n[a]); + this._dict_set = !0; + } + } + function i(t, e) { + var a = new c(e); + if ((a.push(t, !0), a.err)) throw a.msg || n[a.err]; + return a.result; + } + (c.prototype.push = function(t, e) { + var a, + i, + n = this.strm, + r = this.options.chunkSize; + if (this.ended) return !1; + (i = e === ~~e ? e : !0 === e ? 4 : 0), + 'string' == typeof t + ? (n.input = l.string2buf(t)) + : '[object ArrayBuffer]' === h.call(t) + ? (n.input = new Uint8Array(t)) + : (n.input = t), + (n.next_in = 0), + (n.avail_in = n.input.length); + do { + if ( + (0 === n.avail_out && + ((n.output = new o.Buf8(r)), + (n.next_out = 0), + (n.avail_out = r)), + 1 !== (a = s.deflate(n, i)) && a !== d) + ) + return this.onEnd(a), !(this.ended = !0); + (0 !== n.avail_out && + (0 !== n.avail_in || (4 !== i && 2 !== i))) || + ('string' === this.options.to + ? this.onData( + l.buf2binstring(o.shrinkBuf(n.output, n.next_out)) + ) + : this.onData(o.shrinkBuf(n.output, n.next_out))); + } while ((0 < n.avail_in || 0 === n.avail_out) && 1 !== a); + return 4 === i + ? ((a = s.deflateEnd(this.strm)), + this.onEnd(a), + (this.ended = !0), + a === d) + : 2 !== i || (this.onEnd(d), !(n.avail_out = 0)); + }), + (c.prototype.onData = function(t) { + this.chunks.push(t); + }), + (c.prototype.onEnd = function(t) { + t === d && + ('string' === this.options.to + ? (this.result = this.chunks.join('')) + : (this.result = o.flattenChunks(this.chunks))), + (this.chunks = []), + (this.err = t), + (this.msg = this.strm.msg); + }), + (a.Deflate = c), + (a.deflate = i), + (a.deflateRaw = function(t, e) { + return ((e = e || {}).raw = !0), i(t, e); + }), + (a.gzip = function(t, e) { + return ((e = e || {}).gzip = !0), i(t, e); + }); + }, + { + './utils/common': 3, + './utils/strings': 4, + './zlib/deflate': 8, + './zlib/messages': 13, + './zlib/zstream': 15 + } + ], + 2: [ + function(t, e, a) { + 'use strict'; + var f = t('./zlib/inflate'), + _ = t('./utils/common'), + u = t('./utils/strings'), + c = t('./zlib/constants'), + i = t('./zlib/messages'), + n = t('./zlib/zstream'), + r = t('./zlib/gzheader'), + b = Object.prototype.toString; + function s(t) { + if (!(this instanceof s)) return new s(t); + this.options = _.assign( + { chunkSize: 16384, windowBits: 0, to: '' }, + t || {} + ); + var e = this.options; + e.raw && + 0 <= e.windowBits && + e.windowBits < 16 && + ((e.windowBits = -e.windowBits), + 0 === e.windowBits && (e.windowBits = -15)), + !(0 <= e.windowBits && e.windowBits < 16) || + (t && t.windowBits) || + (e.windowBits += 32), + 15 < e.windowBits && + e.windowBits < 48 && + 0 == (15 & e.windowBits) && + (e.windowBits |= 15), + (this.err = 0), + (this.msg = ''), + (this.ended = !1), + (this.chunks = []), + (this.strm = new n()), + (this.strm.avail_out = 0); + var a = f.inflateInit2(this.strm, e.windowBits); + if (a !== c.Z_OK) throw new Error(i[a]); + if ( + ((this.header = new r()), + f.inflateGetHeader(this.strm, this.header), + e.dictionary && + ('string' == typeof e.dictionary + ? (e.dictionary = u.string2buf(e.dictionary)) + : '[object ArrayBuffer]' === b.call(e.dictionary) && + (e.dictionary = new Uint8Array(e.dictionary)), + e.raw && + (a = f.inflateSetDictionary(this.strm, e.dictionary)) !== + c.Z_OK)) + ) + throw new Error(i[a]); + } + function o(t, e) { + var a = new s(e); + if ((a.push(t, !0), a.err)) throw a.msg || i[a.err]; + return a.result; + } + (s.prototype.push = function(t, e) { + var a, + i, + n, + r, + s, + o = this.strm, + l = this.options.chunkSize, + h = this.options.dictionary, + d = !1; + if (this.ended) return !1; + (i = e === ~~e ? e : !0 === e ? c.Z_FINISH : c.Z_NO_FLUSH), + 'string' == typeof t + ? (o.input = u.binstring2buf(t)) + : '[object ArrayBuffer]' === b.call(t) + ? (o.input = new Uint8Array(t)) + : (o.input = t), + (o.next_in = 0), + (o.avail_in = o.input.length); + do { + if ( + (0 === o.avail_out && + ((o.output = new _.Buf8(l)), + (o.next_out = 0), + (o.avail_out = l)), + (a = f.inflate(o, c.Z_NO_FLUSH)) === c.Z_NEED_DICT && + h && + (a = f.inflateSetDictionary(this.strm, h)), + a === c.Z_BUF_ERROR && !0 === d && ((a = c.Z_OK), (d = !1)), + a !== c.Z_STREAM_END && a !== c.Z_OK) + ) + return this.onEnd(a), !(this.ended = !0); + o.next_out && + ((0 !== o.avail_out && + a !== c.Z_STREAM_END && + (0 !== o.avail_in || + (i !== c.Z_FINISH && i !== c.Z_SYNC_FLUSH))) || + ('string' === this.options.to + ? ((n = u.utf8border(o.output, o.next_out)), + (r = o.next_out - n), + (s = u.buf2string(o.output, n)), + (o.next_out = r), + (o.avail_out = l - r), + r && _.arraySet(o.output, o.output, n, r, 0), + this.onData(s)) + : this.onData(_.shrinkBuf(o.output, o.next_out)))), + 0 === o.avail_in && 0 === o.avail_out && (d = !0); + } while ( + (0 < o.avail_in || 0 === o.avail_out) && + a !== c.Z_STREAM_END + ); + return ( + a === c.Z_STREAM_END && (i = c.Z_FINISH), + i === c.Z_FINISH + ? ((a = f.inflateEnd(this.strm)), + this.onEnd(a), + (this.ended = !0), + a === c.Z_OK) + : i !== c.Z_SYNC_FLUSH || + (this.onEnd(c.Z_OK), !(o.avail_out = 0)) + ); + }), + (s.prototype.onData = function(t) { + this.chunks.push(t); + }), + (s.prototype.onEnd = function(t) { + t === c.Z_OK && + ('string' === this.options.to + ? (this.result = this.chunks.join('')) + : (this.result = _.flattenChunks(this.chunks))), + (this.chunks = []), + (this.err = t), + (this.msg = this.strm.msg); + }), + (a.Inflate = s), + (a.inflate = o), + (a.inflateRaw = function(t, e) { + return ((e = e || {}).raw = !0), o(t, e); + }), + (a.ungzip = o); + }, + { + './utils/common': 3, + './utils/strings': 4, + './zlib/constants': 6, + './zlib/gzheader': 9, + './zlib/inflate': 11, + './zlib/messages': 13, + './zlib/zstream': 15 + } + ], + 3: [ + function(t, e, a) { + 'use strict'; + var i = + 'undefined' != typeof Uint8Array && + 'undefined' != typeof Uint16Array && + 'undefined' != typeof Int32Array; + (a.assign = function(t) { + for ( + var e, a, i = Array.prototype.slice.call(arguments, 1); + i.length; + + ) { + var n = i.shift(); + if (n) { + if ('object' != typeof n) + throw new TypeError(n + 'must be non-object'); + for (var r in n) + (e = n), + (a = r), + Object.prototype.hasOwnProperty.call(e, a) && (t[r] = n[r]); + } + } + return t; + }), + (a.shrinkBuf = function(t, e) { + return t.length === e + ? t + : t.subarray + ? t.subarray(0, e) + : ((t.length = e), t); + }); + var n = { + arraySet: function(t, e, a, i, n) { + if (e.subarray && t.subarray) t.set(e.subarray(a, a + i), n); + else for (var r = 0; r < i; r++) t[n + r] = e[a + r]; + }, + flattenChunks: function(t) { + var e, a, i, n, r, s; + for (e = i = 0, a = t.length; e < a; e++) i += t[e].length; + for (s = new Uint8Array(i), e = n = 0, a = t.length; e < a; e++) + (r = t[e]), s.set(r, n), (n += r.length); + return s; + } + }, + r = { + arraySet: function(t, e, a, i, n) { + for (var r = 0; r < i; r++) t[n + r] = e[a + r]; + }, + flattenChunks: function(t) { + return [].concat.apply([], t); + } + }; + (a.setTyped = function(t) { + t + ? ((a.Buf8 = Uint8Array), + (a.Buf16 = Uint16Array), + (a.Buf32 = Int32Array), + a.assign(a, n)) + : ((a.Buf8 = Array), + (a.Buf16 = Array), + (a.Buf32 = Array), + a.assign(a, r)); + }), + a.setTyped(i); + }, + {} + ], + 4: [ + function(t, e, a) { + 'use strict'; + var l = t('./common'), + n = !0, + r = !0; + try { + String.fromCharCode.apply(null, [0]); + } catch (t) { + n = !1; + } + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + r = !1; + } + for (var h = new l.Buf8(256), i = 0; i < 256; i++) + h[i] = + 252 <= i + ? 6 + : 248 <= i + ? 5 + : 240 <= i + ? 4 + : 224 <= i + ? 3 + : 192 <= i + ? 2 + : 1; + function d(t, e) { + if (e < 65534 && ((t.subarray && r) || (!t.subarray && n))) + return String.fromCharCode.apply(null, l.shrinkBuf(t, e)); + for (var a = '', i = 0; i < e; i++) a += String.fromCharCode(t[i]); + return a; + } + (h[254] = h[254] = 1), + (a.string2buf = function(t) { + var e, + a, + i, + n, + r, + s = t.length, + o = 0; + for (n = 0; n < s; n++) + 55296 == (64512 & (a = t.charCodeAt(n))) && + n + 1 < s && + 56320 == (64512 & (i = t.charCodeAt(n + 1))) && + ((a = 65536 + ((a - 55296) << 10) + (i - 56320)), n++), + (o += a < 128 ? 1 : a < 2048 ? 2 : a < 65536 ? 3 : 4); + for (e = new l.Buf8(o), n = r = 0; r < o; n++) + 55296 == (64512 & (a = t.charCodeAt(n))) && + n + 1 < s && + 56320 == (64512 & (i = t.charCodeAt(n + 1))) && + ((a = 65536 + ((a - 55296) << 10) + (i - 56320)), n++), + a < 128 + ? (e[r++] = a) + : (a < 2048 + ? (e[r++] = 192 | (a >>> 6)) + : (a < 65536 + ? (e[r++] = 224 | (a >>> 12)) + : ((e[r++] = 240 | (a >>> 18)), + (e[r++] = 128 | ((a >>> 12) & 63))), + (e[r++] = 128 | ((a >>> 6) & 63))), + (e[r++] = 128 | (63 & a))); + return e; + }), + (a.buf2binstring = function(t) { + return d(t, t.length); + }), + (a.binstring2buf = function(t) { + for ( + var e = new l.Buf8(t.length), a = 0, i = e.length; + a < i; + a++ + ) + e[a] = t.charCodeAt(a); + return e; + }), + (a.buf2string = function(t, e) { + var a, + i, + n, + r, + s = e || t.length, + o = new Array(2 * s); + for (a = i = 0; a < s; ) + if ((n = t[a++]) < 128) o[i++] = n; + else if (4 < (r = h[n])) (o[i++] = 65533), (a += r - 1); + else { + for (n &= 2 === r ? 31 : 3 === r ? 15 : 7; 1 < r && a < s; ) + (n = (n << 6) | (63 & t[a++])), r--; + 1 < r + ? (o[i++] = 65533) + : n < 65536 + ? (o[i++] = n) + : ((n -= 65536), + (o[i++] = 55296 | ((n >> 10) & 1023)), + (o[i++] = 56320 | (1023 & n))); + } + return d(o, i); + }), + (a.utf8border = function(t, e) { + var a; + for ( + (e = e || t.length) > t.length && (e = t.length), a = e - 1; + 0 <= a && 128 == (192 & t[a]); + + ) + a--; + return a < 0 ? e : 0 === a ? e : a + h[t[a]] > e ? a : e; + }); + }, + { './common': 3 } + ], + 5: [ + function(t, e, a) { + 'use strict'; + e.exports = function(t, e, a, i) { + for ( + var n = (65535 & t) | 0, r = ((t >>> 16) & 65535) | 0, s = 0; + 0 !== a; + + ) { + for ( + a -= s = 2e3 < a ? 2e3 : a; + (r = (r + (n = (n + e[i++]) | 0)) | 0), --s; + + ); + (n %= 65521), (r %= 65521); + } + return n | (r << 16) | 0; + }; + }, + {} + ], + 6: [ + function(t, e, a) { + 'use strict'; + e.exports = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + }, + {} + ], + 7: [ + function(t, e, a) { + 'use strict'; + var o = (function() { + for (var t, e = [], a = 0; a < 256; a++) { + t = a; + for (var i = 0; i < 8; i++) + t = 1 & t ? 3988292384 ^ (t >>> 1) : t >>> 1; + e[a] = t; + } + return e; + })(); + e.exports = function(t, e, a, i) { + var n = o, + r = i + a; + t ^= -1; + for (var s = i; s < r; s++) t = (t >>> 8) ^ n[255 & (t ^ e[s])]; + return -1 ^ t; + }; + }, + {} + ], + 8: [ + function(t, e, a) { + 'use strict'; + var l, + _ = t('../utils/common'), + h = t('./trees'), + u = t('./adler32'), + c = t('./crc32'), + i = t('./messages'), + d = 0, + f = 4, + b = 0, + g = -2, + m = -1, + w = 4, + n = 2, + p = 8, + v = 9, + r = 286, + s = 30, + o = 19, + k = 2 * r + 1, + y = 15, + x = 3, + z = 258, + B = z + x + 1, + S = 42, + E = 113, + A = 1, + Z = 2, + R = 3, + C = 4; + function N(t, e) { + return (t.msg = i[e]), e; + } + function O(t) { + return (t << 1) - (4 < t ? 9 : 0); + } + function D(t) { + for (var e = t.length; 0 <= --e; ) t[e] = 0; + } + function I(t) { + var e = t.state, + a = e.pending; + a > t.avail_out && (a = t.avail_out), + 0 !== a && + (_.arraySet( + t.output, + e.pending_buf, + e.pending_out, + a, + t.next_out + ), + (t.next_out += a), + (e.pending_out += a), + (t.total_out += a), + (t.avail_out -= a), + (e.pending -= a), + 0 === e.pending && (e.pending_out = 0)); + } + function U(t, e) { + h._tr_flush_block( + t, + 0 <= t.block_start ? t.block_start : -1, + t.strstart - t.block_start, + e + ), + (t.block_start = t.strstart), + I(t.strm); + } + function T(t, e) { + t.pending_buf[t.pending++] = e; + } + function F(t, e) { + (t.pending_buf[t.pending++] = (e >>> 8) & 255), + (t.pending_buf[t.pending++] = 255 & e); + } + function L(t, e) { + var a, + i, + n = t.max_chain_length, + r = t.strstart, + s = t.prev_length, + o = t.nice_match, + l = t.strstart > t.w_size - B ? t.strstart - (t.w_size - B) : 0, + h = t.window, + d = t.w_mask, + f = t.prev, + _ = t.strstart + z, + u = h[r + s - 1], + c = h[r + s]; + t.prev_length >= t.good_match && (n >>= 2), + o > t.lookahead && (o = t.lookahead); + do { + if ( + h[(a = e) + s] === c && + h[a + s - 1] === u && + h[a] === h[r] && + h[++a] === h[r + 1] + ) { + (r += 2), a++; + do {} while ( + h[++r] === h[++a] && + h[++r] === h[++a] && + h[++r] === h[++a] && + h[++r] === h[++a] && + h[++r] === h[++a] && + h[++r] === h[++a] && + h[++r] === h[++a] && + h[++r] === h[++a] && + r < _ + ); + if (((i = z - (_ - r)), (r = _ - z), s < i)) { + if (((t.match_start = e), o <= (s = i))) break; + (u = h[r + s - 1]), (c = h[r + s]); + } + } + } while ((e = f[e & d]) > l && 0 != --n); + return s <= t.lookahead ? s : t.lookahead; + } + function H(t) { + var e, + a, + i, + n, + r, + s, + o, + l, + h, + d, + f = t.w_size; + do { + if ( + ((n = t.window_size - t.lookahead - t.strstart), + t.strstart >= f + (f - B)) + ) { + for ( + _.arraySet(t.window, t.window, f, f, 0), + t.match_start -= f, + t.strstart -= f, + t.block_start -= f, + e = a = t.hash_size; + (i = t.head[--e]), (t.head[e] = f <= i ? i - f : 0), --a; + + ); + for ( + e = a = f; + (i = t.prev[--e]), (t.prev[e] = f <= i ? i - f : 0), --a; + + ); + n += f; + } + if (0 === t.strm.avail_in) break; + if ( + ((s = t.strm), + (o = t.window), + (l = t.strstart + t.lookahead), + (h = n), + (d = void 0), + (d = s.avail_in), + h < d && (d = h), + (a = + 0 === d + ? 0 + : ((s.avail_in -= d), + _.arraySet(o, s.input, s.next_in, d, l), + 1 === s.state.wrap + ? (s.adler = u(s.adler, o, d, l)) + : 2 === s.state.wrap && (s.adler = c(s.adler, o, d, l)), + (s.next_in += d), + (s.total_in += d), + d)), + (t.lookahead += a), + t.lookahead + t.insert >= x) + ) + for ( + r = t.strstart - t.insert, + t.ins_h = t.window[r], + t.ins_h = + ((t.ins_h << t.hash_shift) ^ t.window[r + 1]) & + t.hash_mask; + t.insert && + ((t.ins_h = + ((t.ins_h << t.hash_shift) ^ t.window[r + x - 1]) & + t.hash_mask), + (t.prev[r & t.w_mask] = t.head[t.ins_h]), + (t.head[t.ins_h] = r), + r++, + t.insert--, + !(t.lookahead + t.insert < x)); + + ); + } while (t.lookahead < B && 0 !== t.strm.avail_in); + } + function j(t, e) { + for (var a, i; ; ) { + if (t.lookahead < B) { + if ((H(t), t.lookahead < B && e === d)) return A; + if (0 === t.lookahead) break; + } + if ( + ((a = 0), + t.lookahead >= x && + ((t.ins_h = + ((t.ins_h << t.hash_shift) ^ t.window[t.strstart + x - 1]) & + t.hash_mask), + (a = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h]), + (t.head[t.ins_h] = t.strstart)), + 0 !== a && + t.strstart - a <= t.w_size - B && + (t.match_length = L(t, a)), + t.match_length >= x) + ) + if ( + ((i = h._tr_tally( + t, + t.strstart - t.match_start, + t.match_length - x + )), + (t.lookahead -= t.match_length), + t.match_length <= t.max_lazy_match && t.lookahead >= x) + ) { + for ( + t.match_length--; + t.strstart++, + (t.ins_h = + ((t.ins_h << t.hash_shift) ^ + t.window[t.strstart + x - 1]) & + t.hash_mask), + (a = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h]), + (t.head[t.ins_h] = t.strstart), + 0 != --t.match_length; + + ); + t.strstart++; + } else + (t.strstart += t.match_length), + (t.match_length = 0), + (t.ins_h = t.window[t.strstart]), + (t.ins_h = + ((t.ins_h << t.hash_shift) ^ t.window[t.strstart + 1]) & + t.hash_mask); + else + (i = h._tr_tally(t, 0, t.window[t.strstart])), + t.lookahead--, + t.strstart++; + if (i && (U(t, !1), 0 === t.strm.avail_out)) return A; + } + return ( + (t.insert = t.strstart < x - 1 ? t.strstart : x - 1), + e === f + ? (U(t, !0), 0 === t.strm.avail_out ? R : C) + : t.last_lit && (U(t, !1), 0 === t.strm.avail_out) + ? A + : Z + ); + } + function K(t, e) { + for (var a, i, n; ; ) { + if (t.lookahead < B) { + if ((H(t), t.lookahead < B && e === d)) return A; + if (0 === t.lookahead) break; + } + if ( + ((a = 0), + t.lookahead >= x && + ((t.ins_h = + ((t.ins_h << t.hash_shift) ^ t.window[t.strstart + x - 1]) & + t.hash_mask), + (a = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h]), + (t.head[t.ins_h] = t.strstart)), + (t.prev_length = t.match_length), + (t.prev_match = t.match_start), + (t.match_length = x - 1), + 0 !== a && + t.prev_length < t.max_lazy_match && + t.strstart - a <= t.w_size - B && + ((t.match_length = L(t, a)), + t.match_length <= 5 && + (1 === t.strategy || + (t.match_length === x && + 4096 < t.strstart - t.match_start)) && + (t.match_length = x - 1)), + t.prev_length >= x && t.match_length <= t.prev_length) + ) { + for ( + n = t.strstart + t.lookahead - x, + i = h._tr_tally( + t, + t.strstart - 1 - t.prev_match, + t.prev_length - x + ), + t.lookahead -= t.prev_length - 1, + t.prev_length -= 2; + ++t.strstart <= n && + ((t.ins_h = + ((t.ins_h << t.hash_shift) ^ + t.window[t.strstart + x - 1]) & + t.hash_mask), + (a = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h]), + (t.head[t.ins_h] = t.strstart)), + 0 != --t.prev_length; + + ); + if ( + ((t.match_available = 0), + (t.match_length = x - 1), + t.strstart++, + i && (U(t, !1), 0 === t.strm.avail_out)) + ) + return A; + } else if (t.match_available) { + if ( + ((i = h._tr_tally(t, 0, t.window[t.strstart - 1])) && + U(t, !1), + t.strstart++, + t.lookahead--, + 0 === t.strm.avail_out) + ) + return A; + } else (t.match_available = 1), t.strstart++, t.lookahead--; + } + return ( + t.match_available && + ((i = h._tr_tally(t, 0, t.window[t.strstart - 1])), + (t.match_available = 0)), + (t.insert = t.strstart < x - 1 ? t.strstart : x - 1), + e === f + ? (U(t, !0), 0 === t.strm.avail_out ? R : C) + : t.last_lit && (U(t, !1), 0 === t.strm.avail_out) + ? A + : Z + ); + } + function M(t, e, a, i, n) { + (this.good_length = t), + (this.max_lazy = e), + (this.nice_length = a), + (this.max_chain = i), + (this.func = n); + } + function P() { + (this.strm = null), + (this.status = 0), + (this.pending_buf = null), + (this.pending_buf_size = 0), + (this.pending_out = 0), + (this.pending = 0), + (this.wrap = 0), + (this.gzhead = null), + (this.gzindex = 0), + (this.method = p), + (this.last_flush = -1), + (this.w_size = 0), + (this.w_bits = 0), + (this.w_mask = 0), + (this.window = null), + (this.window_size = 0), + (this.prev = null), + (this.head = null), + (this.ins_h = 0), + (this.hash_size = 0), + (this.hash_bits = 0), + (this.hash_mask = 0), + (this.hash_shift = 0), + (this.block_start = 0), + (this.match_length = 0), + (this.prev_match = 0), + (this.match_available = 0), + (this.strstart = 0), + (this.match_start = 0), + (this.lookahead = 0), + (this.prev_length = 0), + (this.max_chain_length = 0), + (this.max_lazy_match = 0), + (this.level = 0), + (this.strategy = 0), + (this.good_match = 0), + (this.nice_match = 0), + (this.dyn_ltree = new _.Buf16(2 * k)), + (this.dyn_dtree = new _.Buf16(2 * (2 * s + 1))), + (this.bl_tree = new _.Buf16(2 * (2 * o + 1))), + D(this.dyn_ltree), + D(this.dyn_dtree), + D(this.bl_tree), + (this.l_desc = null), + (this.d_desc = null), + (this.bl_desc = null), + (this.bl_count = new _.Buf16(y + 1)), + (this.heap = new _.Buf16(2 * r + 1)), + D(this.heap), + (this.heap_len = 0), + (this.heap_max = 0), + (this.depth = new _.Buf16(2 * r + 1)), + D(this.depth), + (this.l_buf = 0), + (this.lit_bufsize = 0), + (this.last_lit = 0), + (this.d_buf = 0), + (this.opt_len = 0), + (this.static_len = 0), + (this.matches = 0), + (this.insert = 0), + (this.bi_buf = 0), + (this.bi_valid = 0); + } + function Y(t) { + var e; + return t && t.state + ? ((t.total_in = t.total_out = 0), + (t.data_type = n), + ((e = t.state).pending = 0), + (e.pending_out = 0), + e.wrap < 0 && (e.wrap = -e.wrap), + (e.status = e.wrap ? S : E), + (t.adler = 2 === e.wrap ? 0 : 1), + (e.last_flush = d), + h._tr_init(e), + b) + : N(t, g); + } + function q(t) { + var e, + a = Y(t); + return ( + a === b && + (((e = t.state).window_size = 2 * e.w_size), + D(e.head), + (e.max_lazy_match = l[e.level].max_lazy), + (e.good_match = l[e.level].good_length), + (e.nice_match = l[e.level].nice_length), + (e.max_chain_length = l[e.level].max_chain), + (e.strstart = 0), + (e.block_start = 0), + (e.lookahead = 0), + (e.insert = 0), + (e.match_length = e.prev_length = x - 1), + (e.match_available = 0), + (e.ins_h = 0)), + a + ); + } + function G(t, e, a, i, n, r) { + if (!t) return g; + var s = 1; + if ( + (e === m && (e = 6), + i < 0 ? ((s = 0), (i = -i)) : 15 < i && ((s = 2), (i -= 16)), + n < 1 || + v < n || + a !== p || + i < 8 || + 15 < i || + e < 0 || + 9 < e || + r < 0 || + w < r) + ) + return N(t, g); + 8 === i && (i = 9); + var o = new P(); + return ( + ((t.state = o).strm = t), + (o.wrap = s), + (o.gzhead = null), + (o.w_bits = i), + (o.w_size = 1 << o.w_bits), + (o.w_mask = o.w_size - 1), + (o.hash_bits = n + 7), + (o.hash_size = 1 << o.hash_bits), + (o.hash_mask = o.hash_size - 1), + (o.hash_shift = ~~((o.hash_bits + x - 1) / x)), + (o.window = new _.Buf8(2 * o.w_size)), + (o.head = new _.Buf16(o.hash_size)), + (o.prev = new _.Buf16(o.w_size)), + (o.lit_bufsize = 1 << (n + 6)), + (o.pending_buf_size = 4 * o.lit_bufsize), + (o.pending_buf = new _.Buf8(o.pending_buf_size)), + (o.d_buf = 1 * o.lit_bufsize), + (o.l_buf = 3 * o.lit_bufsize), + (o.level = e), + (o.strategy = r), + (o.method = a), + q(t) + ); + } + (l = [ + new M(0, 0, 0, 0, function(t, e) { + var a = 65535; + for ( + a > t.pending_buf_size - 5 && (a = t.pending_buf_size - 5); + ; + + ) { + if (t.lookahead <= 1) { + if ((H(t), 0 === t.lookahead && e === d)) return A; + if (0 === t.lookahead) break; + } + (t.strstart += t.lookahead), (t.lookahead = 0); + var i = t.block_start + a; + if ( + (0 === t.strstart || t.strstart >= i) && + ((t.lookahead = t.strstart - i), + (t.strstart = i), + U(t, !1), + 0 === t.strm.avail_out) + ) + return A; + if ( + t.strstart - t.block_start >= t.w_size - B && + (U(t, !1), 0 === t.strm.avail_out) + ) + return A; + } + return ( + (t.insert = 0), + e === f + ? (U(t, !0), 0 === t.strm.avail_out ? R : C) + : (t.strstart > t.block_start && (U(t, !1), t.strm.avail_out), + A) + ); + }), + new M(4, 4, 8, 4, j), + new M(4, 5, 16, 8, j), + new M(4, 6, 32, 32, j), + new M(4, 4, 16, 16, K), + new M(8, 16, 32, 32, K), + new M(8, 16, 128, 128, K), + new M(8, 32, 128, 256, K), + new M(32, 128, 258, 1024, K), + new M(32, 258, 258, 4096, K) + ]), + (a.deflateInit = function(t, e) { + return G(t, e, p, 15, 8, 0); + }), + (a.deflateInit2 = G), + (a.deflateReset = q), + (a.deflateResetKeep = Y), + (a.deflateSetHeader = function(t, e) { + return t && t.state + ? 2 !== t.state.wrap + ? g + : ((t.state.gzhead = e), b) + : g; + }), + (a.deflate = function(t, e) { + var a, i, n, r; + if (!t || !t.state || 5 < e || e < 0) return t ? N(t, g) : g; + if ( + ((i = t.state), + !t.output || + (!t.input && 0 !== t.avail_in) || + (666 === i.status && e !== f)) + ) + return N(t, 0 === t.avail_out ? -5 : g); + if ( + ((i.strm = t), + (a = i.last_flush), + (i.last_flush = e), + i.status === S) + ) + if (2 === i.wrap) + (t.adler = 0), + T(i, 31), + T(i, 139), + T(i, 8), + i.gzhead + ? (T( + i, + (i.gzhead.text ? 1 : 0) + + (i.gzhead.hcrc ? 2 : 0) + + (i.gzhead.extra ? 4 : 0) + + (i.gzhead.name ? 8 : 0) + + (i.gzhead.comment ? 16 : 0) + ), + T(i, 255 & i.gzhead.time), + T(i, (i.gzhead.time >> 8) & 255), + T(i, (i.gzhead.time >> 16) & 255), + T(i, (i.gzhead.time >> 24) & 255), + T( + i, + 9 === i.level + ? 2 + : 2 <= i.strategy || i.level < 2 + ? 4 + : 0 + ), + T(i, 255 & i.gzhead.os), + i.gzhead.extra && + i.gzhead.extra.length && + (T(i, 255 & i.gzhead.extra.length), + T(i, (i.gzhead.extra.length >> 8) & 255)), + i.gzhead.hcrc && + (t.adler = c(t.adler, i.pending_buf, i.pending, 0)), + (i.gzindex = 0), + (i.status = 69)) + : (T(i, 0), + T(i, 0), + T(i, 0), + T(i, 0), + T(i, 0), + T( + i, + 9 === i.level + ? 2 + : 2 <= i.strategy || i.level < 2 + ? 4 + : 0 + ), + T(i, 3), + (i.status = E)); + else { + var s = (p + ((i.w_bits - 8) << 4)) << 8; + (s |= + (2 <= i.strategy || i.level < 2 + ? 0 + : i.level < 6 + ? 1 + : 6 === i.level + ? 2 + : 3) << 6), + 0 !== i.strstart && (s |= 32), + (s += 31 - (s % 31)), + (i.status = E), + F(i, s), + 0 !== i.strstart && + (F(i, t.adler >>> 16), F(i, 65535 & t.adler)), + (t.adler = 1); + } + if (69 === i.status) + if (i.gzhead.extra) { + for ( + n = i.pending; + i.gzindex < (65535 & i.gzhead.extra.length) && + (i.pending !== i.pending_buf_size || + (i.gzhead.hcrc && + i.pending > n && + (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), + I(t), + (n = i.pending), + i.pending !== i.pending_buf_size)); + + ) + T(i, 255 & i.gzhead.extra[i.gzindex]), i.gzindex++; + i.gzhead.hcrc && + i.pending > n && + (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), + i.gzindex === i.gzhead.extra.length && + ((i.gzindex = 0), (i.status = 73)); + } else i.status = 73; + if (73 === i.status) + if (i.gzhead.name) { + n = i.pending; + do { + if ( + i.pending === i.pending_buf_size && + (i.gzhead.hcrc && + i.pending > n && + (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), + I(t), + (n = i.pending), + i.pending === i.pending_buf_size) + ) { + r = 1; + break; + } + T( + i, + (r = + i.gzindex < i.gzhead.name.length + ? 255 & i.gzhead.name.charCodeAt(i.gzindex++) + : 0) + ); + } while (0 !== r); + i.gzhead.hcrc && + i.pending > n && + (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), + 0 === r && ((i.gzindex = 0), (i.status = 91)); + } else i.status = 91; + if (91 === i.status) + if (i.gzhead.comment) { + n = i.pending; + do { + if ( + i.pending === i.pending_buf_size && + (i.gzhead.hcrc && + i.pending > n && + (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), + I(t), + (n = i.pending), + i.pending === i.pending_buf_size) + ) { + r = 1; + break; + } + T( + i, + (r = + i.gzindex < i.gzhead.comment.length + ? 255 & i.gzhead.comment.charCodeAt(i.gzindex++) + : 0) + ); + } while (0 !== r); + i.gzhead.hcrc && + i.pending > n && + (t.adler = c(t.adler, i.pending_buf, i.pending - n, n)), + 0 === r && (i.status = 103); + } else i.status = 103; + if ( + (103 === i.status && + (i.gzhead.hcrc + ? (i.pending + 2 > i.pending_buf_size && I(t), + i.pending + 2 <= i.pending_buf_size && + (T(i, 255 & t.adler), + T(i, (t.adler >> 8) & 255), + (t.adler = 0), + (i.status = E))) + : (i.status = E)), + 0 !== i.pending) + ) { + if ((I(t), 0 === t.avail_out)) return (i.last_flush = -1), b; + } else if (0 === t.avail_in && O(e) <= O(a) && e !== f) + return N(t, -5); + if (666 === i.status && 0 !== t.avail_in) return N(t, -5); + if ( + 0 !== t.avail_in || + 0 !== i.lookahead || + (e !== d && 666 !== i.status) + ) { + var o = + 2 === i.strategy + ? (function(t, e) { + for (var a; ; ) { + if (0 === t.lookahead && (H(t), 0 === t.lookahead)) { + if (e === d) return A; + break; + } + if ( + ((t.match_length = 0), + (a = h._tr_tally(t, 0, t.window[t.strstart])), + t.lookahead--, + t.strstart++, + a && (U(t, !1), 0 === t.strm.avail_out)) + ) + return A; + } + return ( + (t.insert = 0), + e === f + ? (U(t, !0), 0 === t.strm.avail_out ? R : C) + : t.last_lit && (U(t, !1), 0 === t.strm.avail_out) + ? A + : Z + ); + })(i, e) + : 3 === i.strategy + ? (function(t, e) { + for (var a, i, n, r, s = t.window; ; ) { + if (t.lookahead <= z) { + if ((H(t), t.lookahead <= z && e === d)) return A; + if (0 === t.lookahead) break; + } + if ( + ((t.match_length = 0), + t.lookahead >= x && + 0 < t.strstart && + (i = s[(n = t.strstart - 1)]) === s[++n] && + i === s[++n] && + i === s[++n]) + ) { + r = t.strstart + z; + do {} while ( + i === s[++n] && + i === s[++n] && + i === s[++n] && + i === s[++n] && + i === s[++n] && + i === s[++n] && + i === s[++n] && + i === s[++n] && + n < r + ); + (t.match_length = z - (r - n)), + t.match_length > t.lookahead && + (t.match_length = t.lookahead); + } + if ( + (t.match_length >= x + ? ((a = h._tr_tally(t, 1, t.match_length - x)), + (t.lookahead -= t.match_length), + (t.strstart += t.match_length), + (t.match_length = 0)) + : ((a = h._tr_tally(t, 0, t.window[t.strstart])), + t.lookahead--, + t.strstart++), + a && (U(t, !1), 0 === t.strm.avail_out)) + ) + return A; + } + return ( + (t.insert = 0), + e === f + ? (U(t, !0), 0 === t.strm.avail_out ? R : C) + : t.last_lit && (U(t, !1), 0 === t.strm.avail_out) + ? A + : Z + ); + })(i, e) + : l[i.level].func(i, e); + if ( + ((o !== R && o !== C) || (i.status = 666), o === A || o === R) + ) + return 0 === t.avail_out && (i.last_flush = -1), b; + if ( + o === Z && + (1 === e + ? h._tr_align(i) + : 5 !== e && + (h._tr_stored_block(i, 0, 0, !1), + 3 === e && + (D(i.head), + 0 === i.lookahead && + ((i.strstart = 0), + (i.block_start = 0), + (i.insert = 0)))), + I(t), + 0 === t.avail_out) + ) + return (i.last_flush = -1), b; + } + return e !== f + ? b + : i.wrap <= 0 + ? 1 + : (2 === i.wrap + ? (T(i, 255 & t.adler), + T(i, (t.adler >> 8) & 255), + T(i, (t.adler >> 16) & 255), + T(i, (t.adler >> 24) & 255), + T(i, 255 & t.total_in), + T(i, (t.total_in >> 8) & 255), + T(i, (t.total_in >> 16) & 255), + T(i, (t.total_in >> 24) & 255)) + : (F(i, t.adler >>> 16), F(i, 65535 & t.adler)), + I(t), + 0 < i.wrap && (i.wrap = -i.wrap), + 0 !== i.pending ? b : 1); + }), + (a.deflateEnd = function(t) { + var e; + return t && t.state + ? (e = t.state.status) !== S && + 69 !== e && + 73 !== e && + 91 !== e && + 103 !== e && + e !== E && + 666 !== e + ? N(t, g) + : ((t.state = null), e === E ? N(t, -3) : b) + : g; + }), + (a.deflateSetDictionary = function(t, e) { + var a, + i, + n, + r, + s, + o, + l, + h, + d = e.length; + if (!t || !t.state) return g; + if ( + 2 === (r = (a = t.state).wrap) || + (1 === r && a.status !== S) || + a.lookahead + ) + return g; + for ( + 1 === r && (t.adler = u(t.adler, e, d, 0)), + a.wrap = 0, + d >= a.w_size && + (0 === r && + (D(a.head), + (a.strstart = 0), + (a.block_start = 0), + (a.insert = 0)), + (h = new _.Buf8(a.w_size)), + _.arraySet(h, e, d - a.w_size, a.w_size, 0), + (e = h), + (d = a.w_size)), + s = t.avail_in, + o = t.next_in, + l = t.input, + t.avail_in = d, + t.next_in = 0, + t.input = e, + H(a); + a.lookahead >= x; + + ) { + for ( + i = a.strstart, n = a.lookahead - (x - 1); + (a.ins_h = + ((a.ins_h << a.hash_shift) ^ a.window[i + x - 1]) & + a.hash_mask), + (a.prev[i & a.w_mask] = a.head[a.ins_h]), + (a.head[a.ins_h] = i), + i++, + --n; + + ); + (a.strstart = i), (a.lookahead = x - 1), H(a); + } + return ( + (a.strstart += a.lookahead), + (a.block_start = a.strstart), + (a.insert = a.lookahead), + (a.lookahead = 0), + (a.match_length = a.prev_length = x - 1), + (a.match_available = 0), + (t.next_in = o), + (t.input = l), + (t.avail_in = s), + (a.wrap = r), + b + ); + }), + (a.deflateInfo = 'pako deflate (from Nodeca project)'); + }, + { + '../utils/common': 3, + './adler32': 5, + './crc32': 7, + './messages': 13, + './trees': 14 + } + ], + 9: [ + function(t, e, a) { + 'use strict'; + e.exports = function() { + (this.text = 0), + (this.time = 0), + (this.xflags = 0), + (this.os = 0), + (this.extra = null), + (this.extra_len = 0), + (this.name = ''), + (this.comment = ''), + (this.hcrc = 0), + (this.done = !1); + }; + }, + {} + ], + 10: [ + function(t, e, a) { + 'use strict'; + e.exports = function(t, e) { + var a, + i, + n, + r, + s, + o, + l, + h, + d, + f, + _, + u, + c, + b, + g, + m, + w, + p, + v, + k, + y, + x, + z, + B, + S; + (a = t.state), + (i = t.next_in), + (B = t.input), + (n = i + (t.avail_in - 5)), + (r = t.next_out), + (S = t.output), + (s = r - (e - t.avail_out)), + (o = r + (t.avail_out - 257)), + (l = a.dmax), + (h = a.wsize), + (d = a.whave), + (f = a.wnext), + (_ = a.window), + (u = a.hold), + (c = a.bits), + (b = a.lencode), + (g = a.distcode), + (m = (1 << a.lenbits) - 1), + (w = (1 << a.distbits) - 1); + t: do { + c < 15 && + ((u += B[i++] << c), (c += 8), (u += B[i++] << c), (c += 8)), + (p = b[u & m]); + e: for (;;) { + if ( + ((u >>>= v = p >>> 24), + (c -= v), + 0 === (v = (p >>> 16) & 255)) + ) + S[r++] = 65535 & p; + else { + if (!(16 & v)) { + if (0 == (64 & v)) { + p = b[(65535 & p) + (u & ((1 << v) - 1))]; + continue e; + } + if (32 & v) { + a.mode = 12; + break t; + } + (t.msg = 'invalid literal/length code'), (a.mode = 30); + break t; + } + (k = 65535 & p), + (v &= 15) && + (c < v && ((u += B[i++] << c), (c += 8)), + (k += u & ((1 << v) - 1)), + (u >>>= v), + (c -= v)), + c < 15 && + ((u += B[i++] << c), + (c += 8), + (u += B[i++] << c), + (c += 8)), + (p = g[u & w]); + a: for (;;) { + if ( + ((u >>>= v = p >>> 24), + (c -= v), + !(16 & (v = (p >>> 16) & 255))) + ) { + if (0 == (64 & v)) { + p = g[(65535 & p) + (u & ((1 << v) - 1))]; + continue a; + } + (t.msg = 'invalid distance code'), (a.mode = 30); + break t; + } + if ( + ((y = 65535 & p), + c < (v &= 15) && + ((u += B[i++] << c), + (c += 8) < v && ((u += B[i++] << c), (c += 8))), + l < (y += u & ((1 << v) - 1))) + ) { + (t.msg = 'invalid distance too far back'), (a.mode = 30); + break t; + } + if (((u >>>= v), (c -= v), (v = r - s) < y)) { + if (d < (v = y - v) && a.sane) { + (t.msg = 'invalid distance too far back'), + (a.mode = 30); + break t; + } + if (((z = _), (x = 0) === f)) { + if (((x += h - v), v < k)) { + for (k -= v; (S[r++] = _[x++]), --v; ); + (x = r - y), (z = S); + } + } else if (f < v) { + if (((x += h + f - v), (v -= f) < k)) { + for (k -= v; (S[r++] = _[x++]), --v; ); + if (((x = 0), f < k)) { + for (k -= v = f; (S[r++] = _[x++]), --v; ); + (x = r - y), (z = S); + } + } + } else if (((x += f - v), v < k)) { + for (k -= v; (S[r++] = _[x++]), --v; ); + (x = r - y), (z = S); + } + for (; 2 < k; ) + (S[r++] = z[x++]), + (S[r++] = z[x++]), + (S[r++] = z[x++]), + (k -= 3); + k && ((S[r++] = z[x++]), 1 < k && (S[r++] = z[x++])); + } else { + for ( + x = r - y; + (S[r++] = S[x++]), + (S[r++] = S[x++]), + (S[r++] = S[x++]), + 2 < (k -= 3); + + ); + k && ((S[r++] = S[x++]), 1 < k && (S[r++] = S[x++])); + } + break; + } + } + break; + } + } while (i < n && r < o); + (i -= k = c >> 3), + (u &= (1 << (c -= k << 3)) - 1), + (t.next_in = i), + (t.next_out = r), + (t.avail_in = i < n ? n - i + 5 : 5 - (i - n)), + (t.avail_out = r < o ? o - r + 257 : 257 - (r - o)), + (a.hold = u), + (a.bits = c); + }; + }, + {} + ], + 11: [ + function(t, e, a) { + 'use strict'; + var Z = t('../utils/common'), + R = t('./adler32'), + C = t('./crc32'), + N = t('./inffast'), + O = t('./inftrees'), + D = 1, + I = 2, + U = 0, + T = -2, + F = 1, + i = 852, + n = 592; + function L(t) { + return ( + ((t >>> 24) & 255) + + ((t >>> 8) & 65280) + + ((65280 & t) << 8) + + ((255 & t) << 24) + ); + } + function r() { + (this.mode = 0), + (this.last = !1), + (this.wrap = 0), + (this.havedict = !1), + (this.flags = 0), + (this.dmax = 0), + (this.check = 0), + (this.total = 0), + (this.head = null), + (this.wbits = 0), + (this.wsize = 0), + (this.whave = 0), + (this.wnext = 0), + (this.window = null), + (this.hold = 0), + (this.bits = 0), + (this.length = 0), + (this.offset = 0), + (this.extra = 0), + (this.lencode = null), + (this.distcode = null), + (this.lenbits = 0), + (this.distbits = 0), + (this.ncode = 0), + (this.nlen = 0), + (this.ndist = 0), + (this.have = 0), + (this.next = null), + (this.lens = new Z.Buf16(320)), + (this.work = new Z.Buf16(288)), + (this.lendyn = null), + (this.distdyn = null), + (this.sane = 0), + (this.back = 0), + (this.was = 0); + } + function s(t) { + var e; + return t && t.state + ? ((e = t.state), + (t.total_in = t.total_out = e.total = 0), + (t.msg = ''), + e.wrap && (t.adler = 1 & e.wrap), + (e.mode = F), + (e.last = 0), + (e.havedict = 0), + (e.dmax = 32768), + (e.head = null), + (e.hold = 0), + (e.bits = 0), + (e.lencode = e.lendyn = new Z.Buf32(i)), + (e.distcode = e.distdyn = new Z.Buf32(n)), + (e.sane = 1), + (e.back = -1), + U) + : T; + } + function o(t) { + var e; + return t && t.state + ? (((e = t.state).wsize = 0), (e.whave = 0), (e.wnext = 0), s(t)) + : T; + } + function l(t, e) { + var a, i; + return t && t.state + ? ((i = t.state), + e < 0 + ? ((a = 0), (e = -e)) + : ((a = 1 + (e >> 4)), e < 48 && (e &= 15)), + e && (e < 8 || 15 < e) + ? T + : (null !== i.window && i.wbits !== e && (i.window = null), + (i.wrap = a), + (i.wbits = e), + o(t))) + : T; + } + function h(t, e) { + var a, i; + return t + ? ((i = new r()), + ((t.state = i).window = null), + (a = l(t, e)) !== U && (t.state = null), + a) + : T; + } + var d, + f, + _ = !0; + function H(t) { + if (_) { + var e; + for (d = new Z.Buf32(512), f = new Z.Buf32(32), e = 0; e < 144; ) + t.lens[e++] = 8; + for (; e < 256; ) t.lens[e++] = 9; + for (; e < 280; ) t.lens[e++] = 7; + for (; e < 288; ) t.lens[e++] = 8; + for ( + O(D, t.lens, 0, 288, d, 0, t.work, { bits: 9 }), e = 0; + e < 32; + + ) + t.lens[e++] = 5; + O(I, t.lens, 0, 32, f, 0, t.work, { bits: 5 }), (_ = !1); + } + (t.lencode = d), + (t.lenbits = 9), + (t.distcode = f), + (t.distbits = 5); + } + function j(t, e, a, i) { + var n, + r = t.state; + return ( + null === r.window && + ((r.wsize = 1 << r.wbits), + (r.wnext = 0), + (r.whave = 0), + (r.window = new Z.Buf8(r.wsize))), + i >= r.wsize + ? (Z.arraySet(r.window, e, a - r.wsize, r.wsize, 0), + (r.wnext = 0), + (r.whave = r.wsize)) + : (i < (n = r.wsize - r.wnext) && (n = i), + Z.arraySet(r.window, e, a - i, n, r.wnext), + (i -= n) + ? (Z.arraySet(r.window, e, a - i, i, 0), + (r.wnext = i), + (r.whave = r.wsize)) + : ((r.wnext += n), + r.wnext === r.wsize && (r.wnext = 0), + r.whave < r.wsize && (r.whave += n))), + 0 + ); + } + (a.inflateReset = o), + (a.inflateReset2 = l), + (a.inflateResetKeep = s), + (a.inflateInit = function(t) { + return h(t, 15); + }), + (a.inflateInit2 = h), + (a.inflate = function(t, e) { + var a, + i, + n, + r, + s, + o, + l, + h, + d, + f, + _, + u, + c, + b, + g, + m, + w, + p, + v, + k, + y, + x, + z, + B, + S = 0, + E = new Z.Buf8(4), + A = [ + 16, + 17, + 18, + 0, + 8, + 7, + 9, + 6, + 10, + 5, + 11, + 4, + 12, + 3, + 13, + 2, + 14, + 1, + 15 + ]; + if (!t || !t.state || !t.output || (!t.input && 0 !== t.avail_in)) + return T; + 12 === (a = t.state).mode && (a.mode = 13), + (s = t.next_out), + (n = t.output), + (l = t.avail_out), + (r = t.next_in), + (i = t.input), + (o = t.avail_in), + (h = a.hold), + (d = a.bits), + (f = o), + (_ = l), + (x = U); + t: for (;;) + switch (a.mode) { + case F: + if (0 === a.wrap) { + a.mode = 13; + break; + } + for (; d < 16; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if (2 & a.wrap && 35615 === h) { + (E[(a.check = 0)] = 255 & h), + (E[1] = (h >>> 8) & 255), + (a.check = C(a.check, E, 2, 0)), + (d = h = 0), + (a.mode = 2); + break; + } + if ( + ((a.flags = 0), + a.head && (a.head.done = !1), + !(1 & a.wrap) || (((255 & h) << 8) + (h >> 8)) % 31) + ) { + (t.msg = 'incorrect header check'), (a.mode = 30); + break; + } + if (8 != (15 & h)) { + (t.msg = 'unknown compression method'), (a.mode = 30); + break; + } + if (((d -= 4), (y = 8 + (15 & (h >>>= 4))), 0 === a.wbits)) + a.wbits = y; + else if (y > a.wbits) { + (t.msg = 'invalid window size'), (a.mode = 30); + break; + } + (a.dmax = 1 << y), + (t.adler = a.check = 1), + (a.mode = 512 & h ? 10 : 12), + (d = h = 0); + break; + case 2: + for (; d < 16; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if (((a.flags = h), 8 != (255 & a.flags))) { + (t.msg = 'unknown compression method'), (a.mode = 30); + break; + } + if (57344 & a.flags) { + (t.msg = 'unknown header flags set'), (a.mode = 30); + break; + } + a.head && (a.head.text = (h >> 8) & 1), + 512 & a.flags && + ((E[0] = 255 & h), + (E[1] = (h >>> 8) & 255), + (a.check = C(a.check, E, 2, 0))), + (d = h = 0), + (a.mode = 3); + case 3: + for (; d < 32; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + a.head && (a.head.time = h), + 512 & a.flags && + ((E[0] = 255 & h), + (E[1] = (h >>> 8) & 255), + (E[2] = (h >>> 16) & 255), + (E[3] = (h >>> 24) & 255), + (a.check = C(a.check, E, 4, 0))), + (d = h = 0), + (a.mode = 4); + case 4: + for (; d < 16; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + a.head && ((a.head.xflags = 255 & h), (a.head.os = h >> 8)), + 512 & a.flags && + ((E[0] = 255 & h), + (E[1] = (h >>> 8) & 255), + (a.check = C(a.check, E, 2, 0))), + (d = h = 0), + (a.mode = 5); + case 5: + if (1024 & a.flags) { + for (; d < 16; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (a.length = h), + a.head && (a.head.extra_len = h), + 512 & a.flags && + ((E[0] = 255 & h), + (E[1] = (h >>> 8) & 255), + (a.check = C(a.check, E, 2, 0))), + (d = h = 0); + } else a.head && (a.head.extra = null); + a.mode = 6; + case 6: + if ( + 1024 & a.flags && + (o < (u = a.length) && (u = o), + u && + (a.head && + ((y = a.head.extra_len - a.length), + a.head.extra || + (a.head.extra = new Array(a.head.extra_len)), + Z.arraySet(a.head.extra, i, r, u, y)), + 512 & a.flags && (a.check = C(a.check, i, u, r)), + (o -= u), + (r += u), + (a.length -= u)), + a.length) + ) + break t; + (a.length = 0), (a.mode = 7); + case 7: + if (2048 & a.flags) { + if (0 === o) break t; + for ( + u = 0; + (y = i[r + u++]), + a.head && + y && + a.length < 65536 && + (a.head.name += String.fromCharCode(y)), + y && u < o; + + ); + if ( + (512 & a.flags && (a.check = C(a.check, i, u, r)), + (o -= u), + (r += u), + y) + ) + break t; + } else a.head && (a.head.name = null); + (a.length = 0), (a.mode = 8); + case 8: + if (4096 & a.flags) { + if (0 === o) break t; + for ( + u = 0; + (y = i[r + u++]), + a.head && + y && + a.length < 65536 && + (a.head.comment += String.fromCharCode(y)), + y && u < o; + + ); + if ( + (512 & a.flags && (a.check = C(a.check, i, u, r)), + (o -= u), + (r += u), + y) + ) + break t; + } else a.head && (a.head.comment = null); + a.mode = 9; + case 9: + if (512 & a.flags) { + for (; d < 16; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if (h !== (65535 & a.check)) { + (t.msg = 'header crc mismatch'), (a.mode = 30); + break; + } + d = h = 0; + } + a.head && + ((a.head.hcrc = (a.flags >> 9) & 1), (a.head.done = !0)), + (t.adler = a.check = 0), + (a.mode = 12); + break; + case 10: + for (; d < 32; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (t.adler = a.check = L(h)), (d = h = 0), (a.mode = 11); + case 11: + if (0 === a.havedict) + return ( + (t.next_out = s), + (t.avail_out = l), + (t.next_in = r), + (t.avail_in = o), + (a.hold = h), + (a.bits = d), + 2 + ); + (t.adler = a.check = 1), (a.mode = 12); + case 12: + if (5 === e || 6 === e) break t; + case 13: + if (a.last) { + (h >>>= 7 & d), (d -= 7 & d), (a.mode = 27); + break; + } + for (; d < 3; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + switch (((a.last = 1 & h), (d -= 1), 3 & (h >>>= 1))) { + case 0: + a.mode = 14; + break; + case 1: + if ((H(a), (a.mode = 20), 6 !== e)) break; + (h >>>= 2), (d -= 2); + break t; + case 2: + a.mode = 17; + break; + case 3: + (t.msg = 'invalid block type'), (a.mode = 30); + } + (h >>>= 2), (d -= 2); + break; + case 14: + for (h >>>= 7 & d, d -= 7 & d; d < 32; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if ((65535 & h) != ((h >>> 16) ^ 65535)) { + (t.msg = 'invalid stored block lengths'), (a.mode = 30); + break; + } + if ( + ((a.length = 65535 & h), + (d = h = 0), + (a.mode = 15), + 6 === e) + ) + break t; + case 15: + a.mode = 16; + case 16: + if ((u = a.length)) { + if ((o < u && (u = o), l < u && (u = l), 0 === u)) + break t; + Z.arraySet(n, i, r, u, s), + (o -= u), + (r += u), + (l -= u), + (s += u), + (a.length -= u); + break; + } + a.mode = 12; + break; + case 17: + for (; d < 14; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if ( + ((a.nlen = 257 + (31 & h)), + (h >>>= 5), + (d -= 5), + (a.ndist = 1 + (31 & h)), + (h >>>= 5), + (d -= 5), + (a.ncode = 4 + (15 & h)), + (h >>>= 4), + (d -= 4), + 286 < a.nlen || 30 < a.ndist) + ) { + (t.msg = 'too many length or distance symbols'), + (a.mode = 30); + break; + } + (a.have = 0), (a.mode = 18); + case 18: + for (; a.have < a.ncode; ) { + for (; d < 3; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (a.lens[A[a.have++]] = 7 & h), (h >>>= 3), (d -= 3); + } + for (; a.have < 19; ) a.lens[A[a.have++]] = 0; + if ( + ((a.lencode = a.lendyn), + (a.lenbits = 7), + (z = { bits: a.lenbits }), + (x = O(0, a.lens, 0, 19, a.lencode, 0, a.work, z)), + (a.lenbits = z.bits), + x) + ) { + (t.msg = 'invalid code lengths set'), (a.mode = 30); + break; + } + (a.have = 0), (a.mode = 19); + case 19: + for (; a.have < a.nlen + a.ndist; ) { + for ( + ; + (m = + ((S = a.lencode[h & ((1 << a.lenbits) - 1)]) >>> 16) & + 255), + (w = 65535 & S), + !((g = S >>> 24) <= d); + + ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if (w < 16) (h >>>= g), (d -= g), (a.lens[a.have++] = w); + else { + if (16 === w) { + for (B = g + 2; d < B; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if (((h >>>= g), (d -= g), 0 === a.have)) { + (t.msg = 'invalid bit length repeat'), + (a.mode = 30); + break; + } + (y = a.lens[a.have - 1]), + (u = 3 + (3 & h)), + (h >>>= 2), + (d -= 2); + } else if (17 === w) { + for (B = g + 3; d < B; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (d -= g), + (y = 0), + (u = 3 + (7 & (h >>>= g))), + (h >>>= 3), + (d -= 3); + } else { + for (B = g + 7; d < B; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (d -= g), + (y = 0), + (u = 11 + (127 & (h >>>= g))), + (h >>>= 7), + (d -= 7); + } + if (a.have + u > a.nlen + a.ndist) { + (t.msg = 'invalid bit length repeat'), (a.mode = 30); + break; + } + for (; u--; ) a.lens[a.have++] = y; + } + } + if (30 === a.mode) break; + if (0 === a.lens[256]) { + (t.msg = 'invalid code -- missing end-of-block'), + (a.mode = 30); + break; + } + if ( + ((a.lenbits = 9), + (z = { bits: a.lenbits }), + (x = O(D, a.lens, 0, a.nlen, a.lencode, 0, a.work, z)), + (a.lenbits = z.bits), + x) + ) { + (t.msg = 'invalid literal/lengths set'), (a.mode = 30); + break; + } + if ( + ((a.distbits = 6), + (a.distcode = a.distdyn), + (z = { bits: a.distbits }), + (x = O( + I, + a.lens, + a.nlen, + a.ndist, + a.distcode, + 0, + a.work, + z + )), + (a.distbits = z.bits), + x) + ) { + (t.msg = 'invalid distances set'), (a.mode = 30); + break; + } + if (((a.mode = 20), 6 === e)) break t; + case 20: + a.mode = 21; + case 21: + if (6 <= o && 258 <= l) { + (t.next_out = s), + (t.avail_out = l), + (t.next_in = r), + (t.avail_in = o), + (a.hold = h), + (a.bits = d), + N(t, _), + (s = t.next_out), + (n = t.output), + (l = t.avail_out), + (r = t.next_in), + (i = t.input), + (o = t.avail_in), + (h = a.hold), + (d = a.bits), + 12 === a.mode && (a.back = -1); + break; + } + for ( + a.back = 0; + (m = + ((S = a.lencode[h & ((1 << a.lenbits) - 1)]) >>> 16) & + 255), + (w = 65535 & S), + !((g = S >>> 24) <= d); + + ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if (m && 0 == (240 & m)) { + for ( + p = g, v = m, k = w; + (m = + ((S = + a.lencode[ + k + ((h & ((1 << (p + v)) - 1)) >> p) + ]) >>> + 16) & + 255), + (w = 65535 & S), + !(p + (g = S >>> 24) <= d); + + ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (h >>>= p), (d -= p), (a.back += p); + } + if ( + ((h >>>= g), + (d -= g), + (a.back += g), + (a.length = w), + 0 === m) + ) { + a.mode = 26; + break; + } + if (32 & m) { + (a.back = -1), (a.mode = 12); + break; + } + if (64 & m) { + (t.msg = 'invalid literal/length code'), (a.mode = 30); + break; + } + (a.extra = 15 & m), (a.mode = 22); + case 22: + if (a.extra) { + for (B = a.extra; d < B; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (a.length += h & ((1 << a.extra) - 1)), + (h >>>= a.extra), + (d -= a.extra), + (a.back += a.extra); + } + (a.was = a.length), (a.mode = 23); + case 23: + for ( + ; + (m = + ((S = a.distcode[h & ((1 << a.distbits) - 1)]) >>> 16) & + 255), + (w = 65535 & S), + !((g = S >>> 24) <= d); + + ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if (0 == (240 & m)) { + for ( + p = g, v = m, k = w; + (m = + ((S = + a.distcode[ + k + ((h & ((1 << (p + v)) - 1)) >> p) + ]) >>> + 16) & + 255), + (w = 65535 & S), + !(p + (g = S >>> 24) <= d); + + ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (h >>>= p), (d -= p), (a.back += p); + } + if (((h >>>= g), (d -= g), (a.back += g), 64 & m)) { + (t.msg = 'invalid distance code'), (a.mode = 30); + break; + } + (a.offset = w), (a.extra = 15 & m), (a.mode = 24); + case 24: + if (a.extra) { + for (B = a.extra; d < B; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + (a.offset += h & ((1 << a.extra) - 1)), + (h >>>= a.extra), + (d -= a.extra), + (a.back += a.extra); + } + if (a.offset > a.dmax) { + (t.msg = 'invalid distance too far back'), (a.mode = 30); + break; + } + a.mode = 25; + case 25: + if (0 === l) break t; + if (((u = _ - l), a.offset > u)) { + if ((u = a.offset - u) > a.whave && a.sane) { + (t.msg = 'invalid distance too far back'), + (a.mode = 30); + break; + } + u > a.wnext + ? ((u -= a.wnext), (c = a.wsize - u)) + : (c = a.wnext - u), + u > a.length && (u = a.length), + (b = a.window); + } else (b = n), (c = s - a.offset), (u = a.length); + for ( + l < u && (u = l), l -= u, a.length -= u; + (n[s++] = b[c++]), --u; + + ); + 0 === a.length && (a.mode = 21); + break; + case 26: + if (0 === l) break t; + (n[s++] = a.length), l--, (a.mode = 21); + break; + case 27: + if (a.wrap) { + for (; d < 32; ) { + if (0 === o) break t; + o--, (h |= i[r++] << d), (d += 8); + } + if ( + ((_ -= l), + (t.total_out += _), + (a.total += _), + _ && + (t.adler = a.check = a.flags + ? C(a.check, n, _, s - _) + : R(a.check, n, _, s - _)), + (_ = l), + (a.flags ? h : L(h)) !== a.check) + ) { + (t.msg = 'incorrect data check'), (a.mode = 30); + break; + } + d = h = 0; + } + a.mode = 28; + case 28: + if (a.wrap && a.flags) { + for (; d < 32; ) { + if (0 === o) break t; + o--, (h += i[r++] << d), (d += 8); + } + if (h !== (4294967295 & a.total)) { + (t.msg = 'incorrect length check'), (a.mode = 30); + break; + } + d = h = 0; + } + a.mode = 29; + case 29: + x = 1; + break t; + case 30: + x = -3; + break t; + case 31: + return -4; + case 32: + default: + return T; + } + return ( + (t.next_out = s), + (t.avail_out = l), + (t.next_in = r), + (t.avail_in = o), + (a.hold = h), + (a.bits = d), + (a.wsize || + (_ !== t.avail_out && + a.mode < 30 && + (a.mode < 27 || 4 !== e))) && + j(t, t.output, t.next_out, _ - t.avail_out) + ? ((a.mode = 31), -4) + : ((f -= t.avail_in), + (_ -= t.avail_out), + (t.total_in += f), + (t.total_out += _), + (a.total += _), + a.wrap && + _ && + (t.adler = a.check = a.flags + ? C(a.check, n, _, t.next_out - _) + : R(a.check, n, _, t.next_out - _)), + (t.data_type = + a.bits + + (a.last ? 64 : 0) + + (12 === a.mode ? 128 : 0) + + (20 === a.mode || 15 === a.mode ? 256 : 0)), + ((0 === f && 0 === _) || 4 === e) && x === U && (x = -5), + x) + ); + }), + (a.inflateEnd = function(t) { + if (!t || !t.state) return T; + var e = t.state; + return e.window && (e.window = null), (t.state = null), U; + }), + (a.inflateGetHeader = function(t, e) { + var a; + return t && t.state + ? 0 == (2 & (a = t.state).wrap) + ? T + : (((a.head = e).done = !1), U) + : T; + }), + (a.inflateSetDictionary = function(t, e) { + var a, + i = e.length; + return t && t.state + ? 0 !== (a = t.state).wrap && 11 !== a.mode + ? T + : 11 === a.mode && R(1, e, i, 0) !== a.check + ? -3 + : j(t, e, i, i) + ? ((a.mode = 31), -4) + : ((a.havedict = 1), U) + : T; + }), + (a.inflateInfo = 'pako inflate (from Nodeca project)'); + }, + { + '../utils/common': 3, + './adler32': 5, + './crc32': 7, + './inffast': 10, + './inftrees': 12 + } + ], + 12: [ + function(t, e, a) { + 'use strict'; + var D = t('../utils/common'), + I = [ + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 13, + 15, + 17, + 19, + 23, + 27, + 31, + 35, + 43, + 51, + 59, + 67, + 83, + 99, + 115, + 131, + 163, + 195, + 227, + 258, + 0, + 0 + ], + U = [ + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 17, + 17, + 17, + 17, + 18, + 18, + 18, + 18, + 19, + 19, + 19, + 19, + 20, + 20, + 20, + 20, + 21, + 21, + 21, + 21, + 16, + 72, + 78 + ], + T = [ + 1, + 2, + 3, + 4, + 5, + 7, + 9, + 13, + 17, + 25, + 33, + 49, + 65, + 97, + 129, + 193, + 257, + 385, + 513, + 769, + 1025, + 1537, + 2049, + 3073, + 4097, + 6145, + 8193, + 12289, + 16385, + 24577, + 0, + 0 + ], + F = [ + 16, + 16, + 16, + 16, + 17, + 17, + 18, + 18, + 19, + 19, + 20, + 20, + 21, + 21, + 22, + 22, + 23, + 23, + 24, + 24, + 25, + 25, + 26, + 26, + 27, + 27, + 28, + 28, + 29, + 29, + 64, + 64 + ]; + e.exports = function(t, e, a, i, n, r, s, o) { + var l, + h, + d, + f, + _, + u, + c, + b, + g, + m = o.bits, + w = 0, + p = 0, + v = 0, + k = 0, + y = 0, + x = 0, + z = 0, + B = 0, + S = 0, + E = 0, + A = null, + Z = 0, + R = new D.Buf16(16), + C = new D.Buf16(16), + N = null, + O = 0; + for (w = 0; w <= 15; w++) R[w] = 0; + for (p = 0; p < i; p++) R[e[a + p]]++; + for (y = m, k = 15; 1 <= k && 0 === R[k]; k--); + if ((k < y && (y = k), 0 === k)) + return (n[r++] = 20971520), (n[r++] = 20971520), (o.bits = 1), 0; + for (v = 1; v < k && 0 === R[v]; v++); + for (y < v && (y = v), w = B = 1; w <= 15; w++) + if (((B <<= 1), (B -= R[w]) < 0)) return -1; + if (0 < B && (0 === t || 1 !== k)) return -1; + for (C[1] = 0, w = 1; w < 15; w++) C[w + 1] = C[w] + R[w]; + for (p = 0; p < i; p++) 0 !== e[a + p] && (s[C[e[a + p]]++] = p); + if ( + (0 === t + ? ((A = N = s), (u = 19)) + : 1 === t + ? ((A = I), (Z -= 257), (N = U), (O -= 257), (u = 256)) + : ((A = T), (N = F), (u = -1)), + (w = v), + (_ = r), + (z = p = E = 0), + (d = -1), + (f = (S = 1 << (x = y)) - 1), + (1 === t && 852 < S) || (2 === t && 592 < S)) + ) + return 1; + for (;;) { + for ( + c = w - z, + s[p] < u + ? ((b = 0), (g = s[p])) + : s[p] > u + ? ((b = N[O + s[p]]), (g = A[Z + s[p]])) + : ((b = 96), (g = 0)), + l = 1 << (w - z), + v = h = 1 << x; + (n[_ + (E >> z) + (h -= l)] = (c << 24) | (b << 16) | g | 0), + 0 !== h; + + ); + for (l = 1 << (w - 1); E & l; ) l >>= 1; + if ( + (0 !== l ? ((E &= l - 1), (E += l)) : (E = 0), p++, 0 == --R[w]) + ) { + if (w === k) break; + w = e[a + s[p]]; + } + if (y < w && (E & f) !== d) { + for ( + 0 === z && (z = y), _ += v, B = 1 << (x = w - z); + x + z < k && !((B -= R[x + z]) <= 0); + + ) + x++, (B <<= 1); + if ( + ((S += 1 << x), (1 === t && 852 < S) || (2 === t && 592 < S)) + ) + return 1; + n[(d = E & f)] = (y << 24) | (x << 16) | (_ - r) | 0; + } + } + return ( + 0 !== E && (n[_ + E] = ((w - z) << 24) | (64 << 16) | 0), + (o.bits = y), + 0 + ); + }; + }, + { '../utils/common': 3 } + ], + 13: [ + function(t, e, a) { + 'use strict'; + e.exports = { + 2: 'need dictionary', + 1: 'stream end', + 0: '', + '-1': 'file error', + '-2': 'stream error', + '-3': 'data error', + '-4': 'insufficient memory', + '-5': 'buffer error', + '-6': 'incompatible version' + }; + }, + {} + ], + 14: [ + function(t, e, a) { + 'use strict'; + var l = t('../utils/common'), + o = 0, + h = 1; + function i(t) { + for (var e = t.length; 0 <= --e; ) t[e] = 0; + } + var d = 0, + s = 29, + f = 256, + _ = f + 1 + s, + u = 30, + c = 19, + g = 2 * _ + 1, + m = 15, + n = 16, + b = 7, + w = 256, + p = 16, + v = 17, + k = 18, + y = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 2, + 2, + 2, + 2, + 3, + 3, + 3, + 3, + 4, + 4, + 4, + 4, + 5, + 5, + 5, + 5, + 0 + ], + x = [ + 0, + 0, + 0, + 0, + 1, + 1, + 2, + 2, + 3, + 3, + 4, + 4, + 5, + 5, + 6, + 6, + 7, + 7, + 8, + 8, + 9, + 9, + 10, + 10, + 11, + 11, + 12, + 12, + 13, + 13 + ], + z = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7], + B = [ + 16, + 17, + 18, + 0, + 8, + 7, + 9, + 6, + 10, + 5, + 11, + 4, + 12, + 3, + 13, + 2, + 14, + 1, + 15 + ], + S = new Array(2 * (_ + 2)); + i(S); + var E = new Array(2 * u); + i(E); + var A = new Array(512); + i(A); + var Z = new Array(256); + i(Z); + var R = new Array(s); + i(R); + var C, + N, + O, + D = new Array(u); + function I(t, e, a, i, n) { + (this.static_tree = t), + (this.extra_bits = e), + (this.extra_base = a), + (this.elems = i), + (this.max_length = n), + (this.has_stree = t && t.length); + } + function r(t, e) { + (this.dyn_tree = t), (this.max_code = 0), (this.stat_desc = e); + } + function U(t) { + return t < 256 ? A[t] : A[256 + (t >>> 7)]; + } + function T(t, e) { + (t.pending_buf[t.pending++] = 255 & e), + (t.pending_buf[t.pending++] = (e >>> 8) & 255); + } + function F(t, e, a) { + t.bi_valid > n - a + ? ((t.bi_buf |= (e << t.bi_valid) & 65535), + T(t, t.bi_buf), + (t.bi_buf = e >> (n - t.bi_valid)), + (t.bi_valid += a - n)) + : ((t.bi_buf |= (e << t.bi_valid) & 65535), (t.bi_valid += a)); + } + function L(t, e, a) { + F(t, a[2 * e], a[2 * e + 1]); + } + function H(t, e) { + for (var a = 0; (a |= 1 & t), (t >>>= 1), (a <<= 1), 0 < --e; ); + return a >>> 1; + } + function j(t, e, a) { + var i, + n, + r = new Array(m + 1), + s = 0; + for (i = 1; i <= m; i++) r[i] = s = (s + a[i - 1]) << 1; + for (n = 0; n <= e; n++) { + var o = t[2 * n + 1]; + 0 !== o && (t[2 * n] = H(r[o]++, o)); + } + } + function K(t) { + var e; + for (e = 0; e < _; e++) t.dyn_ltree[2 * e] = 0; + for (e = 0; e < u; e++) t.dyn_dtree[2 * e] = 0; + for (e = 0; e < c; e++) t.bl_tree[2 * e] = 0; + (t.dyn_ltree[2 * w] = 1), + (t.opt_len = t.static_len = 0), + (t.last_lit = t.matches = 0); + } + function M(t) { + 8 < t.bi_valid + ? T(t, t.bi_buf) + : 0 < t.bi_valid && (t.pending_buf[t.pending++] = t.bi_buf), + (t.bi_buf = 0), + (t.bi_valid = 0); + } + function P(t, e, a, i) { + var n = 2 * e, + r = 2 * a; + return t[n] < t[r] || (t[n] === t[r] && i[e] <= i[a]); + } + function Y(t, e, a) { + for ( + var i = t.heap[a], n = a << 1; + n <= t.heap_len && + (n < t.heap_len && P(e, t.heap[n + 1], t.heap[n], t.depth) && n++, + !P(e, i, t.heap[n], t.depth)); + + ) + (t.heap[a] = t.heap[n]), (a = n), (n <<= 1); + t.heap[a] = i; + } + function q(t, e, a) { + var i, + n, + r, + s, + o = 0; + if (0 !== t.last_lit) + for ( + ; + (i = + (t.pending_buf[t.d_buf + 2 * o] << 8) | + t.pending_buf[t.d_buf + 2 * o + 1]), + (n = t.pending_buf[t.l_buf + o]), + o++, + 0 === i + ? L(t, n, e) + : (L(t, (r = Z[n]) + f + 1, e), + 0 !== (s = y[r]) && F(t, (n -= R[r]), s), + L(t, (r = U(--i)), a), + 0 !== (s = x[r]) && F(t, (i -= D[r]), s)), + o < t.last_lit; + + ); + L(t, w, e); + } + function G(t, e) { + var a, + i, + n, + r = e.dyn_tree, + s = e.stat_desc.static_tree, + o = e.stat_desc.has_stree, + l = e.stat_desc.elems, + h = -1; + for (t.heap_len = 0, t.heap_max = g, a = 0; a < l; a++) + 0 !== r[2 * a] + ? ((t.heap[++t.heap_len] = h = a), (t.depth[a] = 0)) + : (r[2 * a + 1] = 0); + for (; t.heap_len < 2; ) + (r[2 * (n = t.heap[++t.heap_len] = h < 2 ? ++h : 0)] = 1), + (t.depth[n] = 0), + t.opt_len--, + o && (t.static_len -= s[2 * n + 1]); + for (e.max_code = h, a = t.heap_len >> 1; 1 <= a; a--) Y(t, r, a); + for ( + n = l; + (a = t.heap[1]), + (t.heap[1] = t.heap[t.heap_len--]), + Y(t, r, 1), + (i = t.heap[1]), + (t.heap[--t.heap_max] = a), + (t.heap[--t.heap_max] = i), + (r[2 * n] = r[2 * a] + r[2 * i]), + (t.depth[n] = + (t.depth[a] >= t.depth[i] ? t.depth[a] : t.depth[i]) + 1), + (r[2 * a + 1] = r[2 * i + 1] = n), + (t.heap[1] = n++), + Y(t, r, 1), + 2 <= t.heap_len; + + ); + (t.heap[--t.heap_max] = t.heap[1]), + (function(t, e) { + var a, + i, + n, + r, + s, + o, + l = e.dyn_tree, + h = e.max_code, + d = e.stat_desc.static_tree, + f = e.stat_desc.has_stree, + _ = e.stat_desc.extra_bits, + u = e.stat_desc.extra_base, + c = e.stat_desc.max_length, + b = 0; + for (r = 0; r <= m; r++) t.bl_count[r] = 0; + for ( + l[2 * t.heap[t.heap_max] + 1] = 0, a = t.heap_max + 1; + a < g; + a++ + ) + c < (r = l[2 * l[2 * (i = t.heap[a]) + 1] + 1] + 1) && + ((r = c), b++), + (l[2 * i + 1] = r), + h < i || + (t.bl_count[r]++, + (s = 0), + u <= i && (s = _[i - u]), + (o = l[2 * i]), + (t.opt_len += o * (r + s)), + f && (t.static_len += o * (d[2 * i + 1] + s))); + if (0 !== b) { + do { + for (r = c - 1; 0 === t.bl_count[r]; ) r--; + t.bl_count[r]--, + (t.bl_count[r + 1] += 2), + t.bl_count[c]--, + (b -= 2); + } while (0 < b); + for (r = c; 0 !== r; r--) + for (i = t.bl_count[r]; 0 !== i; ) + h < (n = t.heap[--a]) || + (l[2 * n + 1] !== r && + ((t.opt_len += (r - l[2 * n + 1]) * l[2 * n]), + (l[2 * n + 1] = r)), + i--); + } + })(t, e), + j(r, h, t.bl_count); + } + function X(t, e, a) { + var i, + n, + r = -1, + s = e[1], + o = 0, + l = 7, + h = 4; + for ( + 0 === s && ((l = 138), (h = 3)), + e[2 * (a + 1) + 1] = 65535, + i = 0; + i <= a; + i++ + ) + (n = s), + (s = e[2 * (i + 1) + 1]), + (++o < l && n === s) || + (o < h + ? (t.bl_tree[2 * n] += o) + : 0 !== n + ? (n !== r && t.bl_tree[2 * n]++, t.bl_tree[2 * p]++) + : o <= 10 + ? t.bl_tree[2 * v]++ + : t.bl_tree[2 * k]++, + (r = n), + (o = 0) === s + ? ((l = 138), (h = 3)) + : n === s + ? ((l = 6), (h = 3)) + : ((l = 7), (h = 4))); + } + function W(t, e, a) { + var i, + n, + r = -1, + s = e[1], + o = 0, + l = 7, + h = 4; + for (0 === s && ((l = 138), (h = 3)), i = 0; i <= a; i++) + if (((n = s), (s = e[2 * (i + 1) + 1]), !(++o < l && n === s))) { + if (o < h) for (; L(t, n, t.bl_tree), 0 != --o; ); + else + 0 !== n + ? (n !== r && (L(t, n, t.bl_tree), o--), + L(t, p, t.bl_tree), + F(t, o - 3, 2)) + : o <= 10 + ? (L(t, v, t.bl_tree), F(t, o - 3, 3)) + : (L(t, k, t.bl_tree), F(t, o - 11, 7)); + (r = n), + (o = 0) === s + ? ((l = 138), (h = 3)) + : n === s + ? ((l = 6), (h = 3)) + : ((l = 7), (h = 4)); + } + } + i(D); + var J = !1; + function Q(t, e, a, i) { + var n, r, s, o; + F(t, (d << 1) + (i ? 1 : 0), 3), + (r = e), + (s = a), + (o = !0), + M((n = t)), + o && (T(n, s), T(n, ~s)), + l.arraySet(n.pending_buf, n.window, r, s, n.pending), + (n.pending += s); + } + (a._tr_init = function(t) { + J || + ((function() { + var t, + e, + a, + i, + n, + r = new Array(m + 1); + for (i = a = 0; i < s - 1; i++) + for (R[i] = a, t = 0; t < 1 << y[i]; t++) Z[a++] = i; + for (Z[a - 1] = i, i = n = 0; i < 16; i++) + for (D[i] = n, t = 0; t < 1 << x[i]; t++) A[n++] = i; + for (n >>= 7; i < u; i++) + for (D[i] = n << 7, t = 0; t < 1 << (x[i] - 7); t++) + A[256 + n++] = i; + for (e = 0; e <= m; e++) r[e] = 0; + for (t = 0; t <= 143; ) (S[2 * t + 1] = 8), t++, r[8]++; + for (; t <= 255; ) (S[2 * t + 1] = 9), t++, r[9]++; + for (; t <= 279; ) (S[2 * t + 1] = 7), t++, r[7]++; + for (; t <= 287; ) (S[2 * t + 1] = 8), t++, r[8]++; + for (j(S, _ + 1, r), t = 0; t < u; t++) + (E[2 * t + 1] = 5), (E[2 * t] = H(t, 5)); + (C = new I(S, y, f + 1, _, m)), + (N = new I(E, x, 0, u, m)), + (O = new I(new Array(0), z, 0, c, b)); + })(), + (J = !0)), + (t.l_desc = new r(t.dyn_ltree, C)), + (t.d_desc = new r(t.dyn_dtree, N)), + (t.bl_desc = new r(t.bl_tree, O)), + (t.bi_buf = 0), + (t.bi_valid = 0), + K(t); + }), + (a._tr_stored_block = Q), + (a._tr_flush_block = function(t, e, a, i) { + var n, + r, + s = 0; + 0 < t.level + ? (2 === t.strm.data_type && + (t.strm.data_type = (function(t) { + var e, + a = 4093624447; + for (e = 0; e <= 31; e++, a >>>= 1) + if (1 & a && 0 !== t.dyn_ltree[2 * e]) return o; + if ( + 0 !== t.dyn_ltree[18] || + 0 !== t.dyn_ltree[20] || + 0 !== t.dyn_ltree[26] + ) + return h; + for (e = 32; e < f; e++) + if (0 !== t.dyn_ltree[2 * e]) return h; + return o; + })(t)), + G(t, t.l_desc), + G(t, t.d_desc), + (s = (function(t) { + var e; + for ( + X(t, t.dyn_ltree, t.l_desc.max_code), + X(t, t.dyn_dtree, t.d_desc.max_code), + G(t, t.bl_desc), + e = c - 1; + 3 <= e && 0 === t.bl_tree[2 * B[e] + 1]; + e-- + ); + return (t.opt_len += 3 * (e + 1) + 5 + 5 + 4), e; + })(t)), + (n = (t.opt_len + 3 + 7) >>> 3), + (r = (t.static_len + 3 + 7) >>> 3) <= n && (n = r)) + : (n = r = a + 5), + a + 4 <= n && -1 !== e + ? Q(t, e, a, i) + : 4 === t.strategy || r === n + ? (F(t, 2 + (i ? 1 : 0), 3), q(t, S, E)) + : (F(t, 4 + (i ? 1 : 0), 3), + (function(t, e, a, i) { + var n; + for ( + F(t, e - 257, 5), F(t, a - 1, 5), F(t, i - 4, 4), n = 0; + n < i; + n++ + ) + F(t, t.bl_tree[2 * B[n] + 1], 3); + W(t, t.dyn_ltree, e - 1), W(t, t.dyn_dtree, a - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, s + 1), + q(t, t.dyn_ltree, t.dyn_dtree)), + K(t), + i && M(t); + }), + (a._tr_tally = function(t, e, a) { + return ( + (t.pending_buf[t.d_buf + 2 * t.last_lit] = (e >>> 8) & 255), + (t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e), + (t.pending_buf[t.l_buf + t.last_lit] = 255 & a), + t.last_lit++, + 0 === e + ? t.dyn_ltree[2 * a]++ + : (t.matches++, + e--, + t.dyn_ltree[2 * (Z[a] + f + 1)]++, + t.dyn_dtree[2 * U(e)]++), + t.last_lit === t.lit_bufsize - 1 + ); + }), + (a._tr_align = function(t) { + var e; + F(t, 2, 3), + L(t, w, S), + 16 === (e = t).bi_valid + ? (T(e, e.bi_buf), (e.bi_buf = 0), (e.bi_valid = 0)) + : 8 <= e.bi_valid && + ((e.pending_buf[e.pending++] = 255 & e.bi_buf), + (e.bi_buf >>= 8), + (e.bi_valid -= 8)); + }); + }, + { '../utils/common': 3 } + ], + 15: [ + function(t, e, a) { + 'use strict'; + e.exports = function() { + (this.input = null), + (this.next_in = 0), + (this.avail_in = 0), + (this.total_in = 0), + (this.output = null), + (this.next_out = 0), + (this.avail_out = 0), + (this.total_out = 0), + (this.msg = ''), + (this.state = null), + (this.data_type = 2), + (this.adler = 0); + }; + }, + {} + ], + '/': [ + function(t, e, a) { + 'use strict'; + var i = {}; + (0, t('./lib/utils/common').assign)( + i, + t('./lib/deflate'), + t('./lib/inflate'), + t('./lib/zlib/constants') + ), + (e.exports = i); + }, + { + './lib/deflate': 1, + './lib/inflate': 2, + './lib/utils/common': 3, + './lib/zlib/constants': 6 + } + ] + }, + {}, + [] + )('/'); +}); diff --git a/assets/libs/network/protocol/pako.min.js.meta b/assets/libs/network/protocol/pako.min.js.meta new file mode 100644 index 0000000..19c0b67 --- /dev/null +++ b/assets/libs/network/protocol/pako.min.js.meta @@ -0,0 +1,17 @@ +{ + "ver": "4.0.24", + "importer": "javascript", + "imported": true, + "uuid": "60e799a8-4bb9-4e3d-8b8c-ab86909f9eb8", + "files": [ + ".js" + ], + "subMetas": {}, + "userData": { + "isPlugin": true, + "loadPluginInWeb": true, + "loadPluginInNative": false, + "loadPluginInEditor": false, + "loadPluginInMiniGame": true + } +} -- Gitee From c2edf6692b406613064c2b4078faeba3da4c6259 Mon Sep 17 00:00:00 2001 From: dgflash Date: Thu, 14 Aug 2025 20:10:17 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/gui/button/UIButton.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/assets/libs/gui/button/UIButton.ts b/assets/libs/gui/button/UIButton.ts index cadf999..00180da 100644 --- a/assets/libs/gui/button/UIButton.ts +++ b/assets/libs/gui/button/UIButton.ts @@ -26,7 +26,6 @@ export default class UIButton extends Button { type: AudioClip }) private effect: AudioClip = null!; - // private effectIds: number[] = []; /** 触摸次数 */ private _touchCount = 0; @@ -74,22 +73,9 @@ export default class UIButton extends Button { } /** 短按触摸音效 */ - protected async playEffect() { + protected playEffect() { if (this.effect) { oops.audio.playEffect(this.effect); - // const effectId = await oops.audio.playEffect(this.effect, resLoader.defaultBundleName, () => { - // this.effectIds.remove(effectId); - // }); - // if (effectId > 0) this.effectIds.push(effectId); } } - - // onDestroy() { - // if (this.effect) { - // this.effectIds.forEach(effectId => { - // console.log(effectId); - // oops.audio.putEffect(effectId, this.effect); - // }); - // } - // } } -- Gitee From 41b55a60b02d1e77ce1bb2ac43de1c964638c033 Mon Sep 17 00:00:00 2001 From: wangxuhe <1053066913@qq.com> Date: Fri, 15 Aug 2025 14:47:16 +0800 Subject: [PATCH 12/16] =?UTF-8?q?Add=EF=BC=9A=20ObjectUtil=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E4=B8=BA=E9=9D=9E=E6=B3=95=E5=AF=B9=E8=B1=A1=EF=BC=8C=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=A3=80=E6=B5=8Bnumber=E3=80=81string?= =?UTF-8?q?=E3=80=81array=E3=80=81object=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/utils/ObjectUtil.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/assets/core/utils/ObjectUtil.ts b/assets/core/utils/ObjectUtil.ts index 673ae20..b902147 100644 --- a/assets/core/utils/ObjectUtil.ts +++ b/assets/core/utils/ObjectUtil.ts @@ -60,4 +60,25 @@ export class ObjectUtil { static copy(target: object): object { return JSON.parse(JSON.stringify(target)); } + + /** + * @function 检测是否为非法对象,比如"",null, undefined, NaN, [], {} + * @param {any} obj 任意基础数据对象,如:number、string、array、object等 + * @returns boolean 非法为trre, 否则为false + */ + static isIllegalObject(obj: any): boolean { + // 检查是否为空或未定义 + if (obj == null || obj == undefined) return true; + // 检查是否是特殊值 + if (obj === Infinity || obj === -Infinity) return true; + // 检测是否包含空格的字符串 + if (typeof obj === "string" && obj.trim() === "") return true; + // 检查是否是无效的数字 + if (Number.isNaN(obj)) return true; + // 检查是否是空数组 + if (Array.isArray(obj) && obj.length <= 0) return true; + // 检查是否是空对象 + if (typeof (obj) == "object" && Object.keys(obj).length <= 0) return true; + return false; + } } -- Gitee From 115cb63fe331e744fe251d8aa549de5372d8ccbe Mon Sep 17 00:00:00 2001 From: dgflash Date: Fri, 15 Aug 2025 16:55:52 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20LayerGame=20?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=B1=82=E8=8A=82=E7=82=B9=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD=201.=20=E6=94=AF=E6=8C=81=E9=A2=84?= =?UTF-8?q?=E5=88=B6=E8=8A=82=E7=82=B9=E6=B7=BB=E5=8A=A0=E3=80=81=E5=88=A0?= =?UTF-8?q?=E9=99=A4=202.=20=E6=94=AF=E6=8C=81=E9=A2=84=E5=88=B6=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=AF=B9=E8=B1=A1=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/LayerEnum.ts | 18 +- assets/core/gui/layer/LayerGame.ts | 169 ++++++++++++++++++ assets/core/gui/layer/LayerGame.ts.meta | 9 + assets/core/gui/layer/LayerGameElement.ts | 27 +++ .../core/gui/layer/LayerGameElement.ts.meta | 9 + assets/core/gui/layer/LayerManager.ts | 17 +- assets/core/gui/layer/UIConfig.ts | 19 ++ 7 files changed, 254 insertions(+), 14 deletions(-) create mode 100644 assets/core/gui/layer/LayerGame.ts create mode 100644 assets/core/gui/layer/LayerGame.ts.meta create mode 100644 assets/core/gui/layer/LayerGameElement.ts create mode 100644 assets/core/gui/layer/LayerGameElement.ts.meta diff --git a/assets/core/gui/layer/LayerEnum.ts b/assets/core/gui/layer/LayerEnum.ts index 5ded033..e656455 100644 --- a/assets/core/gui/layer/LayerEnum.ts +++ b/assets/core/gui/layer/LayerEnum.ts @@ -15,10 +15,18 @@ export enum ScreenAdapterType { Portrait } -/** 界面层类型 */ -export enum LayerType { +/** 自定义层类型 */ +export enum LayerCustomType { /** 二维游戏层 */ Game = "LayerGame", + /** 消息提示层 */ + Notify = "LayerNotify", + /** 新手引导层 */ + Guide = "LayerGuide" +} + +/** 界面层类型 */ +export enum LayerType { /** 主界面层 */ UI = "LayerUI", /** 弹窗层 */ @@ -27,10 +35,6 @@ export enum LayerType { Dialog = "LayerDialog", /** 系统触发模式窗口层 */ System = "LayerSystem", - /** 消息提示层 */ - Notify = "LayerNotify", - /** 新手引导层 */ - Guide = "LayerGuide" } /** 界面层组件类型 */ @@ -43,6 +47,8 @@ export enum LayerTypeCls { Dialog = "Dialog", /** 消息提示层 */ Notify = "Notify", + /** 游戏层 */ + Game = "Game", /** 自定义节点层 */ Node = "Node" } diff --git a/assets/core/gui/layer/LayerGame.ts b/assets/core/gui/layer/LayerGame.ts new file mode 100644 index 0000000..c16ef28 --- /dev/null +++ b/assets/core/gui/layer/LayerGame.ts @@ -0,0 +1,169 @@ +/* + * @Author: dgflash + * @Date: 2025-08-15 10:06:47 + * @LastEditors: dgflash + * @LastEditTime: 2025-08-15 10:06:47 + */ +import { Layers, Node, NodePool, Prefab, Vec3, warn, Widget } from "cc"; +import { resLoader } from "../../common/loader/ResLoader"; +import { ViewUtil } from "../../utils/ViewUtil"; +import { LayerCustomType } from "./LayerEnum"; +import { GameElementParams, LayerGameElement } from "./LayerGameElement"; +import { GameElementConfig } from "./UIConfig"; + +/* 二维游戏层 */ +export class LayerGame extends Node { + /** 当前显示的元素节点 */ + protected elements = new Map(); + + constructor() { + super(LayerCustomType.Game); + + const widget: Widget = this.addComponent(Widget); + widget.isAlignLeft = widget.isAlignRight = widget.isAlignTop = widget.isAlignBottom = true; + widget.left = widget.right = widget.top = widget.bottom = 0; + widget.alignMode = 2; + widget.enabled = true; + + this.layer = Layers.Enum.UI_2D; + } + + /** + * 添加游戏元素 + * @param prefab 资源地址 + * @param config 游戏元素自定义配置 + */ + add(prefab: string, config: GameElementConfig = {}): Node { + let params = this.setParams(prefab, config, false); + let node = ViewUtil.createPrefabNode(prefab, params.config.bundle); + if (node) { + // 设置自定义属性 + this.setNode(node, config); + + let lge = node.addComponent(LayerGameElement); + lge.params = params; + params.nodes.push(node); + } + return node; + } + + /** + * 加载资源并添加游戏元素 + * @param prefab 资源地址 + * @param config 游戏元素自定义配置 + */ + addAsync(prefab: string, config: GameElementConfig = {}): Promise { + return new Promise(async (resolve, reject) => { + let bundleName = config.bundle ? config.bundle : resLoader.defaultBundleName; + await resLoader.loadAsync(bundleName, prefab, Prefab); + let node = this.add(prefab, config); + resolve(node); + }); + } + + /** + * 添加游戏元素 - 支持对象池 + * @param prefab 资源地址 + * @param config 游戏元素自定义配置 + */ + addPool(prefab: string, config: GameElementConfig = {}): Node { + let params = this.setParams(prefab, config, true); + let node: Node = null!; + if (params.pool.size() > 0) { + node = params.pool.get()!; + } + else { + node = ViewUtil.createPrefabNode(prefab, params.config.bundle); + node.addComponent(LayerGameElement); + } + + // 设置自定义属性 + this.setNode(node, config); + + let lge = node.getComponent(LayerGameElement)!; + lge.params = params; + + return node; + } + + /** + * 加载资源并添加游戏元素 - 支持对象池 + * @param prefab 资源地址 + * @param config 游戏元素自定义配置 + */ + addPoolAsync(prefab: string, config: GameElementConfig = {}): Promise { + return new Promise(async (resolve, reject) => { + let bundleName = config.bundle ? config.bundle : resLoader.defaultBundleName; + await resLoader.loadAsync(bundleName, prefab, Prefab); + let node = this.addPool(prefab, config); + resolve(node); + }); + } + + /** 清理池数据 */ + clearPool(node: Node) { + let lge = node.getComponent(LayerGameElement)!; + if (lge) { + let params = this.elements.get(lge.params.uiid); + if (params) params.pool.clear(); + } + } + + /** + * 移除游戏元素 + * @param node 游戏元素节点 + */ + remove(node: Node) { + let lge = node.getComponent(LayerGameElement)!; + if (lge) { + if (lge.params.pool) { + lge.params.pool.put(node); + } + else { + let nodes = lge.params.nodes; + let index = nodes.indexOf(node); + if (index != -1) { + nodes.splice(index, 1); + if (nodes.length == 0) { + this.elements.delete(lge.params.uiid); + resLoader.release(lge.params.config.prefab!, lge.params.config.bundle); + } + } + node.removeFromParent(); + } + } + else { + warn(`当前删除游戏元素的 Node 不是通过框架添加的`); + } + } + + /** 设置元素参数 */ + private setParams(prefab: string, config: GameElementConfig, pool: boolean) { + let bundleName = config.bundle ? config.bundle : resLoader.defaultBundleName; + let uuid = bundleName + "_" + prefab; + let params = this.elements.get(uuid); + if (params == null) { + config.prefab = prefab; + params = new GameElementParams(); + params.uiid = uuid; + params.config = config; + if (pool) { + params.pool = new NodePool(); + } + else { + params.nodes = []; + } + this.elements.set(uuid, params); + } + return params; + } + + /** 设置自定义属性 */ + private setNode(node: Node, config: GameElementConfig) { + node.scale = config.scale ? config.scale : Vec3.ONE; + node.position = config.position ? config.position : Vec3.ZERO; + node.eulerAngles = config.eulerAngles ? config.eulerAngles : Vec3.ZERO; + node.parent = config.parent ? config.parent : this; + if (config.siblingIndex != null) node.setSiblingIndex(config.siblingIndex); + } +} \ No newline at end of file diff --git a/assets/core/gui/layer/LayerGame.ts.meta b/assets/core/gui/layer/LayerGame.ts.meta new file mode 100644 index 0000000..5801e2c --- /dev/null +++ b/assets/core/gui/layer/LayerGame.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "77041037-badf-4f11-b538-33a855aae209", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/core/gui/layer/LayerGameElement.ts b/assets/core/gui/layer/LayerGameElement.ts new file mode 100644 index 0000000..011a30a --- /dev/null +++ b/assets/core/gui/layer/LayerGameElement.ts @@ -0,0 +1,27 @@ +import { _decorator, Component, Node, NodePool } from "cc"; +import { GameElementConfig } from "./UIConfig"; + +const { ccclass } = _decorator; + +/** 窗口事件触发组件 */ +@ccclass('LayerGameElement') +export class LayerGameElement extends Component { + /** 视图参数 */ + params: GameElementParams = null!; + + protected onDestroy(): void { + this.params = null!; + } +} + +/** 游戏元素参数 */ +export class GameElementParams { + /** 游戏元素唯一编号 */ + uiid: string = null!; + /** 游戏元素配置 */ + config: GameElementConfig = null! + /** 同类游戏元素集合 */ + nodes: Node[] = null!; + /** 同类游戏元素对象池 */ + pool: NodePool = null!; +} \ No newline at end of file diff --git a/assets/core/gui/layer/LayerGameElement.ts.meta b/assets/core/gui/layer/LayerGameElement.ts.meta new file mode 100644 index 0000000..bed6853 --- /dev/null +++ b/assets/core/gui/layer/LayerGameElement.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "b43406cb-41d3-42a1-9393-40dbcd0a853e", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/core/gui/layer/LayerManager.ts b/assets/core/gui/layer/LayerManager.ts index 67dae73..c23e7b4 100644 --- a/assets/core/gui/layer/LayerManager.ts +++ b/assets/core/gui/layer/LayerManager.ts @@ -4,7 +4,8 @@ import { oops } from "../../Oops"; import { UICallbacks } from "./Defines"; import { DelegateComponent } from "./DelegateComponent"; import { LayerDialog } from "./LayerDialog"; -import { LayerType, LayerTypeCls, UIConfigMap, Uiid } from "./LayerEnum"; +import { LayerCustomType, LayerTypeCls, UIConfigMap, Uiid } from "./LayerEnum"; +import { LayerGame } from "./LayerGame"; import { LayerNotify } from "./LayerNotify"; import { LayerPopUp } from "./LayerPopup"; import { LayerUI } from "./LayerUI"; @@ -17,7 +18,7 @@ export class LayerManager { /** 界面摄像机 */ camera!: Camera; /** 游戏界面特效层 */ - game!: Node; + game!: LayerGame; /** 新手引导层 */ guide!: Node; @@ -42,6 +43,7 @@ export class LayerManager { this.clsLayers.set(LayerTypeCls.PopUp, LayerPopUp); this.clsLayers.set(LayerTypeCls.Dialog, LayerDialog); this.clsLayers.set(LayerTypeCls.Notify, LayerNotify); + this.clsLayers.set(LayerTypeCls.Game, LayerGame); this.clsLayers.set(LayerTypeCls.Node, null); } @@ -76,13 +78,10 @@ export class LayerManager { let data = config[i]; let layer: Node = null!; if (data.type == LayerTypeCls.Node) { - layer = this.create_node(data.name); switch (data.name) { - case LayerType.Game: - this.game = layer; - break - case LayerType.Guide: - this.guide = layer; + case LayerCustomType.Guide: + this.guide = this.create_node(data.name); + layer = this.guide; break } } @@ -101,6 +100,8 @@ export class LayerManager { this.uiLayers.set(data.name, layer); else if (layer instanceof LayerNotify) this.notify = layer; + else if (layer instanceof LayerGame) + this.game = layer; } } diff --git a/assets/core/gui/layer/UIConfig.ts b/assets/core/gui/layer/UIConfig.ts index b66f4cd..344c4d7 100644 --- a/assets/core/gui/layer/UIConfig.ts +++ b/assets/core/gui/layer/UIConfig.ts @@ -1,3 +1,4 @@ +import { Node, Vec3 } from "cc"; /** * 界面配置结构体 @@ -43,3 +44,21 @@ export interface UIConfig { /** 界面弹出时的节点排序索引 */ siblingIndex?: number; } + +/** 游戏元素配置 */ +export interface GameElementConfig { + /** 预制资源相对路径 */ + prefab?: string; + /** 游戏元素副节点 */ + parent?: Node; + /** 游戏元素位置 */ + position?: Vec3; + /** 游戏元素旋转 */ + eulerAngles?: Vec3; + /** 游戏元素缩放 */ + scale?: Vec3; + /** 远程包名 */ + bundle?: string; + /** 节点排序索引 */ + siblingIndex?: number; +} -- Gitee From afced51c53d0abf44d1f467952ba59342f32e222 Mon Sep 17 00:00:00 2001 From: dgflash Date: Fri, 15 Aug 2025 19:01:02 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/model-view/StringFormat.ts | 43 +++++++++++++------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/assets/libs/model-view/StringFormat.ts b/assets/libs/model-view/StringFormat.ts index 4e99922..89e3b52 100644 --- a/assets/libs/model-view/StringFormat.ts +++ b/assets/libs/model-view/StringFormat.ts @@ -1,6 +1,8 @@ -import { oops } from "../../core/Oops"; - -/** 数值格式化函数, 通过语义解析自动设置值的范围 */ +/** + * 数值格式化函数, 通过语义解析自动设置值的范围 + * //整数 + * 1:def(0)//显示一个默认值 + */ class StringFormat { deal(value: number | string, format: string): string { if (format === '') return value as string; @@ -23,10 +25,10 @@ class StringFormat { case 'per': res = this.per(value, num); break; case 'sep': res = this.sep(value); break; - case 'tstamp': res = this.time_stamp(value); break; - case 'tm': res = this.time_m(value); break; - case 'ts': res = this.time_s(value); break; - case 'tms': res = this.time_ms(value); break; + case 'stamp': res = this.time_stamp(value); break; + case 'ms': res = this.time_ms(value); break; + case 'hms': res = this.time_hms(value); break; + case 'hmss': res = this.time_hmss(value); break; default: break; } @@ -34,8 +36,10 @@ class StringFormat { else { switch (func) { case 'limit': res = this.limit(value, num); break; - default: res = value; break; + default: + break; } + res = value; } return res as string; @@ -47,18 +51,18 @@ class StringFormat { return num.replace(new RegExp('(\\d)(?=(\\d{3})+$)', 'ig'), "$1,"); } - /** 将数字按分显示 00:00 显示 (时:分) */ - private time_m(value: number) { - return new Date(value).format('hh:ss'); + /** 将数字按分显示 00:00 显示 (分:秒) */ + private time_ms(value: number) { + return new Date(value).format('mm:ss'); } /** 将数字按秒显示 00:00:00 显示 (时:分:秒) */ - private time_s(value: number) { + private time_hms(value: number) { return new Date(value).format('hh:mm:ss'); } /** 将数字按 0:00:00:000 显示 (时:分:秒:毫秒) */ - private time_ms(value: number) { + private time_hmss(value: number) { return new Date(value).format('hh:mm:ss:ms'); } @@ -89,21 +93,18 @@ class StringFormat { } /** 将数字缩短显示为KMBT单位 大写,目前只支持英文 */ - private kmbt(value: number) { + private kmbt(value: number, lang: string = 'en') { //10^4=万, 10^8=亿,10^12=兆,10^16=京, - let counts: number[] = null!; - let units: string[] = null!; + let counts = [1000, 1000000, 1000000000, 1000000000000]; + let units = ['', 'K', 'M', 'B', 'T']; - switch (oops.language.current) { + switch (lang) { case 'zh': //10^4=万, 10^8=亿,10^12=兆,10^16=京, counts = [10000, 100000000, 1000000000000, 10000000000000000]; units = ['', '万', '亿', '兆', '京']; break; - case 'en': - counts = [1000, 1000000, 1000000000, 1000000000000]; - units = ['', 'K', 'M', 'B', 'T']; - break; + default: break; } -- Gitee From 0f41fb85b1e69e335180272aff464d9226f32d1a Mon Sep 17 00:00:00 2001 From: dgflash Date: Sat, 16 Aug 2025 10:30:20 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/Defines.ts | 53 ---- .../core/gui/layer/DelegateComponent.ts.meta | 13 - assets/core/gui/layer/LayerDialog.ts | 26 +- assets/core/gui/layer/LayerGameElement.ts | 2 +- assets/core/gui/layer/LayerManager.ts | 13 +- assets/core/gui/layer/LayerPopup.ts | 14 +- assets/core/gui/layer/LayerUI.ts | 63 ++-- ...DelegateComponent.ts => LayerUIElement.ts} | 289 ++++++++++-------- ...Defines.ts.meta => LayerUIElement.ts.meta} | 22 +- assets/module/common/ModuleUtil.ts | 8 +- 10 files changed, 239 insertions(+), 264 deletions(-) delete mode 100644 assets/core/gui/layer/Defines.ts delete mode 100644 assets/core/gui/layer/DelegateComponent.ts.meta rename assets/core/gui/layer/{DelegateComponent.ts => LayerUIElement.ts} (50%) rename assets/core/gui/layer/{Defines.ts.meta => LayerUIElement.ts.meta} (33%) diff --git a/assets/core/gui/layer/Defines.ts b/assets/core/gui/layer/Defines.ts deleted file mode 100644 index 4cddfe9..0000000 --- a/assets/core/gui/layer/Defines.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * @Author: dgflash - * @Date: 2021-11-18 11:21:32 - * @LastEditors: dgflash - * @LastEditTime: 2023-01-09 11:52:38 - */ -import { Node } from "cc"; -import { UIConfig } from "./UIConfig"; - -/*** 界面回调参数对象定义 */ -export interface UICallbacks { - /** - * 节点添加到层级以后的回调 - * @param node 当前界面节点 - * @param params 外部传递参数 - */ - onAdded?: (node: Node, params: any) => void, - - /** - * 窗口节点 destroy 之后回调 - * @param node 当前界面节点 - * @param params 外部传递参数 - */ - onRemoved?: (node: Node | null, params: any) => void, - - /** - * 如果指定onBeforeRemoved,则next必须调用,否则节点不会被正常删除。 - * - * 比如希望节点做一个FadeOut然后删除,则可以在`onBeforeRemoved`当中播放action动画,动画结束后调用next - * @param node 当前界面节点 - * @param next 回调方法 - */ - onBeforeRemove?: (node: Node, next: Function) => void, - - /** 网络异常时,窗口加载失败回调 */ - onLoadFailure?: () => void; -} - -/** 本类型仅供gui模块内部使用,请勿在功能逻辑中使用 */ -export class ViewParams { - /** 界面唯一编号 */ - uiid: string = null!; - /** 界面配置 */ - config: UIConfig = null!; - /** 传递给打开界面的参数 */ - params: any = null!; - /** 窗口事件 */ - callbacks: UICallbacks = null!; - /** 是否在使用状态 */ - valid: boolean = true; - /** 界面根节点 */ - node: Node = null!; -} \ No newline at end of file diff --git a/assets/core/gui/layer/DelegateComponent.ts.meta b/assets/core/gui/layer/DelegateComponent.ts.meta deleted file mode 100644 index 65a39b0..0000000 --- a/assets/core/gui/layer/DelegateComponent.ts.meta +++ /dev/null @@ -1,13 +0,0 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "d8f1f191-0fb7-41cc-8781-4a43a977f3f2", - "files": [], - "subMetas": {}, - "userData": { - "moduleId": "project:///assets/script/core/gui/layer/DelegateComponent.js", - "importerSettings": 4, - "simulateGlobals": [] - } -} diff --git a/assets/core/gui/layer/LayerDialog.ts b/assets/core/gui/layer/LayerDialog.ts index 68b2965..ff7d51c 100644 --- a/assets/core/gui/layer/LayerDialog.ts +++ b/assets/core/gui/layer/LayerDialog.ts @@ -5,8 +5,8 @@ * @LastEditTime: 2023-07-24 17:14:57 */ -import { UICallbacks, ViewParams } from "./Defines"; import { LayerPopUp } from "./LayerPopup"; +import { UICallbacks, UIParams } from "./LayerUIElement"; import { UIConfig } from "./UIConfig"; /** 模式弹窗数据 */ @@ -45,23 +45,23 @@ export class LayerDialog extends LayerPopUp { /** 显示模式弹窗 */ private show(uiid: string, config: UIConfig, params?: any, callbacks?: UICallbacks) { - let vp = this.ui_cache.get(config.prefab); - if (vp == null) { - vp = new ViewParams(); - vp.uiid = uiid; - vp.valid = true; - vp.config = config; + let uip = this.ui_cache.get(config.prefab); + if (uip == null) { + uip = new UIParams(); + uip.uiid = uiid; + uip.valid = true; + uip.config = config; } - vp.params = params || {}; - vp.callbacks = callbacks ?? {}; - this.ui_nodes.set(vp.config.prefab, vp); + uip.params = params || {}; + uip.callbacks = callbacks ?? {}; + this.ui_nodes.set(uip.config.prefab, uip); - this.load(vp, config.bundle); + this.load(uip, config.bundle); } - protected onCloseWindow(vp: ViewParams) { - super.onCloseWindow(vp); + protected onCloseWindow(uip: UIParams) { + super.onCloseWindow(uip); setTimeout(this.next.bind(this), 0); } diff --git a/assets/core/gui/layer/LayerGameElement.ts b/assets/core/gui/layer/LayerGameElement.ts index 011a30a..32938aa 100644 --- a/assets/core/gui/layer/LayerGameElement.ts +++ b/assets/core/gui/layer/LayerGameElement.ts @@ -3,7 +3,7 @@ import { GameElementConfig } from "./UIConfig"; const { ccclass } = _decorator; -/** 窗口事件触发组件 */ +/** 游戏元素组件 */ @ccclass('LayerGameElement') export class LayerGameElement extends Component { /** 视图参数 */ diff --git a/assets/core/gui/layer/LayerManager.ts b/assets/core/gui/layer/LayerManager.ts index c23e7b4..c3666ab 100644 --- a/assets/core/gui/layer/LayerManager.ts +++ b/assets/core/gui/layer/LayerManager.ts @@ -1,8 +1,7 @@ import { Camera, Layers, Node, ResolutionPolicy, SafeArea, Widget, screen, view, warn } from "cc"; import { resLoader } from "../../common/loader/ResLoader"; import { oops } from "../../Oops"; -import { UICallbacks } from "./Defines"; -import { DelegateComponent } from "./DelegateComponent"; +import { LayerUIElement, UICallbacks } from "./LayerUIElement"; import { LayerDialog } from "./LayerDialog"; import { LayerCustomType, LayerTypeCls, UIConfigMap, Uiid } from "./LayerEnum"; import { LayerGame } from "./LayerGame"; @@ -271,19 +270,19 @@ export class LayerManager { */ removeByNode(node: Node, isDestroy: boolean = true) { if (node instanceof Node) { - let comp = node.getComponent(DelegateComponent); - if (comp && comp.vp) { + let comp = node.getComponent(LayerUIElement); + if (comp && comp.params) { // 释放显示的界面 if (node.parent) { - let uiid = this.configs[comp.vp.uiid]; + let uiid = this.configs[comp.params.uiid]; this.remove(uiid, isDestroy); } // 释放缓存中的界面 else if (isDestroy) { - let layer = this.uiLayers.get(comp.vp.config.layer); + let layer = this.uiLayers.get(comp.params.config.layer); if (layer) { // @ts-ignore 注:不对外使用 - layer.removeCache(comp.vp.config.prefab); + layer.removeCache(comp.params.config.prefab); } } } diff --git a/assets/core/gui/layer/LayerPopup.ts b/assets/core/gui/layer/LayerPopup.ts index c3a397b..aaa7ab4 100644 --- a/assets/core/gui/layer/LayerPopup.ts +++ b/assets/core/gui/layer/LayerPopup.ts @@ -7,9 +7,9 @@ import { BlockInputEvents, EventTouch, Layers, Node } from "cc"; import { ViewUtil } from "../../utils/ViewUtil"; import { PromptResType } from "../GuiEnum"; -import { ViewParams } from "./Defines"; import { LayerUI } from "./LayerUI"; import { UIConfig } from "./UIConfig"; +import { UIParams } from "./LayerUIElement"; /* 弹窗层,允许同时弹出多个窗口 */ export class LayerPopUp extends LayerUI { @@ -20,7 +20,7 @@ export class LayerPopUp extends LayerUI { constructor(name: string) { super(name); - + this.layer = Layers.Enum.UI_2D; this.on(Node.EventType.CHILD_ADDED, this.onChildAdded, this); this.on(Node.EventType.CHILD_REMOVED, this.onChildRemoved, this); @@ -38,11 +38,11 @@ export class LayerPopUp extends LayerUI { } } - protected async showUi(vp: ViewParams): Promise { - const r = await super.showUi(vp); + protected async showUi(uip: UIParams): Promise { + const r = await super.showUi(uip); if (r) { // 界面加载完成显示时,启动触摸非窗口区域关闭 - this.openVacancyRemove(vp.config); + this.openVacancyRemove(uip.config); // 界面加载完成显示时,层级事件阻挡 this.black.enabled = true; @@ -50,8 +50,8 @@ export class LayerPopUp extends LayerUI { return r; } - protected onCloseWindow(vp: ViewParams) { - super.onCloseWindow(vp); + protected onCloseWindow(uip: UIParams) { + super.onCloseWindow(uip); // 界面关闭后,关闭触摸事件阻挡、关闭触摸非窗口区域关闭、关闭遮罩 this.setBlackDisable(); diff --git a/assets/core/gui/layer/LayerUI.ts b/assets/core/gui/layer/LayerUI.ts index 926fc09..432a1c0 100644 --- a/assets/core/gui/layer/LayerUI.ts +++ b/assets/core/gui/layer/LayerUI.ts @@ -1,9 +1,8 @@ import { instantiate, Node, Prefab, SafeArea, Widget } from "cc"; import { Collection } from "db://oops-framework/libs/collection/Collection"; import { oops } from "../../Oops"; -import { UICallbacks, ViewParams } from "./Defines"; -import { DelegateComponent } from "./DelegateComponent"; import { Uiid } from "./LayerEnum"; +import { LayerUIElement, UICallbacks, UIParams } from "./LayerUIElement"; import { UIConfig } from "./UIConfig"; /** 界面层对象 */ @@ -11,9 +10,9 @@ export class LayerUI extends Node { /** 全局窗口打开失败 */ onOpenFailure: Function = null!; /** 显示界面节点集合 */ - protected ui_nodes = new Collection(); + protected ui_nodes = new Collection(); /** 被移除的界面缓存数据 */ - protected ui_cache = new Map(); + protected ui_cache = new Map(); /** * UI基础层,允许添加多个预制件节点 @@ -43,19 +42,19 @@ export class LayerUI extends Node { } // 检查缓存中是否存界面 - let vp = this.ui_cache.get(config.prefab); - if (vp == null) { - vp = new ViewParams(); - vp.uiid = uiid.toString(); - vp.config = config; + let uip = this.ui_cache.get(config.prefab); + if (uip == null) { + uip = new UIParams(); + uip.uiid = uiid.toString(); + uip.config = config; } - this.ui_nodes.set(config.prefab, vp); + this.ui_nodes.set(config.prefab, uip); - vp.params = params ?? {}; - vp.callbacks = callbacks ?? {}; - vp.valid = true; + uip.params = params ?? {}; + uip.callbacks = callbacks ?? {}; + uip.valid = true; - this.load(vp, config.bundle) + this.load(uip, config.bundle) } /** @@ -63,7 +62,7 @@ export class LayerUI extends Node { * @param vp 显示参数 * @param bundle 远程资源包名,如果为空就是默认本地资源包 */ - protected async load(vp: ViewParams, bundle?: string) { + protected async load(vp: UIParams, bundle?: string) { // 加载界面资源超时提示 const timerId = setTimeout(this.onLoadingTimeoutGui, oops.config.game.loadingTimeoutGui); @@ -80,8 +79,8 @@ export class LayerUI extends Node { if (vp.config.safeArea) vp.node.addComponent(SafeArea); // 窗口事件委托 - const dc = vp.node.addComponent(DelegateComponent); - dc.vp = vp; + const dc = vp.node.addComponent(LayerUIElement); + dc.params = vp; dc.onCloseWindow = this.onCloseWindow.bind(this); // 显示界面 @@ -104,35 +103,35 @@ export class LayerUI extends Node { } /** 窗口关闭事件 */ - protected onCloseWindow(vp: ViewParams) { + protected onCloseWindow(vp: UIParams) { this.ui_nodes.delete(vp.config.prefab); } /** * 创建界面节点 - * @param vp 视图参数 + * @param uip 视图参数 */ - protected async showUi(vp: ViewParams): Promise { + protected async showUi(uip: UIParams): Promise { // 触发窗口添加事件 - const comp = vp.node.getComponent(DelegateComponent)!; + const comp = uip.node.getComponent(LayerUIElement)!; const r: boolean = await comp.add(); if (r) { - vp.node.parent = this; + uip.node.parent = this; // 标记界面为使用状态 - vp.valid = true; + uip.valid = true; } else { - console.warn(`路径为【${vp.config.prefab}】的自定义预处理逻辑异常.检查预制上绑定的组件中 onAdded 方法,返回true才能正确完成窗口显示流程`); - this.failure(vp); + console.warn(`路径为【${uip.config.prefab}】的自定义预处理逻辑异常.检查预制上绑定的组件中 onAdded 方法,返回true才能正确完成窗口显示流程`); + this.failure(uip); } return r; } /** 打开窗口失败逻辑 */ - protected failure(vp: ViewParams) { - this.onCloseWindow(vp); - vp.callbacks && vp.callbacks.onLoadFailure && vp.callbacks.onLoadFailure(); + protected failure(uip: UIParams) { + this.onCloseWindow(uip); + uip.callbacks && uip.callbacks.onLoadFailure && uip.callbacks.onLoadFailure(); this.onOpenFailure && this.onOpenFailure(); } @@ -159,7 +158,7 @@ export class LayerUI extends Node { } const childNode = vp.node; - const comp = childNode.getComponent(DelegateComponent)!; + const comp = childNode.getComponent(LayerUIElement)!; comp.remove(release); } @@ -174,7 +173,7 @@ export class LayerUI extends Node { this.onCloseWindow(vp); this.ui_cache.delete(prefabPath); const childNode = vp.node; - const comp = childNode.getComponent(DelegateComponent)!; + const comp = childNode.getComponent(LayerUIElement)!; if (comp) { comp.remove(true); } @@ -207,7 +206,7 @@ export class LayerUI extends Node { */ clear(isDestroy: boolean): void { // 清除所有显示的界面 - this.ui_nodes.forEach((value: ViewParams, key: string) => { + this.ui_nodes.forEach((value: UIParams, key: string) => { this.remove(value.config.prefab, isDestroy); value.valid = false; }); @@ -215,7 +214,7 @@ export class LayerUI extends Node { // 清除缓存中的界面 if (isDestroy) { - this.ui_cache.forEach((value: ViewParams, prefabPath: string) => { + this.ui_cache.forEach((value: UIParams, prefabPath: string) => { this.removeCache(prefabPath); }); } diff --git a/assets/core/gui/layer/DelegateComponent.ts b/assets/core/gui/layer/LayerUIElement.ts similarity index 50% rename from assets/core/gui/layer/DelegateComponent.ts rename to assets/core/gui/layer/LayerUIElement.ts index 36a12b7..142a5d4 100644 --- a/assets/core/gui/layer/DelegateComponent.ts +++ b/assets/core/gui/layer/LayerUIElement.ts @@ -1,122 +1,169 @@ -/* - * @Author: dgflash - * @Date: 2022-09-01 18:00:28 - * @LastEditors: dgflash - * @LastEditTime: 2023-01-09 11:55:03 - */ -import { Component, Node, _decorator } from "cc"; -import { oops } from "../../Oops"; -import { ViewParams } from "./Defines"; - -const { ccclass } = _decorator; - -const EventOnAdded: string = "onAdded"; -const EventOnBeforeRemove: string = "onBeforeRemove"; -const EventOnRemoved: string = "onRemoved"; - -/** 窗口事件触发组件 */ -@ccclass('DelegateComponent') -export class DelegateComponent extends Component { - /** 视图参数 */ - vp: ViewParams = null!; - /** 关闭窗口之前 */ - onCloseWindowBefore: Function = null!; - /** 界面关闭回调 - 包括关闭动画播放完(辅助框架内存业务流程使用) */ - onCloseWindow: Function = null!; - - /** 窗口添加 */ - add(): Promise { - return new Promise(async (resolve, reject) => { - // 触发窗口组件上添加到父节点后的事件 - for (let i = 0; i < this.node.components.length; i++) { - const component: any = this.node.components[i]; - const func = component[EventOnAdded]; - if (func) { - if (await func.call(component, this.vp.params) == false) { - resolve(false); - return; - } - } - } - - // 触发外部窗口显示前的事件(辅助实现自定义动画逻辑) - if (typeof this.vp.callbacks.onAdded === "function") { - this.vp.callbacks.onAdded(this.node, this.vp.params); - } - - resolve(true); - }); - } - - /** 删除节点,该方法只能调用一次,将会触发onBeforeRemoved回调 */ - remove(isDestroy?: boolean) { - if (this.vp.valid) { - // 触发窗口移除舞台之前事件 - this.applyComponentsFunction(this.node, EventOnBeforeRemove, this.vp.params); - - // 通知外部对象窗口组件上移除之前的事件(关闭窗口前的关闭动画处理) - if (typeof this.vp.callbacks.onBeforeRemove === "function") { - this.vp.callbacks.onBeforeRemove( - this.node, - this.onBeforeRemoveNext.bind(this, isDestroy)); - } - else { - this.removed(this.vp, isDestroy); - } - } - else { - this.removed(this.vp, isDestroy); - } - } - - /** 窗口关闭前动画处理完后的回调方法,主要用于释放资源 */ - private onBeforeRemoveNext(isDestroy?: boolean) { - if (this.onCloseWindowBefore) { - this.onCloseWindowBefore(); - this.onCloseWindowBefore = null!; - } - this.removed(this.vp, isDestroy); - } - - /** 窗口组件中触发移除事件与释放窗口对象 */ - private removed(vp: ViewParams, isDestroy?: boolean) { - vp.valid = false; - - if (vp.callbacks && typeof vp.callbacks.onRemoved === "function") { - vp.callbacks.onRemoved(this.node, vp.params); - } - - // 界面移除舞台事件 - this.onCloseWindow && this.onCloseWindow(vp); - - if (isDestroy) { - // 释放界面显示对象 - this.node.destroy(); - - // 释放界面相关资源 - oops.res.release(vp.config.prefab, vp.config.bundle); - - oops.log.logView(`【界面管理】释放【${vp.config.prefab}】界面资源`); - } - else { - this.node.removeFromParent(); - } - - // 触发窗口组件上窗口移除之后的事件 - this.applyComponentsFunction(this.node, EventOnRemoved, this.vp.params); - } - - onDestroy() { - this.vp = null!; - } - - protected applyComponentsFunction(node: Node, funName: string, params: any) { - for (let i = 0; i < node.components.length; i++) { - const component: any = node.components[i]; - const func = component[funName]; - if (func) { - func.call(component, params); - } - } - } +/* + * @Author: dgflash + * @Date: 2022-09-01 18:00:28 + * @LastEditors: dgflash + * @LastEditTime: 2023-01-09 11:55:03 + */ +import { Component, Node, _decorator } from "cc"; +import { oops } from "../../Oops"; +import { UIConfig } from "./UIConfig"; + +const { ccclass } = _decorator; + +const EventOnAdded: string = "onAdded"; +const EventOnBeforeRemove: string = "onBeforeRemove"; +const EventOnRemoved: string = "onRemoved"; + +/** 窗口元素组件 */ +@ccclass('LayerUIElement') +export class LayerUIElement extends Component { + /** 视图参数 */ + params: UIParams = null!; + /** 关闭窗口之前 */ + onCloseWindowBefore: Function = null!; + /** 界面关闭回调 - 包括关闭动画播放完(辅助框架内存业务流程使用) */ + onCloseWindow: Function = null!; + + /** 窗口添加 */ + add(): Promise { + return new Promise(async (resolve, reject) => { + // 触发窗口组件上添加到父节点后的事件 + for (let i = 0; i < this.node.components.length; i++) { + const component: any = this.node.components[i]; + const func = component[EventOnAdded]; + if (func) { + if (await func.call(component, this.params.params) == false) { + resolve(false); + return; + } + } + } + + // 触发外部窗口显示前的事件(辅助实现自定义动画逻辑) + if (typeof this.params.callbacks.onAdded === "function") { + this.params.callbacks.onAdded(this.node, this.params.params); + } + + resolve(true); + }); + } + + /** 删除节点,该方法只能调用一次,将会触发onBeforeRemoved回调 */ + remove(isDestroy?: boolean) { + if (this.params.valid) { + // 触发窗口移除舞台之前事件 + this.applyComponentsFunction(this.node, EventOnBeforeRemove, this.params.params); + + // 通知外部对象窗口组件上移除之前的事件(关闭窗口前的关闭动画处理) + if (typeof this.params.callbacks.onBeforeRemove === "function") { + this.params.callbacks.onBeforeRemove( + this.node, + this.onBeforeRemoveNext.bind(this, isDestroy)); + } + else { + this.removed(this.params, isDestroy); + } + } + else { + this.removed(this.params, isDestroy); + } + } + + /** 窗口关闭前动画处理完后的回调方法,主要用于释放资源 */ + private onBeforeRemoveNext(isDestroy?: boolean) { + if (this.onCloseWindowBefore) { + this.onCloseWindowBefore(); + this.onCloseWindowBefore = null!; + } + this.removed(this.params, isDestroy); + } + + /** 窗口组件中触发移除事件与释放窗口对象 */ + private removed(uip: UIParams, isDestroy?: boolean) { + uip.valid = false; + + if (uip.callbacks && typeof uip.callbacks.onRemoved === "function") { + uip.callbacks.onRemoved(this.node, uip.params); + } + + // 界面移除舞台事件 + this.onCloseWindow && this.onCloseWindow(uip); + + if (isDestroy) { + // 释放界面显示对象 + this.node.destroy(); + + // 释放界面相关资源 + oops.res.release(uip.config.prefab, uip.config.bundle); + + oops.log.logView(`【界面管理】释放【${uip.config.prefab}】界面资源`); + } + else { + this.node.removeFromParent(); + } + + // 触发窗口组件上窗口移除之后的事件 + this.applyComponentsFunction(this.node, EventOnRemoved, this.params.params); + } + + private applyComponentsFunction(node: Node, funName: string, params: any) { + for (let i = 0; i < node.components.length; i++) { + const component: any = node.components[i]; + const func = component[funName]; + if (func) { + func.call(component, params); + } + } + } + + onDestroy() { + this.params = null!; + this.onCloseWindowBefore = null!; + this.onCloseWindow = null!; + } +} + +/** 本类型仅供gui模块内部使用,请勿在功能逻辑中使用 */ +export class UIParams { + /** 界面唯一编号 */ + uiid: string = null!; + /** 界面配置 */ + config: UIConfig = null!; + /** 传递给打开界面的参数 */ + params: any = null!; + /** 窗口事件 */ + callbacks: UICallbacks = null!; + /** 是否在使用状态 */ + valid: boolean = true; + /** 界面根节点 */ + node: Node = null!; +} + +/*** 界面回调参数对象定义 */ +export interface UICallbacks { + /** + * 节点添加到层级以后的回调 + * @param node 当前界面节点 + * @param params 外部传递参数 + */ + onAdded?: (node: Node, params: any) => void, + + /** + * 窗口节点 destroy 之后回调 + * @param node 当前界面节点 + * @param params 外部传递参数 + */ + onRemoved?: (node: Node | null, params: any) => void, + + /** + * 如果指定onBeforeRemoved,则next必须调用,否则节点不会被正常删除。 + * + * 比如希望节点做一个FadeOut然后删除,则可以在`onBeforeRemoved`当中播放action动画,动画结束后调用next + * @param node 当前界面节点 + * @param next 回调方法 + */ + onBeforeRemove?: (node: Node, next: Function) => void, + + /** 网络异常时,窗口加载失败回调 */ + onLoadFailure?: () => void; } \ No newline at end of file diff --git a/assets/core/gui/layer/Defines.ts.meta b/assets/core/gui/layer/LayerUIElement.ts.meta similarity index 33% rename from assets/core/gui/layer/Defines.ts.meta rename to assets/core/gui/layer/LayerUIElement.ts.meta index 98233a9..3caf651 100644 --- a/assets/core/gui/layer/Defines.ts.meta +++ b/assets/core/gui/layer/LayerUIElement.ts.meta @@ -1,13 +1,9 @@ -{ - "ver": "4.0.24", - "importer": "typescript", - "imported": true, - "uuid": "82d3af5c-ef52-4490-8f79-777aac7079bc", - "files": [], - "subMetas": {}, - "userData": { - "moduleId": "project:///assets/script/core/gui/layer/Defines.js", - "importerSettings": 4, - "simulateGlobals": [] - } -} +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "e7207ab9-8ef7-49af-9c19-84f4d6a2e589", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/module/common/ModuleUtil.ts b/assets/module/common/ModuleUtil.ts index ac3bfdf..9b58360 100644 --- a/assets/module/common/ModuleUtil.ts +++ b/assets/module/common/ModuleUtil.ts @@ -2,7 +2,7 @@ import { Node, __private } from "cc"; import { oops } from "../../core/Oops"; import { resLoader } from "../../core/common/loader/ResLoader"; import { UICallbacks } from "../../core/gui/layer/Defines"; -import { DelegateComponent } from "../../core/gui/layer/DelegateComponent"; +import { LayerUIElement } from "../../core/gui/layer/LayerUIElement"; import { Uiid } from "../../core/gui/layer/LayerEnum"; import { UIConfig } from "../../core/gui/layer/UIConfig"; import { ViewUtil } from "../../core/utils/ViewUtil"; @@ -97,15 +97,15 @@ export class ModuleUtil { return; } - const comp = node.getComponent(DelegateComponent); + const comp = node.getComponent(LayerUIElement); if (comp) { - if (comp.vp.callbacks.onBeforeRemove) { + if (comp.params.callbacks.onBeforeRemove) { comp.onCloseWindowBefore = () => { ent.remove(ctor, isDestroy); if (onRemoved) onRemoved(); }; } - else if (comp.vp.callbacks.onRemoved) { + else if (comp.params.callbacks.onRemoved) { comp.onCloseWindow = () => { ent.remove(ctor, isDestroy); if (onRemoved) onRemoved(); -- Gitee From bb2bd8bc635011bd179c20391ac39f4d117d6fc4 Mon Sep 17 00:00:00 2001 From: wangxuhe <1053066913@qq.com> Date: Sat, 16 Aug 2025 11:04:17 +0800 Subject: [PATCH 16/16] =?UTF-8?q?Add=EF=BC=9A=20ArrayUtil=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=9A=8F=E6=9C=BA=E6=89=93=E4=B9=B1=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=A6=82=EF=BC=9A[1,2,3,4,5]=20-->?= =?UTF-8?q?=20[5,=201,=202,=203,=204]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/utils/ArrayUtil.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/assets/core/utils/ArrayUtil.ts b/assets/core/utils/ArrayUtil.ts index 1d7eb75..cd26962 100644 --- a/assets/core/utils/ArrayUtil.ts +++ b/assets/core/utils/ArrayUtil.ts @@ -97,13 +97,32 @@ export class ArrayUtil { } /** - * 获取随机数组成员 + * 获取数组中随机成员 * @param array 目标数组 */ static getRandomValueInArray(array: any[]): any { return array[Math.floor(Math.random() * array.length)]; } + /** + * 随机打乱数组 + * @param array 目标数组 + * @example [1,2,3,4,5] --> [5, 1, 2, 3, 4] + */ + static shuffleArray(array: T[]): T[] { + // 创建一个原数组的副本 + const newArr = [...array]; + + // 使用Fisher-Yates 洗牌算法打乱新数组 + for (let i = newArr.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [newArr[i], newArr[j]] = [newArr[j], newArr[i]]; + } + + // 返回打乱后的新数组 + return newArr; + } + /** * 获取连续数字数组, 范围在[start, end]之间 * @param start 开始数字 -- Gitee