import { GamepadStyle } from "./GamepadStyle" ; const typemap = new Map ( ) ; typemap . set ( /^.*?[Xx][Ii][Nn][Pp][Uu][Tt].*$/ , GamepadStyle . XBOX ) ; typemap . set ( /^.*045e.*$/ , GamepadStyle . XBOX ) ; typemap . set ( /^.*?[Ss]tadia\ [Cc]ontroller.*$/ , GamepadStyle . STADIA ) ; typemap . set ( /^.*?[Pp][Ll][Aa][Yy][Ss][Tt][Aa][Ii][Oo][Nn].*$/ , GamepadStyle . XBOX ) ; typemap . set ( /^.*054c.*$/ , GamepadStyle . PLAYSTATION ) ; /**
 * Regular expression to extract vendor and product identifier.
 */ const productAndVendorMatcher = /^.*?[Vv]endor:?\s*(?<vendorId>.{4}).*?[Pp]roduct:?\s*(?<productId>.{4}).*?$/ ; export class GamepadModel { constructor ( public style , vendorId ? , productId ? ) { } param str public static fromString ( str ) { for ( const [ key , value ] of typemap ) { if ( key . exec ( str ) ) { const productAndVendorMatch = productAndVendorMatcher . exec ( str ) ; let vendorId ; let productId ; if ( productAndVendorMatch !== null ) { vendorId = productAndVendorMatch . groups ?. vendorId ; productId = productAndVendorMatch . groups ?. productId ; } return new GamepadModel ( value , parseInt ( vendorId || "-1" , 16 ) , parseInt ( productId || "-1" ) ) ; } } return DEFAULT_GAMEPAD_MODEL ; } } export const DEFAULT_GAMEPAD_MODEL = new GamepadModel ( GamepadStyle . UNKNOWN ) ;