dbmaster-cli
Version:
Tool for converting tables between Fifa Soccer Games
89 lines (88 loc) • 4.24 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fifaConfigFactory = void 0;
const fs_1 = require("fs");
const Joi = __importStar(require("joi"));
const js_yaml_1 = require("js-yaml");
const path_1 = require("path");
const process_1 = require("process");
const interfaces_1 = require("../interfaces");
const fifa_config_1 = require("./fifa-config");
const schema = Joi.array()
.unique((a, b) => a.order === b.order)
.items({
name: Joi.string().required(),
order: Joi.number().min(0).integer().required(),
type: Joi.string()
.valid(...Object.values(interfaces_1.Datatype))
.required(),
default: Joi.any().required(),
unique: Joi.boolean().optional(),
range: Joi.object({
min: Joi.number().integer().required(),
max: Joi.number().integer().min(Joi.ref('min')).required()
}).when('type', { is: 'int', then: Joi.required(), otherwise: Joi.optional() })
});
const readConfig = (fifa, table) => {
let json;
try {
const yaml = fs_1.readFileSync(path_1.join(process_1.cwd(), 'cfg', 'tables', fifa, `${table}.yml`)).toString();
json = js_yaml_1.safeLoad(yaml);
}
catch (e) {
throw new Error(e);
}
const { error, value } = schema.validate(json);
if (error) {
throw new Error(JSON.stringify(error, null, 2));
}
return value || [];
};
exports.fifaConfigFactory = (fifa) => {
const config = new fifa_config_1.FifaConfig();
config.competition = readConfig(fifa, interfaces_1.Table.Competition);
config.dcplayernames = readConfig(fifa, interfaces_1.Table.DcPlayerNames);
config.formations = readConfig(fifa, interfaces_1.Table.Formations);
config.leaguerefereelinks = readConfig(fifa, interfaces_1.Table.LeagueRefereeLinks);
config.leagues = readConfig(fifa, interfaces_1.Table.Leagues);
config.leagueteamlinks = readConfig(fifa, interfaces_1.Table.LeagueTeamLinks);
config.manager = readConfig(fifa, interfaces_1.Table.Manager);
config.nations = readConfig(fifa, interfaces_1.Table.Nations);
config.player_grudgelove = readConfig(fifa, interfaces_1.Table.PlayerGrudgelove);
config.playerboots = readConfig(fifa, interfaces_1.Table.PlayerBoots);
config.playerloans = readConfig(fifa, interfaces_1.Table.PlayerLoans);
config.playernames = readConfig(fifa, interfaces_1.Table.PlayerNames);
config.players = readConfig(fifa, interfaces_1.Table.Players);
config.previousteam = readConfig(fifa, interfaces_1.Table.PreviousTeam);
config.referee = readConfig(fifa, interfaces_1.Table.Referee);
config.rivals = readConfig(fifa, interfaces_1.Table.Rivals);
config.rowteamnationlinks = readConfig(fifa, interfaces_1.Table.RowTeamNationLinks);
config.shoecolors = readConfig(fifa, interfaces_1.Table.ShoeColors);
config.stadiums = readConfig(fifa, interfaces_1.Table.Stadiums);
config.teamballs = readConfig(fifa, interfaces_1.Table.TeamBalls);
config.teamkits = readConfig(fifa, interfaces_1.Table.TeamKits);
config.teamnationlinks = readConfig(fifa, interfaces_1.Table.TeamNationLinks);
config.teamplayerlinks = readConfig(fifa, interfaces_1.Table.TeamPlayerLinks);
config.teams = readConfig(fifa, interfaces_1.Table.Teams);
config.teamstadiumlinks = readConfig(fifa, interfaces_1.Table.TeamStadiumLinks);
return config;
};