UNPKG

@ohd-tools/utils

Version:
125 lines (124 loc) 5.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Maps_1 = __importDefault(require("../definitions/Maps")); const Factions_1 = __importDefault(require("../definitions/Factions")); /** * Builder for OHD Map Strings */ class MapQuery { /**What map to set the server to */ Map; /**Exclusive to Modded Gamemodes */ Game; /**Blue Team Faction */ BluforFaction; /**Red Team Faction*/ OpforFaction; /**Minimum number of players to start a game. If bBotAutofill is enables, bots will spawn to this point */ MinPlayers; /**Max number of players */ MaxPlayers; /**Allow All players to choose all kits, without limitation */ bDisableKitRestrictions; /**Auto fill the server with bots up to MinPlayers */ bBotAutofill; /**How many bots should the Blue Team have */ BluforNumBots; /**How many bots should the Red Team have */ OpforNumBots; /**How many Reinforcements should the Blue Team have */ BluforNumTickets; /**How many Reinforcements should the Red Team have */ OpforNumTickets; /**What Team to force players to. */ AutoFillHuman; constructor($b = {}) { if (typeof $b === 'string') { $b = MapQuery.parse($b); } this.Map = $b.Map ?? Maps_1.default.Argonne; this.Game = $b.Game ?? null; this.BluforFaction = $b.BluforFaction ?? Factions_1.default.DEFAULT; this.OpforFaction = $b.OpforFaction ?? Factions_1.default.DEFAULT; this.MinPlayers = $b.MinPlayers ?? 1; this.MaxPlayers = $b.MaxPlayers ?? 64; this.bDisableKitRestrictions = $b.bDisableKitRestrictions ?? false; this.bBotAutofill = $b.bBotAutofill ?? false; this.AutoFillHuman = $b.AutoFillHuman ?? null; this.BluforNumBots = $b.BluforNumBots ?? 0; this.OpforNumBots = $b.OpforNumBots ?? 0; this.BluforNumTickets = $b.BluforNumTickets ?? 500; this.OpforNumTickets = $b.OpforNumTickets ?? 500; } static parse(query) { const parsed = {}; const map = /^(\w+)/gi.exec(query)?.[1]; const BluforFaction = /\?Bluforfaction=(\w+)/gi.exec(query)?.[1]; const OpforFaction = /\?Opforfaction=(\w+)/gi.exec(query)?.[1]; const Game = /\?game=(\/\w+\/[\w._]+)/gi.exec(query)?.[1]; const MinPlayers = /\?MinPlayers=(\d+)/gi.exec(query)?.[1]; const MaxPlayers = /\?MaxPlayers=(\d+)/gi.exec(query)?.[1]; const bDisableKitRestrictions = /\?(bDisableKitRestrictions)/gi.exec(query)?.[1]; const bBotAutofill = /\?(bBotAutofill)/gi.exec(query)?.[1]; const BluforNumBots = /\?BluforNumBots=(\d+)/gi.exec(query)?.[1]; const OpforNumBots = /\?OpforNumBots=(\d+)/gi.exec(query)?.[1]; const BluforNumTickets = /\?BluforNumTickets=(\d+)/gi.exec(query)?.[1]; const OpforNumTickets = /\?OpforNumTickets=(\d+)/gi.exec(query)?.[1]; const AutoFillHuman = /\?AutoFillHuman=([01])/gi.exec(query)?.[1]; parsed.Map = map; parsed.Game = Game; parsed.BluforFaction = BluforFaction; parsed.OpforFaction = OpforFaction; parsed.MinPlayers = MinPlayers != null ? parseInt(MinPlayers) : undefined; parsed.MaxPlayers = MaxPlayers != null ? parseInt(MaxPlayers) : undefined; parsed.bDisableKitRestrictions = bDisableKitRestrictions != null; parsed.bBotAutofill = bBotAutofill != null; parsed.BluforNumBots = BluforNumBots != null ? parseInt(BluforNumBots) : undefined; parsed.OpforNumBots = OpforNumBots != null ? parseInt(OpforNumBots) : undefined; parsed.BluforNumTickets = BluforNumTickets != null ? parseInt(BluforNumTickets) : undefined; parsed.OpforNumTickets = OpforNumTickets != null ? parseInt(OpforNumTickets) : undefined; parsed.AutoFillHuman = AutoFillHuman != null ? parseInt(AutoFillHuman) : undefined; return new MapQuery(parsed); } /** * Generate the Level String */ toString() { let map = ''; map += this.Map; if (this.Game != null) map += `?game=${this.Game}`; if (this.BluforFaction != null) map += `?BluforFaction=${this.BluforFaction}`; if (this.OpforFaction != null) map += `?OpforFaction=${this.OpforFaction}`; if (this.MinPlayers != null) map += `?MinPLayers=${this.MinPlayers}`; if (this.MaxPlayers != null) map += `?MaxPlayers=${this.MaxPlayers}`; if (this.bDisableKitRestrictions == true) map += `?bDisableKitRestrictions`; if (this.bBotAutofill == true) map += `?bBotAutofill`; if (this.BluforNumBots != null) map += `?BluforNumBots=${this.BluforNumBots}`; if (this.AutoFillHuman != null) map += `?AutoFillHuman=${this.AutoFillHuman}`; if (this.OpforNumBots != null) map += `?OpforNumBots=${this.OpforNumBots}`; if (this.BluforNumTickets != null) map += `?BluforNumTickets=${this.BluforNumTickets}`; if (this.OpforNumTickets != null) map += `?OpforNumTickets=${this.OpforNumTickets}`; return map; } } exports.default = MapQuery;