Skip to content

Commit

Permalink
Move event handler functions to types [ci minor]
Browse files Browse the repository at this point in the history
  • Loading branch information
ChromeQ committed Oct 7, 2023
1 parent 19b97fe commit b6ff96d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type { GameEngine } from '../GameEngine';
import type { GameEngine } from '../GameEngine';
export type { GameEngine };

export type Player = Record<string, unknown> & { id: string | number };

Expand All @@ -22,3 +23,11 @@ export interface Event<T = unknown> {
export type HistoryItem = {
timestamp: Date;
} & ({ event: Event } | { achievement: Achievement });

export type AchievementAchievedListener = (
player: Player,
achievement: Achievement,
engine: GameEngine
) => void;

export type EventOccurredListener = (player: Player, event: Event, engine: GameEngine) => void;
16 changes: 9 additions & 7 deletions src/GameEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
* The GameEngine is an `EventEmitter`, emitting events when an
* event has occured or an achievement has been achieved.
*/
import type { Achievement, Event, GamePlayer, HistoryItem, Player } from './@types';
import type {
Achievement,
AchievementAchievedListener,
Event,
EventOccurredListener,
GamePlayer,
HistoryItem,
Player,
} from './@types';
import { AchievementRule } from './AchievementRule';
import { DataStore } from './DataStore';
import { MemoryDataStore } from './MemoryDataStore';
Expand All @@ -34,12 +42,6 @@ interface GameEngineProps {

type GAME_ENGINE_ACHIEVEMENT_ACHIEVED = 'achievement-achieved';
type GAME_ENGINE_EVENT_OCCURRED = 'event-occurred';
type AchievementAchievedListener = (
player: Player,
achievement: Achievement,
engine: GameEngine
) => void;
type EventOccurredListener = (player: Player, event: Event, engine: GameEngine) => void;

export class GameEngine extends EventEmitter {
/**
Expand Down

0 comments on commit b6ff96d

Please sign in to comment.