focus的取消注册

This commit is contained in:
unanmed 2023-08-16 11:33:46 +08:00
parent 50fd24fbe0
commit aff4b5a9d0

View File

@ -9,6 +9,7 @@ interface FocusEvent<T> extends EmitableEvent {
add: (item: T) => void;
pop: (item: T | null) => void;
register: (item: T[]) => void;
unregister: (item: T[]) => void;
splice: (spliced: T[]) => void;
}
@ -63,7 +64,10 @@ export class Focus<T = any> extends EventEmitter<FocusEvent<T>> {
*/
add(item: T) {
if (!this.targets.has(item)) {
console.warn(`向显示列表里面添加了不在物品集合里面的物品`);
console.warn(
`向显示列表里面添加了不在物品集合里面的物品`,
`添加的物品:${item}`
);
return;
}
this.stack.push(item);
@ -93,7 +97,7 @@ export class Focus<T = any> extends EventEmitter<FocusEvent<T>> {
}
/**
*
*
* @param item
*/
register(...item: T[]) {
@ -102,6 +106,17 @@ export class Focus<T = any> extends EventEmitter<FocusEvent<T>> {
});
this.emit('register', item);
}
/**
*
* @param item
*/
unregister(...item: T[]) {
item.forEach(v => {
this.targets.delete(v);
});
this.emit('unregister', item);
}
}
interface GameUiEvent extends EmitableEvent {
@ -114,11 +129,13 @@ export class GameUi extends EventEmitter<GameUiEvent> {
component: Component;
hotkey?: Hotkey;
id: string;
constructor(component: Component, hotkey?: Hotkey) {
constructor(id: string, component: Component, hotkey?: Hotkey) {
super();
this.component = component;
this.hotkey = hotkey;
this.id = id;
GameUi.uiList.push(this);
}
}