feat: API文档

This commit is contained in:
AncTe committed 2024-03-01 19:52:30 +08:00
1 parent 85031d3c39
commit 121fbe369d
59 files changed
+5965 -59

No files matched your search

+2 -2
View File
@@ -80,8 +80,8 @@ export class BgmController
this.playing = true;
if (!this.disable) {
this.setTransitionAnimate(id, 1);
if (this.now) this.setTransitionAnimate(this.now, 0, when);
this.setTransitionAnimate(id, 1, when);
if (this.now) this.setTransitionAnimate(this.now, 0);
}
if (!noStack) {
+1 -7
View File
@@ -1,6 +1,5 @@
import { has } from '@/plugin/utils';
import { AudioParamOf, AudioPlayer } from './audio';
import resource from '@/data/resource.json';
import { ResourceController } from '../loader/controller';
// todo: 立体声,可设置音源位置
@@ -24,7 +23,6 @@ export class SoundEffect extends AudioPlayer {
gain: GainNode = AudioPlayer.ac.createGain();
panner: PannerNode | null = null;
merger: ChannelMergerNode | null = null;
set volumn(value: number) {
this.gain.gain.value = value * SoundEffect.volume;
@@ -63,9 +61,7 @@ export class SoundEffect extends AudioPlayer {
* 设置音频路由线路
* ```txt
* 不启用立体声:source -> gain -> destination
* 启用立体声:source -> panner -> gain --> destination
* 单声道立体声:source -> merger -> panner -> gain -> destination
* 单声道立体声指音源为单声道,合成为双声道后模拟为立体声
* 启用立体声:source -> panner -> gain -> destination
* ```
* @param stereo 是否启用立体声
*/
@@ -74,7 +70,6 @@ export class SoundEffect extends AudioPlayer {
const ac = AudioPlayer.ac;
if (!channel) return;
this.panner = null;
this.merger = null;
if (stereo) {
this.panner = ac.createPanner();
this.panner.connect(this.gain);
@@ -155,7 +150,6 @@ export class SoundController extends ResourceController<
* @param data 音频的ArrayBuffer信息,会被解析为AudioBuffer
*/
add(uri: string, data: ArrayBuffer) {
const stereo = resource.stereoSE.includes(uri);
const se = new SoundEffect(data, true);
if (this.list[uri]) {
console.warn(`Repeated sound effect: '${uri}'.`);
+2
View File
@@ -56,6 +56,7 @@ import EnemySpecial from '@/panel/enemySpecial.vue';
import EnemyTarget from '@/panel/enemyTarget.vue';
import KeyboardPanel from '@/panel/keyboard.vue';
import { MCGenerator } from './main/layout';
import { ResourceController } from './loader/controller';
// ----- 类注册
Mota.register('class', 'AudioPlayer', AudioPlayer);
@@ -72,6 +73,7 @@ Mota.register('class', 'SoundController', SoundController);
Mota.register('class', 'SoundEffect', SoundEffect);
Mota.register('class', 'UiController', UiController);
Mota.register('class', 'MComponent', MComponent);
Mota.register('class', 'ResourceController', ResourceController);
// ----- 函数注册
Mota.register('fn', 'm', m);
Mota.register('fn', 'unwrapBinary', unwarpBinary);
+1 -1
View File
@@ -25,6 +25,6 @@ export abstract class ResourceController<
remove(uri: string) {
const content = this.list[uri];
delete this.list[uri];
this.emit(uri, content);
this.emit('delete', uri, content);
}
}
+3 -1
View File
@@ -199,11 +199,13 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
setPos(x?: number, y?: number) {
has(x) && (this.x = x);
has(y) && (this.y = y);
this.emit('posChange', this);
}
setSize(width?: number, height?: number) {
has(width) && (this.width = width);
has(height) && (this.height = height);
this.emit('posChange', this);
}
/**
@@ -288,7 +290,7 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
static load() {
toolbarStorage.read();
for (const [key, value] of Object.entries(toolbarStorage.data)) {
const bar = new CustomToolbar(key);
const bar = this.get(key) ?? new CustomToolbar(key);
bar.x = value.x;
bar.y = value.y;
bar.width = value.w;
-2
View File
@@ -9,8 +9,6 @@ interface FocusEvent<T> extends EmitableEvent {
unfocus: (before: T | null) => void;
add: (item: T) => void;
pop: (item: T | null) => void;
register: (item: T[]) => void;
unregister: (item: T[]) => void;
splice: (spliced: T[]) => void;
}
+1 -1
View File
@@ -3,7 +3,7 @@ import { Keyboard } from '../custom/keyboard';
const qweKey = new Keyboard('qwe'); // 字母键盘,A-Z
const numKey = new Keyboard('num'); // 数字键盘,1-0
const charKey = new Keyboard('charKey'); // 符号键盘,!@<>等
const charKey = new Keyboard('char'); // 符号键盘,:;<>等
const fnKey = new Keyboard('fn'); // Fn键盘,F1-F12
const assistKey = new Keyboard('assist'); // 辅助键盘,tab,capslk,shift,ctrl等
const arrowKey = new Keyboard('arrow'); // 方向键
+1 -1
View File
@@ -133,7 +133,7 @@ export class MComponent {
*/
com(
component: Component | MComponent,
config: Omit<MotaComponentConfig, 'innerText' | 'component'>
config?: Omit<MotaComponentConfig, 'innerText' | 'component'>
) {
return this.h(component, [], config);
}
+4 -1
View File
@@ -205,7 +205,10 @@ export class MotaSetting extends EventEmitter<SettingEvent> {
*/
setDescription(key: string, desc: string) {
const setting = this.getSettingBy(key.split('.'));
setting.description = desc;
setting.description = desc.replace(
/\<\s*script.*\/?\>(.*\<\/\s*script\s*\>)?/g,
''
);
return this;
}
+2 -6
View File
@@ -38,8 +38,6 @@ interface EnemyInfo extends Partial<Enemy> {
interface DamageInfo {
damage: number;
/** 自动切换技能时使用的技能 */
skill?: number;
}
interface MapDamage {
@@ -105,7 +103,6 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
/**
* 计算怪物真实属性
* @param noCache 是否不使用缓存
*/
calRealAttribute() {
this.haloList = [];
@@ -125,6 +122,7 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
}
/**
* @deprecated
* 计算怪物伤害
* @param noCache 是否不使用缓存
*/
@@ -488,9 +486,8 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
}
/**
* 计算怪物临界,计算临界时,根据当前方向计算临界,但也会输出与当前最少伤害的伤害差值
* 计算怪物临界
* @param num 要计算多少个临界
* @param dir 从怪物位置指向勇士的方向
* @param hero 勇士属性,最终结果将会与由此属性计算出的伤害相减计算减伤
*/
calCritical(
@@ -591,7 +588,6 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
/**
* 计算n防减伤
* @param num 要加多少防御
* @param dir 从怪物位置指向勇士的方向
* @param hero 勇士属性,最终结果将会与由此属性计算出的伤害相减计算减伤
*/
calDefDamage(
+10 -8
View File
@@ -84,14 +84,16 @@ export interface GameEvent extends EmitableEvent {
mounted: () => void;
/** Emitted in plugin/ui.js */
statusBarUpdate: () => void;
/** Emitted in libs/events.js */
afterGetItem: (
itemId: AllIdsOf<'items'>,
x: number,
y: number,
isGentleClick: boolean
) => void;
afterOpenDoor: (doorId: AllIdsOf<'animates'>, x: number, y: number) => void;
/** Emitted in core/index.ts */
renderLoaded: () => void;
// /** Emitted in libs/events.js */
// afterGetItem: (
// itemId: AllIdsOf<'items'>,
// x: number,
// y: number,
// isGentleClick: boolean
// ) => void;
// afterOpenDoor: (doorId: AllIdsOf<'animates'>, x: number, y: number) => void;
}
export const hook = new EventEmitter<GameEvent>();
+9
View File
@@ -1,6 +1,7 @@
import type { AudioPlayer } from '@/core/audio/audio';
import type { BgmController } from '@/core/audio/bgm';
import type { SoundController, SoundEffect } from '@/core/audio/sound';
import type { ResourceController } from '@/core/loader/controller';
import type { Disposable } from '@/core/common/disposable';
import type {
EventEmitter,
@@ -47,6 +48,7 @@ import type * as toolboxTools from '@/plugin/ui/toolbox';
import type * as battle from './enemy/battle';
import type * as hero from './hero';
import type { Damage } from './enemy/damage';
import type * as utils from '@/plugin/utils';
// ---------- 插件
import type * as pop_r from '../plugin/pop';
import type * as use_r from '../plugin/use';
@@ -72,6 +74,7 @@ import type * as _lodash from 'lodash-es';
import type * as _lzString from 'lz-string';
import type * as _mutateAnimate from 'mutate-animate';
import type * as _vue from 'vue';
// ---------- UI
import type * as UI from '@ui/index';
import type Box from '@/components/box.vue';
import type BoxAnimate from '@/components/boxAnimate.vue.vue';
@@ -82,6 +85,7 @@ import type EnemyCritical from '@/panel/enemyCritical.vue';
import type EnemySpecial from '@/panel/enemySpecial.vue.vue';
import type EnemyTarget from '@/panel/enemyTarget.vue.vue';
import type KeyboardPanel from '@/panel/keyboard.vue.vue';
import type { VirtualKey } from '@/core/main/init/misc';
export interface ClassInterface {
// 渲染进程与游戏进程通用
@@ -103,6 +107,7 @@ export interface ClassInterface {
SoundController: typeof SoundController;
BgmController: typeof BgmController;
MComponent: typeof MComponent;
ResourceController: typeof ResourceController;
// 定义于游戏进程,渲染进程依然可用
Range: typeof Range;
EnemyCollection: typeof EnemyCollection;
@@ -172,6 +177,10 @@ export interface ModuleInterface {
KeyboardPanel: typeof KeyboardPanel;
};
MCGenerator: typeof MCGenerator;
RenderUtils: typeof utils;
MiscComponents: {
VirtualKey: typeof VirtualKey;
};
}
export interface SystemInterfaceMap {
+1 -1
View File
@@ -39,7 +39,7 @@ function checkMobile() {
/**
* 向一个元素添加拖拽事件
* @param ele 目标元素,当为全局拖拽时,传入数组表示所有元素共用一个全局拖拽函数
* @param fn 推拽时触发的函数,传入x y和鼠标事件或点击事件
* @param fn 拖拽时触发的函数,传入x y和鼠标事件或点击事件
* @param ondown 鼠标按下时执行的函数
* @param global 是否全局拖拽,即拖拽后鼠标或手指离开元素后是否依然视为正在拖拽
*/
+1 -19
View File
@@ -25,8 +25,7 @@ export default function init() {
getDamageColor,
parseCss,
tip,
changeLocalStorage,
swapChapter
changeLocalStorage
};
}
@@ -240,23 +239,6 @@ export function changeLocalStorage<T>(
core.setLocalStorage(name, to);
}
export async function swapChapter(chapter: number, hard: number) {
const h = hard === 2 ? 'hard' : 'easy';
const save = await axios.get(
`${import.meta.env.BASE_URL}swap/${chapter}.${h}.h5save`,
{
responseType: 'text',
responseEncoding: 'utf-8'
}
);
const data = JSON.parse(decompressFromBase64(save.data));
core.loadData(data.data, () => {
core.removeFlag('__fromLoad__');
core.drawTip('读档成功');
});
}
export function ensureArray<T>(arr: T): T extends any[] ? T : T[] {
// @ts-ignore
return arr instanceof Array ? arr : [arr];