diff options
| author | stonedDiscord <Tukz@gmx.de> | 2024-08-12 13:40:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-12 13:40:47 +0200 |
| commit | 2039178b0f4550534ea6cca1efe64e2a6e4e901d (patch) | |
| tree | 880b7290ed18b2eb8fb38dc8a39b5ad0ca234e58 /webAO/client/handleCharacterInfo.ts | |
| parent | 1a32ea5886de62a495e6fcc65b3d270f9bd84cce (diff) | |
| parent | dc85197c9b966105813dd026480f9f6bc77d8b68 (diff) | |
Merge pull request #225 from AttorneyOnline/playerlist
Playerlist
Diffstat (limited to 'webAO/client/handleCharacterInfo.ts')
| -rw-r--r-- | webAO/client/handleCharacterInfo.ts | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/webAO/client/handleCharacterInfo.ts b/webAO/client/handleCharacterInfo.ts index 9d74a8b..cd024b5 100644 --- a/webAO/client/handleCharacterInfo.ts +++ b/webAO/client/handleCharacterInfo.ts @@ -6,6 +6,24 @@ import fileExists from "../utils/fileExists"; import { AO_HOST } from "./aoHost"; +export const getCharIcon = async (img: HTMLImageElement, charname: string) => { + const extensions = [".png", ".webp"]; + img.alt = charname; + const charIconBaseUrl = `${AO_HOST}characters/${encodeURI( + charname.toLowerCase() + )}/char_icon`; + for (let i = 0; i < extensions.length; i++) { + const fileUrl = charIconBaseUrl + extensions[i]; + const exists = await fileExists(fileUrl); + if (exists) { + img.alt = charname; + img.title = charname; + img.src = fileUrl; + return; + } + } +}; + /** * Handles the incoming character information, and downloads the sprite + ini for it * @param {Array} chargs packet arguments @@ -15,24 +33,8 @@ export const handleCharacterInfo = async (chargs: string[], charid: number) => { const img = <HTMLImageElement>document.getElementById(`demo_${charid}`); if (chargs[0]) { let cini: any = {}; - 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) { - img.alt = chargs[0]; - img.title = chargs[0]; - img.src = fileUrl; - return; - } - } - }; - getCharIcon(); + + getCharIcon(img, chargs[0]); // If the ini doesn't exist on the server this will throw an error try { |
