HumanBreak/src/types/util.d.ts

582 lines
19 KiB
TypeScript
Raw Normal View History

2022-11-13 18:02:05 +08:00
/** 工具类 主要用来进行一些辅助函数的计算 */
declare class utils {
/**
* ${}
* @example core.replaceText('衬衫的价格是${status:hp}镑${item:yellowKey}便士。'); // 把主角的生命值和持有的黄钥匙数量代入这句话
* @param text 使${}js表达式idid
* @returns
*/
replaceText(text: string, prefix?: string): string;
/**
* 如status:xxx等
* @example core.replaceValue('衬衫的价格是${status:hp}镑${item:yellowKey}便士。'); // 把这两个冒号表达式替换为core.getStatus('hp')和core.itemCount('yellowKey')这样的函数调用
* @param value
* @returns
*/
replaceValue(value: string): string;
/**
* 支持status:xxx等的计算
* @example core.calValue('status:hp + status:def'); // 计算主角的生命值加防御力
* @param value
* @param prefix
* @returns
*/
calValue(value: string, prefix?: string): any;
/**
* ba的开头a.unshift(b)b只能是单项的不足
* @example core.unshift(todo, {type: 'unfollow'}); // 在事件指令数组todo的开头插入“取消所有跟随者”指令
* @param a
* @param b
* @returns a本身得到的
*/
unshift(a: any[], b: any): any[];
/**
* ba的末尾a.push(b)b只能是单项的不足
* @example core.push(todo, {type: 'unfollow'}); // 在事件指令数组todo的末尾插入“取消所有跟随者”指令
* @param a
* @param b
* @returns a本身得到的
*/
push(a: any[], b: any): any[];
/**
* 适用于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(key: string, defaultValue?: any): any;
/**
* ()
* @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,
filter?: (name: string, value: any) => boolean,
recursion?: boolean
): T;
/** 深拷贝一个1D或2D的数组 */
cloneArray(
data?: Array<number> | Array<Array<number>>
): Array<number> | Array<Array<number>>;
/**
*
* @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?: string | HTMLImageElement,
width?: number,
height?: number
): HTMLImageElement[];
/**
* 10000w,e,z,j,g
* @example core.formatBigNumber(123456789, false); // "12346w"
* @param x
* @param onMap true表示用于地图显伤56
* @returns
*/
2022-11-19 11:30:14 +08:00
formatBigNumber(
x: number | string,
onMap?: boolean,
onCritical?: boolean
): string;
2022-11-13 18:02:05 +08:00
/** 变速移动 */
applyEasing(mode?: string): (number) => number;
/**
*
* @example core.arrayToRGB([102, 204, 255]); // "#66ccff",加载画面的宣传色
* @param color 255
* @returns 使
*/
arrayToRGB(color: [number, number, number]): string;
/**
*
* @example core.arrayToRGBA([102, 204, 255]); // "rgba(102,204,255,1)"
* @param color 255011
* @returns
*/
2022-11-19 11:30:14 +08:00
arrayToRGBA(color: [number, number, number, number?] | string): string;
2022-11-13 18:02:05 +08:00
/**
* base64压缩
* @example core.encodeRoute(core.status.route); // 一压当前录像
* @param route 0-9A-Za-z和下划线JSON.stringify预处理再base64压缩才能交由一压
* @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表示为其他值!(v == null || v != v)
*/
isset(v?: any): boolean;
/**
*
* @example core.subarray(['ad', '米库', '小精灵', '小破草', '小艾'], ['ad', '米库', '小精灵']); // ['小破草', '小艾']
* @param a b短将返回null
* @param b a长将返回null
* @returns b不是a的前缀将返回nulla去掉此前缀后的剩余数组
*/
subarray(a?: any[], b?: any[]): any[] | null;
/**
* array是不是一个数组element是否在该数组中
* @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;
/**
*
* @example core.setStatusBarInnerHTML('hp', core.status.hero.hp, 'color: #66CCFF'); // 更新状态栏中的主角生命,使用加载画面的宣传色
* @param name 'hp', 'atk', 'def'core.statusBar中的一个合法项
* @param value 6
* @param css css样式
*/
setStatusBarInnerHTML(name: string, value: any, css?: string): void;
/**
* Verdana不是等宽字体
* @example core.strlen('无敌ad'); // 6
* @param str
* @returns 2ASCII字符为1
*/
strlen(str: string): number;
/**
*
* @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;
/**
* base64加密
* @example core.encodeBase64('If you found this note in a small wooden box with a heart on it'); // "SWYgeW91IGZvdW5kIHRoaXMgbm90ZSBpbiBhIHNtYWxsIHdvb2RlbiBib3ggd2l0aCBhIGhlYXJ0IG9uIGl0"
* @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"
* @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;
/**
*
* @example core.download('route.txt', core.status.route); // 弹窗请求下载录像
* @param filename
* @param content
*/
download(filename: string, content: string | String[]): void;
/**
* core.drawConfirmBox()
* @example core.myconfirm('重启游戏?', core.restart); // 弹窗询问玩家是否重启游戏
* @param hint
* @param yesCallback
* @param noCallback
*/
myconfirm(
hint: string,
yesCallback: () => void,
noCallback?: () => void
): void;
/**
* ,
* @example core.same(['1', 2], ['1', 2]); // true
*/
same(a?: any, b?: any): boolean;
/**
* []
* @param success
* @param error
* @param readType DataUrl形式读取
*/
readFile(success, error, readType): void;
/**
* []
* @param content
*/
readFileContent(content): void;
/**
*
*/
copy(data: string): void;
/**
* HTTP请求 []
* @param type
* @param url
* @param formData POST请求则为表单数据
* @param success
* @param error
*/
http(
type: 'GET' | 'POST',
url: string,
formData: FormData,
success: () => void,
error: () => void
): void;
/** 获得浏览器唯一的guid */
getGuid(): string;
/** 解压缩一个数据 */
decompress(value: any): any;
/** 设置本地存储 */
setLocalStorage(key: string, value?: any): void;
/** 获得本地存储 */
getLocalStorage(key: string, defaultValue?: any): any;
/** 移除本地存储 */
removeLocalStorage(key: string): void;
/** 往数据库写入一段数据 */
setLocalForage(
key: string,
value?: any,
successCallback?: () => void,
errorCallback?: () => void
): void;
/** 从数据库读出一段数据 */
getLocalForage(
key: string,
defaultValue?: any,
successCallback?: (data: any) => void,
errorCallback?: () => void
): void;
/** 移除数据库的数据 */
removeLocalForage(
key: string,
successCallback?: () => void,
errorCallback?: () => void
): void;
/** 格式化日期为字符串 */
formatDate(date: Date): string;
/** 格式化日期为最简字符串 */
formatDate2(date: Date): string;
/** 格式化时间 */
formatTime(time: number): string;
/** 两位数显示 */
setTwoDigits(x: number): string;
/** 格式化文件大小 */
formatSize(size: number): string;
/** 访问浏览器cookie */
getCookie(name: string): string;
/**
*
* @param turn
* @param direction
*/
turnDirection(
turn: 'up' | 'down' | 'left' | 'right' | ':left' | ':right' | ':back',
direction?: string
): string;
/** 是否满足正则表达式 */
matchRegex(pattern: string, string: string): string;
/** 让用户输入一段文字 */
myprompt(
hint: string,
value: string,
callback?: (data?: string) => any
): void;
/** 动画显示某对象 */
showWithAnimate(obj?: any, speed?: number, callback?: () => any): void;
/** 动画使某对象消失 */
hideWithAnimate(obj?: any, speed?: number, callback?: () => any): void;
/** 解压一段内容 */
unzip(
blobOrUrl?: any,
success?: (data: any) => void,
error?: (error: string) => void,
convertToText?: boolean,
onprogress?: (loaded: number, total: number) => void
): void;
}
interface TextContentConfig {
left?: number;
top?: number;
maxWidth?: number;
color?: rgbarray | string;
align?: 'left' | 'center' | 'right';
fontSize: number;
lineHeight?: number;
time?: number;
font?: string;
letterSpacing?: number;
bold?: boolean;
italic?: boolean;
}
type direction = 'up' | 'down' | 'left' | 'right';
type move = 'forward' | direction;
type loc = { direction: direction; x: number; y: number };
type rgbarray = [number, number, number, number];
2022-11-16 23:01:23 +08:00
type BlockCls =
| 'terrain'
| 'animate'
| 'enemy'
| 'item'
| 'enemy48'
| 'npcs'
| 'npc48'
| 'autotile'
| 'tilesets';
2022-11-13 18:02:05 +08:00
type Events = MotaAction[] | string;
type Block = {
x: number;
y: number;
id: number;
event: {
cls: string;
id: string;
[key: string]: any;
};
};
type frameObj = {
angle: number;
index: number;
mirror: number;
opacity: number;
x: number;
y: number;
zoom: number;
};
type CtxRefer =
| string
| CanvasRenderingContext2D
| HTMLCanvasElement
| HTMLImageElement;
type Animate = {
frame: number;
frames: frameObj[][];
images: HTMLImageElement[];
ratio: number;
se: string;
};
type Floor = {
title: string;
ratio: number;
};
type ResolvedMap = {
floorId: string;
afterBattle: { [x: string]: Events };
afterOpenDoor: { [x: string]: Events };
afterGetItem: { [x: string]: Events };
autoEvent: Event;
beforeBattle: { [x: string]: Events };
canFlyFrom: boolean;
canFltTo: boolean;
canUseQuickShop: boolean;
cannotMove: Object;
cannotMoveIn: Object;
cannotViewMap: boolean;
changeFloor: {
[x: string]: {
floorId: ':before' | ':after' | ':now' | string;
loc?: [number, number];
stair?:
| 'upFloor'
| 'downFloor'
| ':symmetry'
| ':symmetry_x'
| ':symmetry_y'
| 'flyPoint';
direction?:
| 'left'
| 'right'
| 'up'
| 'down'
| ':left'
| ':right'
| ':back'
| ':hero'
| ':backhero';
time?: number;
ignoreChangeFloor?: boolean;
};
};
defaultGround: string;
bgm: string | Array<string>;
bgmap: number[][];
/** 事件层 */
map: number[][];
fgmap: number[][];
width: number;
height: number;
images: Array<{
canvas: 'bg' | 'auto' | 'fg';
name: string;
x: number;
y: number;
reverse?: ':x' | ':y' | ':o';
disable?: boolean;
sx?: number;
sy?: number;
w?: number;
h?: number;
frame?: number;
}>;
name: string;
ratio: number;
title: string;
weather: [string, number];
blocks: Array<Block>;
};
type Enemy = {
id: string;
name: string;
displayIdInBook: string;
2022-11-16 23:01:23 +08:00
special: number[];
2022-11-13 18:02:05 +08:00
hp: number;
atk: number;
def: number;
money: number;
exp: number;
point: number;
[key: string]: any;
};
2022-11-16 23:01:23 +08:00
type DetailedEnemy = {
name: string;
specialText: string[];
specialColor: (string | rgbarray)[];
damage: number;
critical: number;
criticalDamage: number;
defDamage: number;
toShowSpecial?: string[];
toShowColor?: any[];
damageColor?: string;
};
2022-11-13 18:02:05 +08:00
type Item = {
cls: string;
[key: string]: any;
};
type Save = {};
type MotaAction =
| {
type: string;
[key: string]: any;
}
| string;
type SystemFlags = {
enableXxx: boolean;
flyNearStair: boolean;
steelDoorWithoutKey: boolean;
betweenAttackMax: boolean;
ignoreChangeFloor: boolean;
disableShopOnDamage: boolean;
blurFg: boolean;
};
type event = { type: string; [key: string]: any };
type step = 'up' | 'down' | 'left' | 'right' | 'forward' | 'backward';