mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 15:17:36 +00:00
Convert tabs to spaces
This commit is contained in:
parent
0dd25bfcda
commit
3674d384d0
39 changed files with 2414 additions and 2414 deletions
|
|
@ -1,94 +1,94 @@
|
|||
const Path = require('path'),
|
||||
fs = require('fs');
|
||||
fs = require('fs');
|
||||
|
||||
const protocolDir = Path.normalize(__dirname+'/../protocols');
|
||||
const gamesFile = Path.normalize(__dirname+'/../games.txt');
|
||||
|
||||
function parseList(str) {
|
||||
if(!str) return {};
|
||||
if(!str) return {};
|
||||
const out = {};
|
||||
for (const one of str.split(',')) {
|
||||
for (const one of str.split(',')) {
|
||||
const equals = one.indexOf('=');
|
||||
const key = equals === -1 ? one : one.substr(0,equals);
|
||||
let value = equals === -1 ? '' : one.substr(equals+1);
|
||||
let value = equals === -1 ? '' : one.substr(equals+1);
|
||||
|
||||
if(value === 'true' || value === '') value = true;
|
||||
else if(value === 'false') value = false;
|
||||
else if(!isNaN(value)) value = parseInt(value);
|
||||
if(value === 'true' || value === '') value = true;
|
||||
else if(value === 'false') value = false;
|
||||
else if(!isNaN(value)) value = parseInt(value);
|
||||
|
||||
out[key] = value;
|
||||
}
|
||||
return out;
|
||||
out[key] = value;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function readGames() {
|
||||
const lines = fs.readFileSync(gamesFile,'utf8').split('\n');
|
||||
const games = {};
|
||||
|
||||
for (let line of lines) {
|
||||
// strip comments
|
||||
const comment = line.indexOf('#');
|
||||
if(comment !== -1) line = line.substr(0,comment);
|
||||
line = line.trim();
|
||||
if(!line) continue;
|
||||
for (let line of lines) {
|
||||
// strip comments
|
||||
const comment = line.indexOf('#');
|
||||
if(comment !== -1) line = line.substr(0,comment);
|
||||
line = line.trim();
|
||||
if(!line) continue;
|
||||
|
||||
const split = line.split('|');
|
||||
const split = line.split('|');
|
||||
|
||||
games[split[0].trim()] = {
|
||||
pretty: split[1].trim(),
|
||||
protocol: split[2].trim(),
|
||||
options: parseList(split[3]),
|
||||
params: parseList(split[4])
|
||||
};
|
||||
}
|
||||
return games;
|
||||
games[split[0].trim()] = {
|
||||
pretty: split[1].trim(),
|
||||
protocol: split[2].trim(),
|
||||
options: parseList(split[3]),
|
||||
params: parseList(split[4])
|
||||
};
|
||||
}
|
||||
return games;
|
||||
}
|
||||
const games = readGames();
|
||||
|
||||
function createProtocolInstance(type) {
|
||||
type = Path.basename(type);
|
||||
type = Path.basename(type);
|
||||
|
||||
const path = protocolDir+'/'+type;
|
||||
if(!fs.existsSync(path+'.js')) throw Error('Protocol definition file missing: '+type);
|
||||
const path = protocolDir+'/'+type;
|
||||
if(!fs.existsSync(path+'.js')) throw Error('Protocol definition file missing: '+type);
|
||||
const protocol = require(path);
|
||||
|
||||
return new protocol();
|
||||
return new protocol();
|
||||
}
|
||||
|
||||
class TypeResolver {
|
||||
static lookup(type) {
|
||||
if(!type) throw Error('No game specified');
|
||||
static lookup(type) {
|
||||
if(!type) throw Error('No game specified');
|
||||
|
||||
if(type.substr(0,9) === 'protocol-') {
|
||||
return createProtocolInstance(type.substr(9));
|
||||
}
|
||||
if(type.substr(0,9) === 'protocol-') {
|
||||
return createProtocolInstance(type.substr(9));
|
||||
}
|
||||
|
||||
const game = games[type];
|
||||
if(!game) throw Error('Invalid game: '+type);
|
||||
if(!game) throw Error('Invalid game: '+type);
|
||||
|
||||
const query = createProtocolInstance(game.protocol);
|
||||
query.pretty = game.pretty;
|
||||
for(const key of Object.keys(game.options)) {
|
||||
query.pretty = game.pretty;
|
||||
for(const key of Object.keys(game.options)) {
|
||||
query.options[key] = game.options[key];
|
||||
}
|
||||
for(const key of Object.keys(game.params)) {
|
||||
for(const key of Object.keys(game.params)) {
|
||||
query[key] = game.params[key];
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
static printReadme() {
|
||||
let out = '';
|
||||
for(const key of Object.keys(games)) {
|
||||
const game = games[key];
|
||||
out += "* "+game.pretty+" ("+key+")";
|
||||
if(game.options.port_query_offset || game.options.port_query)
|
||||
out += " [[Separate Query Port](#separate-query-port)]";
|
||||
if(game.params.doc_notes)
|
||||
out += " [[Additional Notes](#"+game.params.doc_notes+")]";
|
||||
out += "\n";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
static printReadme() {
|
||||
let out = '';
|
||||
for(const key of Object.keys(games)) {
|
||||
const game = games[key];
|
||||
out += "* "+game.pretty+" ("+key+")";
|
||||
if(game.options.port_query_offset || game.options.port_query)
|
||||
out += " [[Separate Query Port](#separate-query-port)]";
|
||||
if(game.params.doc_notes)
|
||||
out += " [[Additional Notes](#"+game.params.doc_notes+")]";
|
||||
out += "\n";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TypeResolver;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue