添加广播逻辑

This commit is contained in:
2025-05-19 20:58:15 +08:00
parent ce53eda29c
commit b6c1e58f35
5 changed files with 342 additions and 83 deletions

View File

@@ -0,0 +1,50 @@
export const EVENT_TYPES = {
NOT_UPDATE_MISTAKE: "NOT_UPDATE_MISTAKE",//更新分数
}
export class EventManager {
private static instance: EventManager
public static getInstance(): EventManager {
if (!EventManager.instance) {
EventManager.instance = new EventManager()
}
return EventManager.instance
}
private listeners: Map<string, Array<any>> = new Map()
public RegisterEvent(eventID: string, func: any): void {
if (this.listeners.has(eventID) == false) {
this.listeners.set(eventID, new Array())
}
var list: Array<any> = this.listeners.get(eventID)
var find = list.indexOf(func)
if (find < 0) {
list.push(func)
}
}
public UnregisterEvent(eventID: string, func: any): void {
if (this.listeners.has(eventID)) {
var list: Array<any> = this.listeners.get(eventID)
var find = list.indexOf(func)
if (find >= 0) {
list.splice(find, 1)
}
}
}
public DispatchEvent(eventID: string, arg: any): void {
if (this.listeners.has(eventID)) {
var list: Array<any> = this.listeners.get(eventID)
for (var i=0; i<list.length; i++) {
list[i](arg)
}
}
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "1784429c-7fbe-47bc-8281-9a34510da81b"
}