


export const EVENT_TYPES = {
  NOT_UPDATE_MISTAKE: "NOT_UPDATE_MISTAKE",//更新分数
  NOT_UPDATE_PAUSE: "NOT_UPDATE_PAUSE",//更新暂停状态

  NOT_SET_TROPHY_BUTTON: "NOT_SET_TROPHY_BUTTON",
}


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=null): 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)
            }
        }
    }
}