mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 20:59:37 +08:00
fix: hotkey scope
This commit is contained in:
parent
ed80fba4c9
commit
80e20b1cdc
@ -1,6 +1,6 @@
|
||||
import { KeyCode } from '@/plugin/keyCodes';
|
||||
import { getLocFromMouseLoc } from '@/plugin/ui/fixed';
|
||||
import { deleteWith, generateBinary, has, tip } from '@/plugin/utils';
|
||||
import { deleteWith, generateBinary, has, spliceBy, tip } from '@/plugin/utils';
|
||||
import { EmitableEvent, EventEmitter } from '../../common/eventEmitter';
|
||||
import { GameStorage } from '../storage';
|
||||
|
||||
@ -81,6 +81,7 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
|
||||
* @param symbol 当前作用域的symbol
|
||||
*/
|
||||
use(symbol: symbol) {
|
||||
spliceBy(this.scopeStack, symbol);
|
||||
this.scopeStack.push(symbol);
|
||||
this.scope = symbol;
|
||||
for (const key of Object.values(this.data)) {
|
||||
@ -89,13 +90,14 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放一个作用域,释放后不能调用{@link realize}函数,除非重新调用{@link use}函数
|
||||
* 释放一个作用域,释放后作用域将退回至删除的作用域的上一级
|
||||
* @param symbol 要释放的作用域的symbol
|
||||
*/
|
||||
dispose(symbol: symbol) {
|
||||
for (const key of Object.values(this.data)) {
|
||||
key.func.delete(symbol);
|
||||
}
|
||||
spliceBy(this.scopeStack, symbol);
|
||||
this.scope = this.scopeStack.pop() ?? Symbol();
|
||||
}
|
||||
|
||||
|
@ -271,6 +271,13 @@ export function deleteWith<T>(arr: T[], ele: T): T[] {
|
||||
return arr;
|
||||
}
|
||||
|
||||
export function spliceBy<T>(arr: T[], from: T): T[] {
|
||||
const index = arr.indexOf(from);
|
||||
if (index === -1) return arr;
|
||||
arr.splice(index);
|
||||
return arr;
|
||||
}
|
||||
|
||||
export async function triggerFullscreen(full: boolean) {
|
||||
const { maxGameScale } = core.plugin.utils;
|
||||
if (!!document.fullscreenElement && !full) {
|
||||
|
Loading…
Reference in New Issue
Block a user