author suo
  module FishingJoy { export class EventManager { private static _instance : EventManager = null ; private _eventDic : SimpleMap < Handler [ ] > = new SimpleMap < Handler [ ] > ( ) ; private _cacheEventDic : SimpleMap < any > = new SimpleMap < any > ( ) ; public constructor ( ) { } /**
         * 获得单例
         */ public static get instance ( ) : EventManager { if ( this . _instance == null ) { this . _instance = new EventManager ( ) ; } return this . _instance ; } param id事件 param func回调函数 param regType注册回调类型 param withClearCacheEvent是否清理缓存事件 public static registerEvent ( id , func , regType = REG_TYPE . COMMON , withClearCacheEvent = false ) { if ( regType == REG_TYPE . COMMON ) { if ( EventManager . instance . _cacheEventDic . isExist ( id ) ) { var data = EventManager . instance . _cacheEventDic . get ( id ) ; func . runWith ( data ) ; if ( withClearCacheEvent ) { EventManager . removeCacheEvent ( id ) ; } } let funcs = EventManager . instance . _eventDic . get ( id ) ; if ( funcs != null ) { } else { funcs = new Array < Handler > ( ) ; } funcs . push ( func ) ; EventManager . instance . _eventDic . set ( id , funcs ) ; } else if ( regType == REG_TYPE . ONCE ) { if ( EventManager . instance . _cacheEventDic . isExist ( id ) ) { var data = EventManager . instance . _cacheEventDic . get ( id ) ; func . once = true ; func . runWith ( data ) ; if ( withClearCacheEvent ) { EventManager . removeCacheEvent ( id ) ; } } else { let funcs = EventManager . instance . _eventDic . get ( id ) ; if ( funcs != null ) { } else { funcs = new Array < Handler > ( ) ; } func . once = true ; funcs . push ( func ) ; EventManager . instance . _eventDic . set ( id , funcs ) ; } } } param id事件 param func回调函数 public static unregisterEvent ( id , caller , func ) { let funcs = EventManager . instance . _eventDic . get ( id ) ; if ( funcs != null && funcs . length != 0 ) { for ( var i = 0 ; i < funcs . length ; i ++ ) { if ( funcs [ i ] . caller == caller && funcs [ i ] . method == func ) { funcs [ i ] . recover ( ) ; funcs . remove ( funcs [ i ] ) ; break ; } } } } /**
         * 移除缓存事件
         */ public static removeCacheEvent ( id ) { EventManager . instance . _cacheEventDic . remove ( id ) ; } param id事件 public static fireEvent ( id , data = null , fireType = FIRE_TYPE . COMMON ) { let funcs = EventManager . instance . _eventDic . get ( id ) ; if ( funcs != null && funcs . length != 0 ) { let temp = funcs . slice ( ) ; let len = temp . length ; for ( var i = 0 ; i < len ; i ++ ) { var func = temp [ i ] ; if ( func . once ) { EventManager . instance . _cacheEventDic . remove ( id ) ; } func . runWith ( data ) ; } } else { if ( fireType == FIRE_TYPE . FIRE_OR_CACHE ) { EventManager . instance . _cacheEventDic . set ( id , data ) ; } } if ( fireType == FIRE_TYPE . FIRE_AND_CHCHE ) { EventManager . instance . _cacheEventDic . set ( id , data ) ; } } /**
         * 释放
         */ public dispose ( ) { EventManager . instance . _eventDic . clear ( ) ; EventManager . instance . _cacheEventDic . clear ( ) ; EventManager . _instance = null ; } } } /**
 * 注册侦听类型
 */ const enum REG_TYPE { COMMON , ONCE } /**
 * 派发事件类型
 */ const enum FIRE_TYPE { COMMON , FIRE_OR_CACHE , FIRE_AND_CHCHE } /**
 * 事件枚举
 */ const enum EVENT_ID { ROOM_LEVEL_UPDATE , REMOVW_HOST_ALL_BULLETS , HIT_FISH , ADD_BATTERY_IN_MAP , REMOVE_BATTERY_IN_MAP , /**主角坐下*/ MASTER_SIT_DOWN , CHANEG_SHOOT_TYPE , AIM_FISH , CHANGE_SEAT , BATTERY_UPDATE , PLAY_USE_PORP_EFF , MER_EFF_COMPLETE , DRA_EFF_COMPLETE , WAIT_AIM , AIM_SPECIAL_FISH , FIRE_BULLET , EBB_TIDE , ROBOT_AIM_FISH , FREEZE_EFF_SHOW , FREEZE_EFF_RECOVER , FREEZE_FISH_OPERA , FISH_DIE_ACTION }