From 1296cecb0690bbe70c109693625cb424297a0b40 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Sat, 12 Mar 2022 22:06:52 -0500 Subject: Removing console logs adding function for different char icons --- webAO/client.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index 2c1a831..0c7c4b6 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -780,13 +780,28 @@ class Client extends EventEmitter { async handleCharacterInfo(chargs, charid) { if (chargs[0]) { let cini = {}; - const cswap = {}; - const icon = `${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char_icon.png`; + const getCharIcon = async () => { + const extensions = [ + '.png', + '.webp', + ]; + const charIconBaseUrl = `${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char_icon`; + for (let i = 0; i < extensions.length; i++) { + const fileUrl = charIconBaseUrl + extensions[i]; + const exists = await fileExists(fileUrl); + if (exists) { + return fileUrl + } + } + return transparentPNG + }; + const charIconUrlResponse = await getCharIcon(); + const icon = charIconUrlResponse || transparentPNG; const img = document.getElementById(`demo_${charid}`); img.alt = chargs[0]; img.src = icon; // seems like a good time to load the icon - + // If the ini doesn't exist on the server this will throw an error try { const cinidata = await request(`${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char.ini`); @@ -853,12 +868,13 @@ class Client extends EventEmitter { */ handleCI(args) { // Loop through the 10 characters that were sent + for (let i = 2; i <= args.length - 2; i++) { if (i % 2 === 0) { document.getElementById('client_loadingtext').innerHTML = `Loading Character ${args[1]}/${this.char_list_length}`; const chargs = args[i].split('&'); const charid = args[i - 1]; - setTimeout(() => this.handleCharacterInfo(chargs, charid), charid * 10); + setTimeout(() => this.handleCharacterInfo(chargs, charid), 500) } } // Request the next pack @@ -870,13 +886,14 @@ class Client extends EventEmitter { * in one packet. * @param {Array} args packet arguments */ - handleSC(args) { + async handleSC(args) { document.getElementById('client_loadingtext').innerHTML = 'Loading Characters'; for (let i = 1; i < args.length; i++) { document.getElementById('client_loadingtext').innerHTML = `Loading Character ${i}/${this.char_list_length}`; const chargs = args[i].split('&'); const charid = i - 1; - setTimeout(() => this.handleCharacterInfo(chargs, charid), charid * 10); + + this.handleCharacterInfo(chargs, charid) } // We're done with the characters, request the music this.sendServer('RM#%'); -- cgit From 39da04dc796b635b43879d285bc9d2c2aabc8761 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Sat, 12 Mar 2022 22:07:48 -0500 Subject: Lint --- webAO/client.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index 0c7c4b6..e07c7e9 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -21,7 +21,7 @@ import chatbox_arr from './styles/chatbox/chatboxes.js'; import iniParse from './iniParse'; import getCookie from './utils/getCookie.js'; import setCookie from './utils/setCookie.js'; -import {request} from './services/request.js'; +import { request } from './services/request.js'; import { changeShoutVolume, changeSFXVolume } from './dom/changeVolume.js'; import setEmote from './client/setEmote.js'; import fileExists from './utils/fileExists.js'; @@ -790,10 +790,10 @@ class Client extends EventEmitter { const fileUrl = charIconBaseUrl + extensions[i]; const exists = await fileExists(fileUrl); if (exists) { - return fileUrl + return fileUrl; } } - return transparentPNG + return transparentPNG; }; const charIconUrlResponse = await getCharIcon(); @@ -801,7 +801,7 @@ class Client extends EventEmitter { const img = document.getElementById(`demo_${charid}`); img.alt = chargs[0]; img.src = icon; // seems like a good time to load the icon - + // If the ini doesn't exist on the server this will throw an error try { const cinidata = await request(`${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char.ini`); @@ -874,7 +874,7 @@ class Client extends EventEmitter { document.getElementById('client_loadingtext').innerHTML = `Loading Character ${args[1]}/${this.char_list_length}`; const chargs = args[i].split('&'); const charid = args[i - 1]; - setTimeout(() => this.handleCharacterInfo(chargs, charid), 500) + setTimeout(() => this.handleCharacterInfo(chargs, charid), 500); } } // Request the next pack @@ -892,8 +892,8 @@ class Client extends EventEmitter { document.getElementById('client_loadingtext').innerHTML = `Loading Character ${i}/${this.char_list_length}`; const chargs = args[i].split('&'); const charid = i - 1; - - this.handleCharacterInfo(chargs, charid) + + this.handleCharacterInfo(chargs, charid); } // We're done with the characters, request the music this.sendServer('RM#%'); @@ -1542,7 +1542,7 @@ class Client extends EventEmitter { esfxd = 0; } // Make sure the asset server is case insensitive, or that everything on it is lowercase - + emotes[i] = { desc: emoteinfo[0].toLowerCase(), preanim: emoteinfo[1].toLowerCase(), @@ -1553,7 +1553,7 @@ class Client extends EventEmitter { frame_screenshake: '', frame_realization: '', frame_sfx: '', - button: `${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/emotions/button${i}_off.png`, + button: `${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/emotions/button${i}_off.png`, }; emotesList.innerHTML += ` Date: Sun, 13 Mar 2022 01:29:10 -0500 Subject: Resolve too many network calls --- webAO/client.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index e07c7e9..36e2555 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -778,29 +778,28 @@ class Client extends EventEmitter { * @param {Number} charid character ID */ async handleCharacterInfo(chargs, charid) { + if (chargs[0]) { let cini = {}; + const img = document.getElementById(`demo_${charid}`); const getCharIcon = async () => { const extensions = [ '.png', '.webp', ]; + img.alt = chargs[0] const charIconBaseUrl = `${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char_icon`; for (let i = 0; i < extensions.length; i++) { const fileUrl = charIconBaseUrl + extensions[i]; const exists = await fileExists(fileUrl); if (exists) { - return fileUrl; + img.alt = chargs[0]; + img.src = fileUrl; + return } } - return transparentPNG; }; - - const charIconUrlResponse = await getCharIcon(); - const icon = charIconUrlResponse || transparentPNG; - const img = document.getElementById(`demo_${charid}`); - img.alt = chargs[0]; - img.src = icon; // seems like a good time to load the icon + await getCharIcon(); // If the ini doesn't exist on the server this will throw an error try { @@ -844,7 +843,7 @@ class Client extends EventEmitter { side: safeTags(cini.options.side).toLowerCase(), chat: (cini.options.chat === '') ? safeTags(cini.options.chat).toLowerCase() : safeTags(cini.options.category).toLowerCase(), evidence: chargs[3], - icon, + icon: img.src, inifile: cini, muted: false, }; @@ -887,12 +886,18 @@ class Client extends EventEmitter { * @param {Array} args packet arguments */ async handleSC(args) { + const sleep = ms => new Promise(r => setTimeout(r, ms)); + + // Add this so people can see characters loading on the screen. + document.getElementById('client_loading').style.display = 'none'; + document.getElementById('client_charselect').style.display = 'block'; + document.getElementById('client_loadingtext').innerHTML = 'Loading Characters'; for (let i = 1; i < args.length; i++) { document.getElementById('client_loadingtext').innerHTML = `Loading Character ${i}/${this.char_list_length}`; const chargs = args[i].split('&'); const charid = i - 1; - + await sleep(.1) // TODO: Too many network calls without this. net::ERR_INSUFFICIENT_RESOURCES this.handleCharacterInfo(chargs, charid); } // We're done with the characters, request the music -- cgit From d9a78c0f6ec11ced9748eaca2f62336a2201fbbc Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Sun, 13 Mar 2022 01:29:40 -0500 Subject: LINT!! --- webAO/client.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index 36e2555..6cdcc50 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -778,7 +778,6 @@ class Client extends EventEmitter { * @param {Number} charid character ID */ async handleCharacterInfo(chargs, charid) { - if (chargs[0]) { let cini = {}; const img = document.getElementById(`demo_${charid}`); @@ -787,7 +786,7 @@ class Client extends EventEmitter { '.png', '.webp', ]; - img.alt = chargs[0] + img.alt = chargs[0]; const charIconBaseUrl = `${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char_icon`; for (let i = 0; i < extensions.length; i++) { const fileUrl = charIconBaseUrl + extensions[i]; @@ -795,7 +794,7 @@ class Client extends EventEmitter { if (exists) { img.alt = chargs[0]; img.src = fileUrl; - return + return; } } }; @@ -886,7 +885,7 @@ class Client extends EventEmitter { * @param {Array} args packet arguments */ async handleSC(args) { - const sleep = ms => new Promise(r => setTimeout(r, ms)); + const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); // Add this so people can see characters loading on the screen. document.getElementById('client_loading').style.display = 'none'; @@ -897,7 +896,7 @@ class Client extends EventEmitter { document.getElementById('client_loadingtext').innerHTML = `Loading Character ${i}/${this.char_list_length}`; const chargs = args[i].split('&'); const charid = i - 1; - await sleep(.1) // TODO: Too many network calls without this. net::ERR_INSUFFICIENT_RESOURCES + await sleep(0.1); // TODO: Too many network calls without this. net::ERR_INSUFFICIENT_RESOURCES this.handleCharacterInfo(chargs, charid); } // We're done with the characters, request the music -- cgit