node-gamedig/lib/game-resolver.js

34 lines
649 B
JavaScript
Raw Normal View History

import { games } from './games.js'
export const lookup = (options) => {
const type = options.type
if (!type) { throw Error('No game specified') }
if (type.startsWith('protocol-')) {
return {
protocol: type.substring(9)
}
}
2024-01-18 12:00:08 +01:00
let game = games[type]
2024-02-14 15:31:58 +01:00
if (options.checkAlias) {
Object.keys(games).forEach((id) => {
if (games[id]?.extra?.alias) game = games[id]
})
}
if (options.checkOldIDs) {
Object.keys(games).forEach((id) => {
if (games[id]?.extra?.old_id === type) {
game = games[id]
}
})
}
if (!game) { throw Error('Invalid game: ' + type) }
return game.options
}