Initial Cocos Creator port of main-site Unity WebGL game.
Includes core gameplay, 600 exported levels, visual assets, web bridge, and bootstrap scene. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
27
assets/scripts/core/EventManager.ts
Normal file
27
assets/scripts/core/EventManager.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export enum EventType {
|
||||
LevelInit = 'LevelInit',
|
||||
InputEnd = 'InputEnd',
|
||||
}
|
||||
|
||||
type Handler = (...args: unknown[]) => void;
|
||||
|
||||
const listeners = new Map<EventType, Handler[]>();
|
||||
|
||||
export const EventManager = {
|
||||
register(type: EventType, handler: Handler) {
|
||||
if (!listeners.has(type)) listeners.set(type, []);
|
||||
const list = listeners.get(type)!;
|
||||
if (!list.includes(handler)) list.push(handler);
|
||||
},
|
||||
remove(type: EventType, handler: Handler) {
|
||||
const list = listeners.get(type);
|
||||
if (!list) return;
|
||||
const i = list.indexOf(handler);
|
||||
if (i >= 0) list.splice(i, 1);
|
||||
},
|
||||
dispatch(type: EventType, ...args: unknown[]) {
|
||||
const list = listeners.get(type);
|
||||
if (!list) return;
|
||||
for (const h of [...list]) h(...args);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user