fix: hotkey scope

This commit is contained in:
unanmed 2023-11-18 11:33:24 +08:00
parent ed80fba4c9
commit 80e20b1cdc
2 changed files with 11 additions and 2 deletions

View File

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

View File

@ -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) {