// Copyright Epic Games, Inc. All Rights Reserved. class BotSelector { /* id: unique html id for the component display: one of ['dropbox', 'checkboxes] */ constructor(id, display) { this.id = id; this.display = display; } botselectInit(selected, bots, handler) { const div = document.getElementById(this.id); if(div === undefined) return; if(this.display === 'dropbox') { const html = this.#initBotListDropBox(selected, bots); var parent = div.parentNode; parent.removeChild(div); parent.innerHTML = html; this.#initCheckboxHandlers(bots, handler); this.#initEscapeHandler(); document.addEventListener('click', this.#clickHandler.bind(this)); } if(this.display === 'checkboxes') { const html = this.#initBotListCheckBoxes(selected, bots); var parent = div.parentNode; parent.removeChild(div); parent.innerHTML = html; this.#initCheckboxHandlers(bots, handler); } } getBotsSelection() { let result = []; for( let item of document.getElementsByClassName("botselectitem")) { if (item.id.startsWith(`${this.id}_`) && item.checked) { result.push(item.value); } } return result; } clearBotsSelection() { for( let item of document.getElementsByClassName("botselectitem")) { if (item.id.startsWith(`${this.id}_`) && item.checked) { item.checked = false; } } } #initBotListCheckBoxes(selected, bots) { if (this.id === undefined) return; if (this.display === undefined) return; if (selected === undefined) return; if (bots === undefined) return; // maximum 3 cols const groupSize = Math.ceil(bots.length / 3); let groups = new Map(); for (let i = 0; i < bots.length / groupSize; i++) { groups.set(i, []); } for (let i = 0; i < bots.length; i++) { groups.get(Math.floor(i/groupSize)).push(i); } let checkboxes = ''; const sortedBots = bots.sort(); for(const group of groups.keys()) { checkboxes += '