HumanBreak/src/types/util.d.ts

906 lines
24 KiB
TypeScript
Raw Normal View History

2022-11-13 18:02:05 +08:00
/** 工具类 主要用来进行一些辅助函数的计算 */
interface Utils {
2022-11-13 18:02:05 +08:00
/**
*
*/
readonly scan: DeepReadonly<Scan>;
/**
*
*/
readonly scan2: DeepReadonly<Scan2>;
/**
* ${}
* @example
* // 把主角的生命值和持有的黄钥匙数量代入这句话
* core.replaceText('衬衫的价格是${status:hp}镑${item:yellowKey}便士。');
* @param text 使${}js表达式
* @param prefix
2022-11-13 18:02:05 +08:00
* @returns
*/
replaceText(text: string, prefix?: string): string;
/**
* 如status:xxx等
*
* @example
* // 把这两个冒号表达式替换为core.getStatus('hp')和core.itemCount('yellowKey')这样的函数调用
* core.replaceValue('衬衫的价格是${status:hp}镑${item:yellowKey}便士。');
2022-11-13 18:02:05 +08:00
* @param value
* @returns
*/
replaceValue(value: string): string;
/**
* 支持status:xxx等的计算
* @example core.calValue('status:hp + status:def'); // 计算主角的生命值加防御力
* @param value
* @param prefix
* @returns
*/
calValue(value: string | Function, prefix?: string): any;
2022-11-13 18:02:05 +08:00
/**
* @deprecated
* ba的开头Array.unshift就行
2022-11-13 18:02:05 +08:00
* @example core.unshift(todo, {type: 'unfollow'}); // 在事件指令数组todo的开头插入“取消所有跟随者”指令
* @param a
* @param b
* @returns a本身得到的
*/
unshift<A extends any[], B extends any[]>(a: A, b: B): [...B, ...A];
2022-11-13 18:02:05 +08:00
/**
* @deprecated
* ba的末尾Array.push就行
2022-11-13 18:02:05 +08:00
* @example core.push(todo, {type: 'unfollow'}); // 在事件指令数组todo的末尾插入“取消所有跟随者”指令
* @param a
* @param b
* @returns a本身得到的
*/
push<A extends any[], B extends any[]>(a: A, b: B): [...A, ...B];
/**
*
* @param
*/
decompress(value: string): any;
/**
*
* @param key
* @param value
*/
setLocalStorage(key: string, value?: any): void;
/**
*
* @param key
* @param defaultValue
*/
getLocalStorage<T>(key: string, defaultValue?: T): T;
/**
*
* @param key
*/
removeLocalStorage(key: string): void;
/**
* localforage
* @param key
* @param value
* @param successCallback
* @param errorCallback
*/
setLocalForage(
key: string,
value?: any,
successCallback?: () => void,
errorCallback?: (err: Error) => void
): void;
/**
* localforage读出一段数据
*/
getLocalForage<T>(
key: string,
defaultValue?: T,
successCallback?: (data: T) => void,
errorCallback?: (err: Error) => void
): void;
/**
* localforage的数据
*/
removeLocalForage(
key: string,
successCallback?: () => void,
errorCallback?: (err: Error) => void
): void;
/**
* localforage所有的数据
* @param callback
*/
clearLocalForage(callback?: (err?: Error) => void): void;
/**
* localforage的数据
* @param iteratee
* @param callback
*/
iterateLocalForage<T, U>(
iteratee: (value: T, key: string, iterationNumber: number) => U,
callback?: (err: any, result: U) => void
): void;
/**
* localforage数据的所有的键
* @param callback
*/
keysLocalForage(callback?: (err: any, keys: string[]) => void): void;
/**
* localforage数据的数据量
* @param callback
*/
lengthLocalForage(
callback?: (err: any, numberOfKeys: number) => void
): void;
2022-11-13 18:02:05 +08:00
/**
* 适用于global:xxx
* @example core.setBlobal('一周目已通关', true); // 设置全局存储“一周目已通关”为true方便二周目游戏中的新要素。
* @param key
* @param value null表示清除此全局存储
*/
setGlobal(key: string, value?: any): void;
/**
* 适用于global:xxx
* @example if (core.getGlobal('一周目已通关', false) === true) core.getItem('dagger'); // 二周目游戏进行到此处时会获得一把屠龙匕首
* @param key
* @param defaultValue nullundefined时
* @returns
*/
getGlobal<T>(key: string, defaultValue?: T): T;
2022-11-13 18:02:05 +08:00
/**
* ()
* @example core.clone(core.status.hero, (name, value) => (name == 'items' || typeof value == 'number'), false); // 深拷贝主角的属性和道具
* @param data
* @param filter data为数组或对象时拷贝哪些项或属性true表示拷贝
* @param recursion true表示过滤器也被递归
* @returns
*/
clone<T>(
data: T,
2022-11-13 18:02:05 +08:00
filter?: (name: string, value: any) => boolean,
recursion?: boolean
): T;
/**
* 1D或2D的数组
* @param data
*/
cloneArray<T extends any[]>(data: T): T;
2022-11-13 18:02:05 +08:00
/**
*
* @example core.splitImage(core.material.images.images['npc48.png'], 32, 48); // 把npc48.png切分成若干32×48px的小人
* @param image []
* @param width 32
* @param height
* @returns
*/
splitImage(
image: NameMapIn<ImageIds> | ImageIds | HTMLImageElement,
2022-11-13 18:02:05 +08:00
width?: number,
height?: number
): HTMLImageElement[];
/**
*
* @param date
* @returns 格式: yyyy-mm-dd hh:mm:ss
*/
formatDate(date?: Date): string;
/**
*
* @param date
* @returns 格式: yyyymmddhhmmss
*/
formatDate2(date?: Date): string;
/**
*
* @param time
* @returns 格式: hh:mm:ss
*/
formatTime(time: number): string;
/**
* @deprecated
* 使setDigits代替
*/
setTwoDigits(x: number): string;
/**
* n位数显示
* @param x
* @param n
*/
setDigits(x: number, n: number): string;
/**
*
* @param size
* @returns xx.xxB KB MB
*/
formatSize(size: number): string;
2022-11-13 18:02:05 +08:00
/**
* 10000w,e,z,j,g
* @example core.formatBigNumber(123456789); // "12346w"
2022-11-13 18:02:05 +08:00
* @param x
* @param onMap
2022-11-13 18:02:05 +08:00
* @returns
*/
2023-01-09 20:36:40 +08:00
formatBigNumber<T extends string>(x: T, onMap?: number): T;
2023-06-30 21:56:54 +08:00
formatBigNumber(x: number | string, onMap?: number | boolean): string;
2022-11-13 18:02:05 +08:00
/**
* @deprecated
* mutate-animate代替
* @param mode
*/
applyEasing(mode?: EaseMode): (x: number) => number;
2022-11-13 18:02:05 +08:00
/**
*
* @example core.arrayToRGB([102, 204, 255]); // "#66ccff",加载画面的宣传色
* @param color 255
* @returns 使
*/
2023-07-12 12:01:35 +08:00
arrayToRGB(color: RGBArray): _RGBA;
2022-11-13 18:02:05 +08:00
/**
*
* @example core.arrayToRGBA([102, 204, 255]); // "rgba(102,204,255,1)"
* @param color 255
* 011
2022-11-13 18:02:05 +08:00
* @returns
*/
arrayToRGBA(color: Color): _RGBA;
2022-11-13 18:02:05 +08:00
/**
* base64压缩
* @example core.encodeRoute(core.status.route); // 一压当前录像
* @param route 0-9A-Za-z和下划线
* JSON.stringify预处理再base64压缩才能交由一压
2022-11-13 18:02:05 +08:00
* @returns
*/
encodeRoute(route: string[]): string;
/**
*
* @example core.decodeRoute(core.encodeRoute(core.status.route)); // 一压当前录像再解压-_-|
* @param route
* @returns
*/
decodeRoute(route: string): string[];
/**
* nullundefined和NaN
* @example core.isset(0/0); // false因为0/0等于NaN
* @param v
* @returns false表示待测值为nullundefinedNaN或未填写true表示为其他值
2022-11-13 18:02:05 +08:00
*/
isset(v?: any): boolean;
/**
*
2022-11-13 18:02:05 +08:00
* @example core.subarray(['ad', '米库', '小精灵', '小破草', '小艾'], ['ad', '米库', '小精灵']); // ['小破草', '小艾']
* @param a b短将返回null
* @param b a长将返回null
* @returns b不是a的前缀将返回nulla去掉此前缀后的剩余数组
*/
subarray(a: any[], b: any[]): any[] | null;
2022-11-13 18:02:05 +08:00
/**
* @deprecated
* array是不是一个数组element是否在该数组中使Array.includes代替
2022-11-13 18:02:05 +08:00
* @param array false
* @param element
* @returns array为数组且具有element这项truefalse
*/
inArray(array?: any, element?: any): boolean;
/**
* x限定在[a,b]a和b可交换
* @example core.clamp(1200, 1, 1000); // 1000
* @param x !x为true时x一律视为0
* @param a b将导致与b交换
* @param b a将导致与a交换
*/
clamp(x: number, a: number, b: number): number;
/**
* 访cookie
*/
getCookie(name: string): string;
2022-11-13 18:02:05 +08:00
/**
*
* @example
* // 更新状态栏中的主角生命,使用加载画面的宣传色
* core.setStatusBarInnerHTML('hp', core.status.hero.hp, 'color: #66CCFF');
2022-11-13 18:02:05 +08:00
* @param name 'hp', 'atk', 'def'core.statusBar中的一个合法项
* @param value 6
* @param css css样式
*/
setStatusBarInnerHTML(
name: string,
value: string | number,
css?: string
): void;
2022-11-13 18:02:05 +08:00
/**
* Verdana不是等宽字体
* @example core.strlen('无敌ad'); // 6
* @param str
* @returns 2ASCII字符为1
*/
strlen(str: string): number;
/**
*
* @param turn
* @param direction
*/
turnDirection(turn: HeroTurnDir, direction?: Dir): string;
2022-11-13 18:02:05 +08:00
/**
*
* @example core.playSound(core.matchWildcard('*Key', itemId) ? 'item.mp3' : 'door.mp3'); // 判断捡到的是钥匙还是别的道具,从而播放不同的音效
* @param pattern 0
* @param string
* @returns true表示匹配成功false表示匹配失败
*/
matchWildcard(pattern: string, string: string): boolean;
/**
* /RegExp/.test(str)
* @param pattern
* @param string
*/
matchRegex(pattern: string, string: string): string;
2022-11-13 18:02:05 +08:00
/**
* base64加密
* @example
* core.encodeBase64('If you found this note in a small wooden box with a heart on it');
* // "SWYgeW91IGZvdW5kIHRoaXMgbm90ZSBpbiBhIHNtYWxsIHdvb2RlbiBib3ggd2l0aCBhIGhlYXJ0IG9uIGl0"
2022-11-13 18:02:05 +08:00
* @param str
* @returns
*/
encodeBase64(str: string): string;
/**
* base64解密
* @example
* core.decodeBase64('SWYgeW91IGZvdW5kIHRoaXMgbm90ZSBpbiBhIHNtYWxsIHdvb2RlbiBib3ggd2l0aCBhIGhlYXJ0IG9uIGl0');
* // "If you found this note in a small wooden box with a heart on it"
2022-11-13 18:02:05 +08:00
* @param str
* @returns
*/
decodeBase64(str: string): string;
/**
* SL的随机数
* @exmaple 1 + core.rand(6); // 随机生成一个小于7的正整数模拟骰子的效果
* @param num num的随机自然数1
* @returns 使
*/
rand(num?: number): number;
/**
* SL的随机数
* @exmaple 1 + core.rand2(6); // 随机生成一个小于7的正整数模拟骰子的效果
* @param num 02147483648
* @returns [0, num)
*/
rand2(num?: number): number;
/**
* []
* @param success
* @param error
* @param accept input元素的accept属性
* @param readType DataUrl形式读取
*/
readFile(
success: (obj: any) => void,
error: () => void,
accept: string,
readType: boolean
): void;
/**
* []
* @param content
*/
readFileContent(content: string): void;
2022-11-13 18:02:05 +08:00
/**
*
* @example core.download('route.txt', core.status.route); // 弹窗请求下载录像
* @param filename
* @param content
*/
download(filename: string, content: string | string[]): void;
/**
*
* @param data 西
*/
copy(data: string): void;
2022-11-13 18:02:05 +08:00
/**
* core.drawConfirmBox()
* @example core.myconfirm('重启游戏?', core.restart); // 弹窗询问玩家是否重启游戏
* @param hint
* @param yesCallback
* @param noCallback
2022-11-13 18:02:05 +08:00
*/
myconfirm(
hint: string,
yesCallback: () => void,
noCallback?: () => void
): void;
/**
*
2022-11-13 18:02:05 +08:00
*/
myprompt(
hint: string,
value: string,
callback?: (data?: string) => void
): void;
2022-11-13 18:02:05 +08:00
/**
* @deprecated
* vue了Transition组件和css的transition比这个强得多
2022-11-13 18:02:05 +08:00
*/
showWithAnimate(
obj?: HTMLElement,
speed?: number,
callback?: () => any
): void;
2022-11-13 18:02:05 +08:00
/**
* @deprecated
* 使
2022-11-13 18:02:05 +08:00
*/
hideWithAnimate(
obj?: HTMLElement,
speed?: number,
callback?: () => any
): void;
2022-11-13 18:02:05 +08:00
/**
* guid
2022-11-13 18:02:05 +08:00
*/
getGuid(): string;
/**
*
* @param obj
*/
hashCode(obj: any): number;
/**
* ,
* @example core.same(['1', 2], ['1', 2]); // true
*/
same(a: any, b: any): boolean;
/**
*
*/
unzip(
blobOrUrl: string | Blob,
success?: (data: any) => void,
error?: (error: string) => void,
convertToText?: boolean,
onprogress?: (loaded: number, total: number) => void
): void;
2022-11-13 18:02:05 +08:00
/**
* HTTP请求 []
* @param type
* @param url
* @param formData POST请求则为表单数据
* @param success
* @param error
*/
http(
type: 'GET' | 'POST',
url: string,
formData?: FormData,
success?: (res: any) => void,
error?: (err: string) => void,
mimeType?: string,
responseType?: XMLHttpRequestResponseType,
onProgress?: (loaded: number, total: number) => void
2022-11-13 18:02:05 +08:00
): void;
}
2022-11-13 18:02:05 +08:00
declare const utils: new () => Utils;
2024-05-01 10:49:54 +08:00
interface JSInterface {
requestLandscape(): void;
requestPortrait(): void;
}
interface Window {
jsinterface: JSInterface;
}
declare const jsinterface: JSInterface;
/**
*
*/
type Step = Move | 'backward';
/**
*
*/
type LocString = `${number},${number}`;
type _RGBA =
| `rgb(${number},${number},${number})`
| `rgba(${number},${number},${number},${number})`;
/**
* RGBA颜色数组
*/
type RGBArray = [number, number, number, number?];
/**
*
*/
type Color = `#${string}` | _RGBA | RGBArray | 'transparent';
/**
*
*/
type Dir = 'up' | 'down' | 'left' | 'right';
/**
*
*/
type Dir2 = Dir | 'leftup' | 'rightup' | 'leftdown' | 'rightdown';
/**
*
*/
type TurnDir = Dir | ':left' | ':right' | ':back';
/**
*
*/
type HeroTurnDir = TurnDir | ':hero' | ':backhero';
/**
*
*/
type TextPosition = 'up' | 'center' | 'down';
/**
*
*/
type Move = 'forward' | Dir;
/**
*
*/
type EaseMode = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut';
/**
* \
* += \
* -= \
* *= \
* /= \
* //= 除以并取商\
* **= \
* %= \
* min= \
* max= \
*
*/
type MotaOperator =
| '+='
| '-='
| '*='
| '/='
| '//='
| '**='
| '%='
| 'min='
| 'max='
| '=';
/**
*
*/
type LocArr = [x: number, y: number];
/**
*
*/
interface Loc {
/**
*
*/
x: number;
2022-11-13 18:02:05 +08:00
/**
*
*/
y: number;
}
2022-11-13 18:02:05 +08:00
/**
*
*/
interface DiredLoc extends Loc {
/**
*
*/
direction: Dir;
}
2022-11-13 18:02:05 +08:00
interface CompressedStep {
/**
*
*/
direction: Dir;
2022-11-13 18:02:05 +08:00
/**
*
*/
step: number;
}
2022-11-13 18:02:05 +08:00
/**
*
*/
type Scan = {
[D in Dir]: Loc;
};
2022-11-13 18:02:05 +08:00
/**
*
*/
type Scan2 = {
[D in Dir2]: Loc;
};
2022-11-13 18:02:05 +08:00
/**
*
*/
type ImageReverse = ':o' | ':x' | ':y';
/**
*
*/
type TextBoxDir = 'up' | 'down';
/**
*
*/
type TextBoxPos =
| `${TextBoxDir},hero`
| `${TextBoxDir},${number},${number}`
| TextPosition;
/**
*
*/
type CtxRefer = string | CanvasRenderingContext2D | HTMLCanvasElement;
/**
*
*/
type MotaTrigger =
| 'battle'
| 'pusBox'
| 'openDoor'
| 'ski'
| 'custom'
2024-02-01 19:31:49 +08:00
| 'getItem'
| 'changeFloor'
| 'null';
/**
*
*/
type FloorChangeStair =
| 'upFloor'
| 'downFloor'
| ':symmetry'
| ':symmetry_x'
| ':symmetry_y'
| 'flyPoint';
/**
*
*/
type EventValuePreffix =
| 'status'
| 'flag'
| 'item'
| 'buff'
| 'switch'
| 'temp'
| 'global';
2022-11-13 18:02:05 +08:00
interface Animate {
2022-11-13 18:02:05 +08:00
/**
* s
2022-11-13 18:02:05 +08:00
*/
frame: number;
2022-11-13 18:02:05 +08:00
/**
*
*/
frames: FrameObj[][];
2022-11-13 18:02:05 +08:00
/**
*
*/
images: HTMLImageElement[];
2022-11-13 18:02:05 +08:00
/**
*
*/
ratio: number;
2022-11-13 18:02:05 +08:00
/**
*
*/
se: string;
2022-11-13 18:02:05 +08:00
}
type Save = DeepReadonly<{
/**
* id
*/
floorId: FloorIds;
2022-11-13 18:02:05 +08:00
/**
*
*/
hero: HeroStatus;
2022-11-13 18:02:05 +08:00
/**
*
*/
hard: number;
2022-11-13 18:02:05 +08:00
/**
*
*/
maps: Record<string, ResolvedFloor>;
2022-11-13 18:02:05 +08:00
/**
*
*/
route: string;
2022-11-13 18:02:05 +08:00
/**
*
*/
values: CoreValues;
2022-11-13 18:02:05 +08:00
/**
*
*/
version: string;
2022-11-13 18:02:05 +08:00
/**
* guid
*/
guid: string;
2022-11-13 18:02:05 +08:00
/**
*
*/
time: number;
}>;
2022-11-13 18:02:05 +08:00
/**
* 使
*/
type DeepReadonly<T> = {
readonly [P in keyof T]: T[P] extends number | string | boolean
? T[P]
: DeepReadonly<T[P]>;
2022-11-13 18:02:05 +08:00
};
/**
2023-02-15 13:19:05 +08:00
* 使
*/
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends number | string | boolean
? T[P]
2023-02-15 13:19:05 +08:00
: DeepPartial<T[P]>;
2022-11-16 23:01:23 +08:00
};
/**
* 使
*/
type DeepRequired<T> = {
[P in keyof T]-?: T[P] extends number | string | boolean
? T[P]
2023-02-15 13:19:05 +08:00
: DeepRequired<T[P]>;
2022-11-30 16:42:44 +08:00
};
/**
* 使
*/
type Writable<T> = {
-readonly [P in keyof T]: T[P];
2022-11-13 18:02:05 +08:00
};
/**
* 使
*/
type DeepWritable<T> = {
-readonly [P in keyof T]: T[P] extends number | string | boolean
? T[P]
2023-02-15 13:19:05 +08:00
: DeepWritable<T[P]>;
2022-11-13 18:02:05 +08:00
};
/**
*
*/
type SelectType<R, T> = {
[P in keyof R as R[P] extends T ? P : never]: R[P];
};
2022-11-13 18:02:05 +08:00
2023-02-05 18:17:10 +08:00
/**
*
*/
type SelectKey<R, T> = keyof SelectType<R, T>;
/**
*
*/
type FirstCharOf<T extends string> = T extends `${infer F}${infer A}`
? F
: never;
/**
*
*/
type NonObject = number | string | boolean;
/**
*
*/
type NonObjectOf<T> = SelectType<T, NonObject>;
/**
*
*/
type EndsWith<T extends string> = `${string}${T}`;
2023-02-05 18:17:10 +08:00
type KeyExcludesUnderline<T> = Exclude<keyof T, `_${string}`>;
2023-04-15 20:21:29 +08:00
type ValueOf<T> = T[keyof T];