import { ColorID } from "@skeldjs/constant" ; import { EventEmitter } from "events" ; import util from "util" ; import chalk from "chalk" ; import logger from "../util/logger" ; import { BackendModel , BackendType } from "../types/models/Backends" ; import { GameSettings } from "../types/models/ClientOptions" ; import { BackendEvent } from "../types/enums/BackendEvents" ; import { PlayerFlag } from "../types/enums/PlayerFlags" ; import { GameState } from "../types/enums/GameState" ; import { GameFlag } from "../types/enums/GameFlags" ; import { Vector2 } from "@skeldjs/util" ; export type LogMode = "log" | "info" | "success" | "fatal" | "warn" | "error" ; export abstract class BackendAdapter extends EventEmitter { abstract backendModel : BackendModel ; destroyed : boolean ; gameID : string ; protected constructor ( ) { super ( ) ; } abstract initialize ( ) ; abstract destroy ( ) ; log ( mode , format , ... params ) { const formatted = util . format ( format , ... params ) ; logger [ mode ] ( chalk . grey ( "[" + BackendType [ this . backendModel . backendType ] + " " + this . gameID + "]" ) , formatted ) ; } emitPlayerPosition ( name , position ) { this . emit ( BackendEvent . PlayerPosition , { name , position } ) ; } emitPlayerColor ( name , color ) { this . emit ( BackendEvent . PlayerColor , { name , color } ) ; } emitHostChange ( name ) { this . emit ( BackendEvent . HostChange , { name } ) ; } emitGameState ( state ) { this . emit ( BackendEvent . GameState , { state } ) ; } emitSettingsUpdate ( settings ) { this . emit ( BackendEvent . SettingsUpdate , { settings } ) ; } emitPlayerFlags ( name , flags , set ) { this . emit ( BackendEvent . PlayerFlags , { name , flags , set } ) ; } emitGameFlags ( flags , set ) { this . emit ( BackendEvent . GameFlags , { flags , set } ) ; } emitError ( err , fatal ) { this . emit ( BackendEvent . Error , { err , fatal } ) ; } }