diff options
Diffstat (limited to 'webAO')
| -rw-r--r-- | webAO/client/handleCharacterInfo.ts | 38 | ||||
| -rw-r--r-- | webAO/packets/handlers/handlePR.ts | 23 | ||||
| -rw-r--r-- | webAO/packets/handlers/handlePU.ts | 9 | ||||
| -rw-r--r-- | webAO/packets/handlers/handlePV.ts | 25 | ||||
| -rw-r--r-- | webAO/ui.js | 19 |
5 files changed, 83 insertions, 31 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 { diff --git a/webAO/packets/handlers/handlePR.ts b/webAO/packets/handlers/handlePR.ts new file mode 100644 index 0000000..1908077 --- /dev/null +++ b/webAO/packets/handlers/handlePR.ts @@ -0,0 +1,23 @@ +import { client } from "../../client"; + +function addPlayer(playerID) { +const list = <HTMLTableElement>document.getElementById("client_playerlist"); + +} + +function removePlayer(playerID) { + const list = <HTMLTableElement>document.getElementById("client_playerlist"); + +} + +/** + * Handles a player joining or leaving + * @param {Array} args packet arguments + */ +export const handlePR = (args: string[]) => { + const playerID = Number(args[1]); + if (Number(args[2]) === 0) + addPlayer(playerID); + else if (Number(args[2]) === 1) + removePlayer(playerID); +}
\ No newline at end of file diff --git a/webAO/packets/handlers/handlePU.ts b/webAO/packets/handlers/handlePU.ts new file mode 100644 index 0000000..0bc1201 --- /dev/null +++ b/webAO/packets/handlers/handlePU.ts @@ -0,0 +1,9 @@ +import { getCharIcon } from "../../client/handleCharacterInfo"; + +/** + * Handles a playerlist update + * @param {Array} args packet arguments + */ +export const handlePU = (args: string[]) => { + const playerID = Number(args[1]); +}
\ No newline at end of file diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts index 879d004..38657be 100644 --- a/webAO/packets/handlers/handlePV.ts +++ b/webAO/packets/handlers/handlePV.ts @@ -4,6 +4,19 @@ import { updateActionCommands } from '../../dom/updateActionCommands' import { pickEmotion } from '../../dom/pickEmotion' import { AO_HOST } from "../../client/aoHost"; +function addEmoteButton(i: Number, imgurl: string, desc: string) { + const emotesList = document.getElementById("client_emo"); + const emote_item = new Image(); + emote_item.id = "emo_" + i; + emote_item.className = "emote_button"; + emote_item.src = imgurl; + emote_item.alt = desc; + emote_item.title = desc; + emote_item.onclick = () => { window.pickEmotion(i) } + emotesList.appendChild(emote_item); +} + + /** * Handles the server's assignment of a character for the player to use. * PV # playerID (unused) # CID # character ID @@ -17,7 +30,7 @@ export const handlePV = async (args: string[]) => { const me = client.chars[client.charID]; client.selectedEmote = -1; const { emotes } = client; - const emotesList = document.getElementById("client_emo")!; + const emotesList = document.getElementById("client_emo"); emotesList.style.display = ""; emotesList.innerHTML = ""; // Clear emote box const ini = me.inifile; @@ -72,14 +85,8 @@ export const handlePV = async (args: string[]) => { button: url, }; - const emote_item = new Image(); - emote_item.id = "emo_" + i; - emote_item.className = "emote_button"; - emote_item.src = emotes[i].button; - emote_item.alt = emotes[i].desc; - emote_item.title = emotes[i].desc; - emote_item.onclick = () => { window.pickEmotion(i) } - emotesList.appendChild(emote_item); + addEmoteButton(i, url, emotes[i].desc); + if (i === 1) pickEmotion(1); } catch (e) { console.error(`missing emote ${i}`); diff --git a/webAO/ui.js b/webAO/ui.js index f82688c..154b008 100644 --- a/webAO/ui.js +++ b/webAO/ui.js @@ -47,11 +47,22 @@ const config = { }], }, { - type: 'component', - title: 'Music', + type: 'stack', width: 30, - componentName: 'template', - componentState: { id: 'music' }, + content: [{ + type: 'component', + isClosable: false, + title: 'Music', + componentName: 'template', + componentState: { id: 'music' }, + }, + { + type: 'component', + isClosable: false, + title: 'Players', + componentName: 'template', + componentState: { id: 'players' }, + }], }], }, { |
