Closed SebastienGllmt closed 2 months ago
The new code for the events package is as follows
events
import type { EventQueue } from '@paima/events'; import { registerEvents } from '@paima/events'; import { genEvent } from '@paima/events'; import { Type } from '@sinclair/typebox'; export const ClickEvent = genEvent({ name: 'MyClickEvent', fields: [ { indexed: true, name: 'user', type: Type.String(), }, { name: 'time', type: Type.Number(), }, ], }); export const eventDefinitions = { ClickEvent, } as const; export const events = registerEvents(eventDefinitions); export type Events = EventQueue<typeof eventDefinitions>;
You can then use it inside a subscribe call like this
import { events } from '@game/events'; await PaimaEventManager.Instance.subscribe( { topic: events.ClickEvent, filter: { user: undefined }, // all users }, event => { console.log(`EVENT: ${event.time}`); callback(`Click time: ${event.time}`); } );
The new code for the
events
package is as followsYou can then use it inside a subscribe call like this