添加get.promises.zip,修复类型问题
This commit is contained in:
parent
3f3c07b0ec
commit
7c0a6d7bef
|
@ -1910,55 +1910,60 @@ export class Game extends Uninstantable {
|
|||
}
|
||||
/**
|
||||
* 下载文件
|
||||
* @type { (url: string, folder: string, onsuccess?: Function, onerror?: (e: Error) => void) => void, dev?: 'nodev', onprogress?: Function) => void }
|
||||
* @type { undefined | ((url: string, folder: string, onsuccess?: Function, onerror?: (e: Error) => void) => void, dev?: 'nodev', onprogress?: Function) => void) }
|
||||
*/
|
||||
static download;
|
||||
/**
|
||||
* 读取文件为arraybuffer
|
||||
* @type { (filename: string, callback?: (data: Buffer | ArrayBuffer) => any, onerror?: (e: Error) => void) => void }
|
||||
* @type { undefined | ((filename: string, callback?: (data: Buffer | ArrayBuffer) => any, onerror?: (e: Error) => void) => void) }
|
||||
*/
|
||||
static readFile;
|
||||
/**
|
||||
* 读取文件为文本
|
||||
* @type { (filename: string, callback?: (data: string) => any, onerror?: (e: Error) => void) => void }
|
||||
* @type { undefined | ((filename: string, callback?: (data: string) => any, onerror?: (e: Error) => void) => void) }
|
||||
*/
|
||||
static readFileAsText;
|
||||
/**
|
||||
* 将数据写入文件
|
||||
* @type { (data: File | ArrayBuffer, path: string, name: string, callback?: (e: Error) => void) => void }
|
||||
* @type { undefined | ((data: File | ArrayBuffer, path: string, name: string, callback?: (e: Error) => void) => void) }
|
||||
*/
|
||||
static writeFile;
|
||||
/**
|
||||
* 移除文件
|
||||
* @type { (filename: string, callback?: (e: Error) => void) => void }
|
||||
* @type { undefined | ((filename: string, callback?: (e: Error) => void) => void) }
|
||||
*/
|
||||
static removeFile;
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @type { (dir: string, success: (folders: string[], files: string[]) => any, failure: (e: Error) => void) => void }
|
||||
* @type { undefined | ((dir: string, success: (folders: string[], files: string[]) => any, failure: (e: Error) => void) => void) }
|
||||
*/
|
||||
static getFileList;
|
||||
/**
|
||||
* 按路径依次创建文件夹
|
||||
* @type { (list: string | string[], callback: Function, file?: boolean) => void }
|
||||
* @type { undefined | ((list: string | string[], callback: Function, file?: boolean) => void) }
|
||||
*/
|
||||
static ensureDirectory;
|
||||
/**
|
||||
* 创建文件夹
|
||||
* @type { (directory: string, successCallback?: Function, errorCallback?: Function) => void }
|
||||
* @type { undefined | ((directory: string, successCallback?: Function, errorCallback?: Function) => void) }
|
||||
*/
|
||||
static createDir;
|
||||
/**
|
||||
* 删除文件夹
|
||||
* @type { (directory: string, successCallback?: Function, errorCallback?: Function) => void }
|
||||
* @type { undefined | ((directory: string, successCallback?: Function, errorCallback?: Function) => void) }
|
||||
*/
|
||||
static removeDir;
|
||||
/**
|
||||
* @type { (forcecheck?: boolean | null, dev?: boolean) => Promise<any> }
|
||||
*/
|
||||
static checkForUpdate;
|
||||
/**
|
||||
* @type { () => Promise<any> }
|
||||
*/
|
||||
static checkForAssetUpdate;
|
||||
static async importExtension(data, finishLoad, exportExtension, extensionPackage) {
|
||||
//by 来瓶可乐加冰、Rintim、Tipx-L
|
||||
if (!window.JSZip)
|
||||
await new Promise((resolve, reject) => lib.init.js(`${lib.assetURL}game`, "jszip", resolve, reject));
|
||||
|
||||
const zip = new JSZip();
|
||||
//by 来瓶可乐加冰、Rintim、Tipx-L、诗笺
|
||||
const zip = await get.promises.zip();
|
||||
if (get.objtype(data) == 'object') {
|
||||
//导出
|
||||
const _filelist = data._filelist, filelist2 = _filelist || [];
|
||||
|
|
|
@ -6,11 +6,12 @@ import { status as _status } from '../status/index.js';
|
|||
import { UI as ui } from '../ui/index.js';
|
||||
import { GNC as gnc } from '../gnc/index.js';
|
||||
import { CacheContext } from "../library/cache/cacheContext.js";
|
||||
|
||||
import { Is } from "./is.js";
|
||||
import { Promises } from "./promises.js";
|
||||
|
||||
export class Get extends Uninstantable {
|
||||
static is = Is;
|
||||
static promises = Promises;
|
||||
/**
|
||||
* 获取当前内核版本信息
|
||||
*
|
||||
|
@ -627,6 +628,9 @@ export class Get extends Uninstantable {
|
|||
}
|
||||
static sort(arr, method, arg) { return method == "seat" ? arr.sortBySeat(arg) : void 0; }
|
||||
static sortSeat(arr, target) { return arr.sortBySeat(target); }
|
||||
/**
|
||||
* @param { (zip: JSZip) => any } callback
|
||||
*/
|
||||
static zip(callback) {
|
||||
if (!window.JSZip) {
|
||||
lib.init.js(lib.assetURL + 'game', 'jszip', function () {
|
||||
|
@ -4748,5 +4752,6 @@ export class Get extends Uninstantable {
|
|||
export const get = Get;
|
||||
|
||||
export {
|
||||
Is
|
||||
Is,
|
||||
Promises
|
||||
};
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import { get } from "./index.js";
|
||||
import { Uninstantable } from "../util/index.js";
|
||||
|
||||
export class Promises extends Uninstantable {
|
||||
/**
|
||||
* @returns { Promise<JSZip> }
|
||||
*/
|
||||
static zip() {
|
||||
return new Promise(resolve => get.zip(resolve));
|
||||
}
|
||||
}
|
|
@ -123,36 +123,38 @@ export class Library extends Uninstantable {
|
|||
*/
|
||||
static tempSortSeat;
|
||||
/**
|
||||
* @returns { never }
|
||||
*/
|
||||
static typeAnnotation() {
|
||||
/**
|
||||
* @type { Videos[] }
|
||||
*/
|
||||
// @ts-ignore
|
||||
this.videos;
|
||||
/**
|
||||
* @type { {
|
||||
* fs: typeof import("fs"),
|
||||
* path: typeof import("path"),
|
||||
* debug: () => void,
|
||||
* clients: Element.Client[],
|
||||
* banned:[],
|
||||
* observing:[],
|
||||
* torespond:{},
|
||||
* torespondtimeout:{},
|
||||
* } }
|
||||
*/
|
||||
// @ts-ignore
|
||||
this.node;
|
||||
/**
|
||||
* @type { { [key: string]: string } }
|
||||
*/
|
||||
// @ts-ignore
|
||||
this.playerOL;
|
||||
throw new Error('Do not call this method');
|
||||
}
|
||||
|
||||
* @type { 'android' | 'ios' | undefined }
|
||||
*/
|
||||
static device;
|
||||
/**
|
||||
* @type { string }
|
||||
*/
|
||||
static version;
|
||||
/**
|
||||
* @type { Videos[] }
|
||||
*/
|
||||
static videos;
|
||||
/**
|
||||
* @type { {
|
||||
* fs: typeof import("fs"),
|
||||
* path: typeof import("path"),
|
||||
* debug: () => void,
|
||||
* clients: Element.Client[],
|
||||
* banned:[],
|
||||
* observing:[],
|
||||
* torespond:{},
|
||||
* torespondtimeout:{},
|
||||
* } }
|
||||
*/
|
||||
static node;
|
||||
/**
|
||||
* @type { { [key: string]: string } }
|
||||
*/
|
||||
static playerOL;
|
||||
/**
|
||||
* @type { IDBRequest<IDBDatabase> }
|
||||
*/
|
||||
static db;
|
||||
//函数钩子
|
||||
/**
|
||||
* 你可以往这里加入{钩子名:函数数组},并在数组里增加你的自定义函数
|
||||
|
|
|
@ -292,7 +292,7 @@ export async function getRepoFilesList(path = '', branch, options = { username:
|
|||
|
||||
/**
|
||||
*
|
||||
* 获取仓库指定分支和指定目录内的所有文件和目录
|
||||
* 获取仓库指定分支和指定目录内的所有文件(包含子目录的文件)
|
||||
* @param { string } [path = ''] 路径名称(可放参数)
|
||||
* @param { string } [branch = ''] 仓库分支名称
|
||||
* @param { Object } options
|
||||
|
@ -335,7 +335,7 @@ export async function flattenRepositoryFiles(path = '', branch, options = { user
|
|||
|
||||
// 返回不含文件夹的扁平化文件列表
|
||||
return allFiles;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 请求一个文件而不是直接储存为文件
|
||||
|
|
|
@ -49,6 +49,10 @@ export const status = {
|
|||
* @type { boolean | void }
|
||||
*/
|
||||
touchconfirmed: undefined,
|
||||
/**
|
||||
* @type { boolean | void }
|
||||
*/
|
||||
connectMode: undefined,
|
||||
};
|
||||
|
||||
export const _status = status;
|
|
@ -2,6 +2,14 @@ import { ui, game, get, lib, _status } from "../../../noname.js";
|
|||
import { Uninstantable } from "../../util/index.js";
|
||||
|
||||
export class Click extends Uninstantable {
|
||||
/**
|
||||
* @type {() => void}
|
||||
*/
|
||||
static consoleMenu;
|
||||
/**
|
||||
* @type {(arg0: string) => void}
|
||||
*/
|
||||
static menuTab;
|
||||
static identitycircle() {
|
||||
var list = [];
|
||||
this.classList.toggle('transparent');
|
||||
|
|
|
@ -9,6 +9,10 @@ import { otherMenu } from "./menu/pages/otherMenu.js";
|
|||
import { startMenu } from "./menu/pages/startMenu.js";
|
||||
|
||||
export class Create extends Uninstantable {
|
||||
/**
|
||||
* @type {(video: Videos, before: boolean) => void}
|
||||
*/
|
||||
static videoNode;
|
||||
/**
|
||||
* 创建身份牌实例
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ import {
|
|||
gainAuthorization
|
||||
} from "../../../../library/update.js"
|
||||
|
||||
export const otherMenu = function (connectMenu) {
|
||||
export const otherMenu = function (/** @type { boolean | undefined } */ connectMenu) {
|
||||
if (connectMenu) return;
|
||||
/**
|
||||
* 由于联机模式会创建第二个菜单,所以需要缓存一下可变的变量
|
||||
|
@ -147,7 +147,18 @@ export const otherMenu = function (connectMenu) {
|
|||
li3.style.whiteSpace = 'nowrap';
|
||||
li3.style.display = 'none';// coding
|
||||
|
||||
var checkVersionButton, checkAssetButton, checkDevVersionButton/*, button4, button5*/;
|
||||
/**
|
||||
* @type {HTMLButtonElement}
|
||||
*/
|
||||
var checkVersionButton;
|
||||
/**
|
||||
* @type {HTMLButtonElement}
|
||||
*/
|
||||
var checkAssetButton;
|
||||
/**
|
||||
* @type {HTMLButtonElement}
|
||||
*/
|
||||
var checkDevVersionButton;
|
||||
|
||||
game.checkForUpdate = async function (forcecheck, dev) {
|
||||
if (!dev && checkVersionButton.disabled) {
|
||||
|
@ -236,8 +247,14 @@ export const otherMenu = function (connectMenu) {
|
|||
refresh();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param {{ assets: any; author?: { login: string; avatar_url: string; html_url: string; }; body?: string; html_url?: string; name: any; published_at?: string; zipball_url: any; }} description
|
||||
*/
|
||||
function download(description) {
|
||||
const progress = createProgress('正在更新' + description.name, 1, description.name + '.zip');
|
||||
/**
|
||||
* @type {progress}
|
||||
*/
|
||||
let unZipProgress;
|
||||
let url = description.zipball_url;
|
||||
if (Array.isArray(description.assets) && description.assets.length > 0) {
|
||||
|
@ -262,8 +279,8 @@ export const otherMenu = function (connectMenu) {
|
|||
progress.setProgressValue(received);
|
||||
}).then(async blob => {
|
||||
progress.remove();
|
||||
await import('../../../../../game/jszip.js');
|
||||
const zip = new window.JSZip().load(await blob.arrayBuffer());
|
||||
const zip = await get.promises.zip();
|
||||
zip.load(await blob.arrayBuffer());
|
||||
const entries = Object.entries(zip.files);
|
||||
let root;
|
||||
const hiddenFileFlags = ['.', '_'];
|
||||
|
@ -317,11 +334,13 @@ export const otherMenu = function (connectMenu) {
|
|||
});
|
||||
}
|
||||
unZipProgress.remove();
|
||||
// await import('../../../../../game/update.js');
|
||||
// if (Array.isArray(window.noname_asset_list)) {
|
||||
// game.saveConfig('asset_version', window.noname_asset_list[0]);
|
||||
// delete window.noname_asset_list;
|
||||
// }
|
||||
if (url === description.zipball_url) {
|
||||
await lib.init.promises.js('game', 'update.js');
|
||||
if (Array.isArray(window.noname_asset_list)) {
|
||||
game.saveConfig('asset_version', window.noname_asset_list[0]);
|
||||
delete window.noname_asset_list;
|
||||
}
|
||||
}
|
||||
if (confirm('更新完成,是否重启?')) {
|
||||
game.reload();
|
||||
}
|
||||
|
@ -397,18 +416,14 @@ export const otherMenu = function (connectMenu) {
|
|||
})
|
||||
}).then(async blob => {
|
||||
progress.remove();
|
||||
await import('../../../../../game/jszip.js');
|
||||
const zip = new window.JSZip().load(await blob.arrayBuffer());
|
||||
const zip = await get.promises.zip();
|
||||
zip.load(await blob.arrayBuffer());
|
||||
const entries = Object.entries(zip.files);
|
||||
let root;
|
||||
const hiddenFileFlags = ['.', '_'];
|
||||
unZipProgress = createProgress('正在解压' + progress.getFileName(), entries.length);
|
||||
let i = 0;
|
||||
for (const [key, value] of entries) {
|
||||
// 第一个是文件夹的话,就是根文件夹
|
||||
// if (i == 0 && value.dir && !description.name.includes('noname.core.zip')) {
|
||||
// root = key;
|
||||
// }
|
||||
unZipProgress.setProgressValue(i++);
|
||||
const fileName = typeof root == 'string' && key.startsWith(root) ? key.replace(root, '') : key;
|
||||
if (hiddenFileFlags.includes(fileName[0])) continue;
|
||||
|
@ -422,11 +437,11 @@ export const otherMenu = function (connectMenu) {
|
|||
await game.promises.writeFile(value.asArrayBuffer(), path, name);
|
||||
}
|
||||
unZipProgress.remove();
|
||||
// await import('../../../../../game/update.js');
|
||||
// if (Array.isArray(window.noname_asset_list)) {
|
||||
// game.saveConfig('asset_version', window.noname_asset_list[0]);
|
||||
// delete window.noname_asset_list;
|
||||
// }
|
||||
await lib.init.promises.js('game', 'update.js');
|
||||
if (Array.isArray(window.noname_asset_list)) {
|
||||
game.saveConfig('asset_version', window.noname_asset_list[0]);
|
||||
delete window.noname_asset_list;
|
||||
}
|
||||
if (confirm('更新完成,是否重启?')) {
|
||||
game.reload();
|
||||
}
|
||||
|
@ -459,6 +474,8 @@ export const otherMenu = function (connectMenu) {
|
|||
// }
|
||||
|
||||
(function () {
|
||||
/** @type { HTMLParagraphElement } */
|
||||
// @ts-ignore
|
||||
var updatep1 = li1.querySelector('p');
|
||||
var updatep2 = li2;
|
||||
var updatep3 = li3;
|
||||
|
|
|
@ -111,6 +111,18 @@ export class UI extends Uninstantable {
|
|||
* @type { HTMLDivElement } 挑战模式下正在操作的角色
|
||||
*/
|
||||
static mebg;
|
||||
/**
|
||||
* @type { Function | undefined }
|
||||
*/
|
||||
static updateUpdate;
|
||||
/**
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
static commandnode;
|
||||
/**
|
||||
* @type {() => void}
|
||||
*/
|
||||
static updateVideoMenu;
|
||||
static refresh(node) {
|
||||
void window.getComputedStyle(node, null).getPropertyValue("opacity");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue