添加get.promises.zip,修复类型问题

This commit is contained in:
nonameShijian 2024-04-06 21:50:53 +08:00
parent 3f3c07b0ec
commit 7c0a6d7bef
10 changed files with 136 additions and 68 deletions

View File

@ -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; static download;
/** /**
* 读取文件为arraybuffer * 读取文件为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; 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; 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; static writeFile;
/** /**
* 移除文件 * 移除文件
* @type { (filename: string, callback?: (e: Error) => void) => void } * @type { undefined | ((filename: string, callback?: (e: Error) => void) => void) }
*/ */
static removeFile; 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; static getFileList;
/** /**
* 按路径依次创建文件夹 * 按路径依次创建文件夹
* @type { (list: string | string[], callback: Function, file?: boolean) => void } * @type { undefined | ((list: string | string[], callback: Function, file?: boolean) => void) }
*/ */
static ensureDirectory; static ensureDirectory;
/** /**
* 创建文件夹 * 创建文件夹
* @type { (directory: string, successCallback?: Function, errorCallback?: Function) => void } * @type { undefined | ((directory: string, successCallback?: Function, errorCallback?: Function) => void) }
*/ */
static createDir; static createDir;
/** /**
* 删除文件夹 * 删除文件夹
* @type { (directory: string, successCallback?: Function, errorCallback?: Function) => void } * @type { undefined | ((directory: string, successCallback?: Function, errorCallback?: Function) => void) }
*/ */
static removeDir; static removeDir;
/**
* @type { (forcecheck?: boolean | null, dev?: boolean) => Promise<any> }
*/
static checkForUpdate;
/**
* @type { () => Promise<any> }
*/
static checkForAssetUpdate;
static async importExtension(data, finishLoad, exportExtension, extensionPackage) { static async importExtension(data, finishLoad, exportExtension, extensionPackage) {
//by 来瓶可乐加冰、Rintim、Tipx-L //by 来瓶可乐加冰、Rintim、Tipx-L、诗笺
if (!window.JSZip) const zip = await get.promises.zip();
await new Promise((resolve, reject) => lib.init.js(`${lib.assetURL}game`, "jszip", resolve, reject));
const zip = new JSZip();
if (get.objtype(data) == 'object') { if (get.objtype(data) == 'object') {
//导出 //导出
const _filelist = data._filelist, filelist2 = _filelist || []; const _filelist = data._filelist, filelist2 = _filelist || [];

View File

@ -6,11 +6,12 @@ import { status as _status } from '../status/index.js';
import { UI as ui } from '../ui/index.js'; import { UI as ui } from '../ui/index.js';
import { GNC as gnc } from '../gnc/index.js'; import { GNC as gnc } from '../gnc/index.js';
import { CacheContext } from "../library/cache/cacheContext.js"; import { CacheContext } from "../library/cache/cacheContext.js";
import { Is } from "./is.js"; import { Is } from "./is.js";
import { Promises } from "./promises.js";
export class Get extends Uninstantable { export class Get extends Uninstantable {
static is = Is; 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 sort(arr, method, arg) { return method == "seat" ? arr.sortBySeat(arg) : void 0; }
static sortSeat(arr, target) { return arr.sortBySeat(target); } static sortSeat(arr, target) { return arr.sortBySeat(target); }
/**
* @param { (zip: JSZip) => any } callback
*/
static zip(callback) { static zip(callback) {
if (!window.JSZip) { if (!window.JSZip) {
lib.init.js(lib.assetURL + 'game', 'jszip', function () { lib.init.js(lib.assetURL + 'game', 'jszip', function () {
@ -4748,5 +4752,6 @@ export class Get extends Uninstantable {
export const get = Get; export const get = Get;
export { export {
Is Is,
Promises
}; };

11
noname/get/promises.js Normal file
View File

@ -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));
}
}

View File

@ -123,14 +123,17 @@ export class Library extends Uninstantable {
*/ */
static tempSortSeat; static tempSortSeat;
/** /**
* @returns { never } * @type { 'android' | 'ios' | undefined }
*/ */
static typeAnnotation() { static device;
/**
* @type { string }
*/
static version;
/** /**
* @type { Videos[] } * @type { Videos[] }
*/ */
// @ts-ignore static videos;
this.videos;
/** /**
* @type { { * @type { {
* fs: typeof import("fs"), * fs: typeof import("fs"),
@ -143,16 +146,15 @@ export class Library extends Uninstantable {
* torespondtimeout:{}, * torespondtimeout:{},
* } } * } }
*/ */
// @ts-ignore static node;
this.node;
/** /**
* @type { { [key: string]: string } } * @type { { [key: string]: string } }
*/ */
// @ts-ignore static playerOL;
this.playerOL; /**
throw new Error('Do not call this method'); * @type { IDBRequest<IDBDatabase> }
} */
static db;
//函数钩子 //函数钩子
/** /**
* 你可以往这里加入{钩子名:函数数组}并在数组里增加你的自定义函数 * 你可以往这里加入{钩子名:函数数组}并在数组里增加你的自定义函数

View File

@ -292,7 +292,7 @@ export async function getRepoFilesList(path = '', branch, options = { username:
/** /**
* *
* 获取仓库指定分支和指定目录内的所有文件和目录 * 获取仓库指定分支和指定目录内的所有文件(包含子目录的文件)
* @param { string } [path = ''] 路径名称(可放参数) * @param { string } [path = ''] 路径名称(可放参数)
* @param { string } [branch = ''] 仓库分支名称 * @param { string } [branch = ''] 仓库分支名称
* @param { Object } options * @param { Object } options
@ -335,7 +335,7 @@ export async function flattenRepositoryFiles(path = '', branch, options = { user
// 返回不含文件夹的扁平化文件列表 // 返回不含文件夹的扁平化文件列表
return allFiles; return allFiles;
} };
/** /**
* 请求一个文件而不是直接储存为文件 * 请求一个文件而不是直接储存为文件

View File

@ -49,6 +49,10 @@ export const status = {
* @type { boolean | void } * @type { boolean | void }
*/ */
touchconfirmed: undefined, touchconfirmed: undefined,
/**
* @type { boolean | void }
*/
connectMode: undefined,
}; };
export const _status = status; export const _status = status;

View File

@ -2,6 +2,14 @@ import { ui, game, get, lib, _status } from "../../../noname.js";
import { Uninstantable } from "../../util/index.js"; import { Uninstantable } from "../../util/index.js";
export class Click extends Uninstantable { export class Click extends Uninstantable {
/**
* @type {() => void}
*/
static consoleMenu;
/**
* @type {(arg0: string) => void}
*/
static menuTab;
static identitycircle() { static identitycircle() {
var list = []; var list = [];
this.classList.toggle('transparent'); this.classList.toggle('transparent');

View File

@ -9,6 +9,10 @@ import { otherMenu } from "./menu/pages/otherMenu.js";
import { startMenu } from "./menu/pages/startMenu.js"; import { startMenu } from "./menu/pages/startMenu.js";
export class Create extends Uninstantable { export class Create extends Uninstantable {
/**
* @type {(video: Videos, before: boolean) => void}
*/
static videoNode;
/** /**
* 创建身份牌实例 * 创建身份牌实例
*/ */

View File

@ -29,7 +29,7 @@ import {
gainAuthorization gainAuthorization
} from "../../../../library/update.js" } from "../../../../library/update.js"
export const otherMenu = function (connectMenu) { export const otherMenu = function (/** @type { boolean | undefined } */ connectMenu) {
if (connectMenu) return; if (connectMenu) return;
/** /**
* 由于联机模式会创建第二个菜单所以需要缓存一下可变的变量 * 由于联机模式会创建第二个菜单所以需要缓存一下可变的变量
@ -147,7 +147,18 @@ export const otherMenu = function (connectMenu) {
li3.style.whiteSpace = 'nowrap'; li3.style.whiteSpace = 'nowrap';
li3.style.display = 'none';// coding 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) { game.checkForUpdate = async function (forcecheck, dev) {
if (!dev && checkVersionButton.disabled) { if (!dev && checkVersionButton.disabled) {
@ -236,8 +247,14 @@ export const otherMenu = function (connectMenu) {
refresh(); 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) { function download(description) {
const progress = createProgress('正在更新' + description.name, 1, description.name + '.zip'); const progress = createProgress('正在更新' + description.name, 1, description.name + '.zip');
/**
* @type {progress}
*/
let unZipProgress; let unZipProgress;
let url = description.zipball_url; let url = description.zipball_url;
if (Array.isArray(description.assets) && description.assets.length > 0) { if (Array.isArray(description.assets) && description.assets.length > 0) {
@ -262,8 +279,8 @@ export const otherMenu = function (connectMenu) {
progress.setProgressValue(received); progress.setProgressValue(received);
}).then(async blob => { }).then(async blob => {
progress.remove(); progress.remove();
await import('../../../../../game/jszip.js'); const zip = await get.promises.zip();
const zip = new window.JSZip().load(await blob.arrayBuffer()); zip.load(await blob.arrayBuffer());
const entries = Object.entries(zip.files); const entries = Object.entries(zip.files);
let root; let root;
const hiddenFileFlags = ['.', '_']; const hiddenFileFlags = ['.', '_'];
@ -317,11 +334,13 @@ export const otherMenu = function (connectMenu) {
}); });
} }
unZipProgress.remove(); unZipProgress.remove();
// await import('../../../../../game/update.js'); if (url === description.zipball_url) {
// if (Array.isArray(window.noname_asset_list)) { await lib.init.promises.js('game', 'update.js');
// game.saveConfig('asset_version', window.noname_asset_list[0]); if (Array.isArray(window.noname_asset_list)) {
// delete window.noname_asset_list; game.saveConfig('asset_version', window.noname_asset_list[0]);
// } delete window.noname_asset_list;
}
}
if (confirm('更新完成,是否重启?')) { if (confirm('更新完成,是否重启?')) {
game.reload(); game.reload();
} }
@ -397,18 +416,14 @@ export const otherMenu = function (connectMenu) {
}) })
}).then(async blob => { }).then(async blob => {
progress.remove(); progress.remove();
await import('../../../../../game/jszip.js'); const zip = await get.promises.zip();
const zip = new window.JSZip().load(await blob.arrayBuffer()); zip.load(await blob.arrayBuffer());
const entries = Object.entries(zip.files); const entries = Object.entries(zip.files);
let root; let root;
const hiddenFileFlags = ['.', '_']; const hiddenFileFlags = ['.', '_'];
unZipProgress = createProgress('正在解压' + progress.getFileName(), entries.length); unZipProgress = createProgress('正在解压' + progress.getFileName(), entries.length);
let i = 0; let i = 0;
for (const [key, value] of entries) { for (const [key, value] of entries) {
// 第一个是文件夹的话,就是根文件夹
// if (i == 0 && value.dir && !description.name.includes('noname.core.zip')) {
// root = key;
// }
unZipProgress.setProgressValue(i++); unZipProgress.setProgressValue(i++);
const fileName = typeof root == 'string' && key.startsWith(root) ? key.replace(root, '') : key; const fileName = typeof root == 'string' && key.startsWith(root) ? key.replace(root, '') : key;
if (hiddenFileFlags.includes(fileName[0])) continue; if (hiddenFileFlags.includes(fileName[0])) continue;
@ -422,11 +437,11 @@ export const otherMenu = function (connectMenu) {
await game.promises.writeFile(value.asArrayBuffer(), path, name); await game.promises.writeFile(value.asArrayBuffer(), path, name);
} }
unZipProgress.remove(); unZipProgress.remove();
// await import('../../../../../game/update.js'); await lib.init.promises.js('game', 'update.js');
// if (Array.isArray(window.noname_asset_list)) { if (Array.isArray(window.noname_asset_list)) {
// game.saveConfig('asset_version', window.noname_asset_list[0]); game.saveConfig('asset_version', window.noname_asset_list[0]);
// delete window.noname_asset_list; delete window.noname_asset_list;
// } }
if (confirm('更新完成,是否重启?')) { if (confirm('更新完成,是否重启?')) {
game.reload(); game.reload();
} }
@ -459,6 +474,8 @@ export const otherMenu = function (connectMenu) {
// } // }
(function () { (function () {
/** @type { HTMLParagraphElement } */
// @ts-ignore
var updatep1 = li1.querySelector('p'); var updatep1 = li1.querySelector('p');
var updatep2 = li2; var updatep2 = li2;
var updatep3 = li3; var updatep3 = li3;

View File

@ -111,6 +111,18 @@ export class UI extends Uninstantable {
* @type { HTMLDivElement } 挑战模式下正在操作的角色 * @type { HTMLDivElement } 挑战模式下正在操作的角色
*/ */
static mebg; static mebg;
/**
* @type { Function | undefined }
*/
static updateUpdate;
/**
* @type {HTMLDivElement}
*/
static commandnode;
/**
* @type {() => void}
*/
static updateVideoMenu;
static refresh(node) { static refresh(node) {
void window.getComputedStyle(node, null).getPropertyValue("opacity"); void window.getComputedStyle(node, null).getPropertyValue("opacity");
} }