diff options
| author | stonedDiscord <Tukz@gmx.de> | 2024-08-07 19:23:44 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2024-08-07 19:23:44 +0200 |
| commit | a87d5a87167ee790b395f57eb5da19fbaa684537 (patch) | |
| tree | 621102bde769c597320a62942ff6a00395ec17dd /webAO/client/handleCharacterInfo.ts | |
| parent | 267c3b81fe8cd10578a6cd68e74cebbd5d130bf5 (diff) | |
update layout
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..86d1a09 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"; +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 { |
