()
| 5255 | } |
| 5256 | } |
| 5257 | defineNetplayFunctions() { |
| 5258 | function guidGenerator() { |
| 5259 | const S4 = function() { |
| 5260 | return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); |
| 5261 | }; |
| 5262 | return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); |
| 5263 | } |
| 5264 | this.netplay.url = this.config.netplayUrl; |
| 5265 | while (this.netplay.url.endsWith("/")) { |
| 5266 | this.netplay.url = this.netplay.url.substring(0, this.netplay.url.length - 1); |
| 5267 | } |
| 5268 | this.netplay.current_frame = 0; |
| 5269 | this.netplay.getOpenRooms = async () => { |
| 5270 | return JSON.parse(await (await fetch(this.netplay.url + "/list?domain=" + window.location.host + "&game_id=" + this.config.gameId)).text()); |
| 5271 | } |
| 5272 | this.netplay.updateTableList = async () => { |
| 5273 | const addToTable = (id, name, current, max) => { |
| 5274 | const row = this.createElement("tr"); |
| 5275 | row.classList.add("ejs_netplay_table_row"); |
| 5276 | const addToHeader = (text) => { |
| 5277 | const item = this.createElement("td"); |
| 5278 | item.innerText = text; |
| 5279 | item.style.padding = "10px 0"; |
| 5280 | item.style["text-align"] = "center"; |
| 5281 | row.appendChild(item); |
| 5282 | return item; |
| 5283 | } |
| 5284 | addToHeader(name).style["text-align"] = "left"; |
| 5285 | addToHeader(current + "/" + max).style.width = "80px"; |
| 5286 | |
| 5287 | const parent = addToHeader(""); |
| 5288 | parent.style.width = "80px"; |
| 5289 | this.netplay.table.appendChild(row); |
| 5290 | if (current < max) { |
| 5291 | const join = this.createElement("button"); |
| 5292 | join.classList.add("ejs_netplay_join_button"); |
| 5293 | join.classList.add("ejs_button_button"); |
| 5294 | join.style["background-color"] = "rgba(var(--ejs-primary-color),1)"; |
| 5295 | join.innerText = this.localization("Join"); |
| 5296 | parent.appendChild(join); |
| 5297 | this.addEventListener(join, "click", (e) => { |
| 5298 | this.netplay.joinRoom(id, name); |
| 5299 | }) |
| 5300 | return join; |
| 5301 | } |
| 5302 | } |
| 5303 | const open = await this.netplay.getOpenRooms(); |
| 5304 | //console.log(open); |
| 5305 | this.netplay.table.innerHTML = ""; |
| 5306 | for (const k in open) { |
| 5307 | addToTable(k, open[k].room_name, open[k].current, open[k].max);//todo: password |
| 5308 | } |
| 5309 | } |
| 5310 | this.netplay.showOpenRoomDialog = () => { |
| 5311 | const popups = this.createSubPopup(); |
| 5312 | this.netplayMenu.appendChild(popups[0]); |
| 5313 | popups[1].classList.add("ejs_cheat_parent"); //Hehe |
| 5314 | const popup = popups[1]; |
no test coverage detected