aboutsummaryrefslogtreecommitdiff
path: root/webAO/dom/renderPlayerList.ts
blob: 48354ae27d35432aa946c56adf9bfdfbb0f7daf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { client } from "../client";
import { AO_HOST } from "../client/aoHost";

export function renderPlayerList() {
  const list = document.getElementById("client_playerlist") as HTMLTableElement;
  list.innerHTML = "";

  const header = list.createTHead().insertRow();
  for (const label of ["Icon", "Character", "Showname", "OOC Name"]) {
    const th = document.createElement("th");
    th.textContent = label;
    header.appendChild(th);
  }

  const body = list.createTBody();
  for (const [playerID, player] of client.playerlist) {
    const playerRow = body.insertRow();
    playerRow.id = `client_playerlist_entry${playerID}`;
    playerRow.style.display = player.area === client.area ? "" : "none";

    const imgCell = playerRow.insertCell(0);
    imgCell.style.width = "64px";
    const img = document.createElement("img");
    img.style.maxWidth = "60px";
    img.style.maxHeight = "60px";
    if (player.charName) {
      const iconExt = client.charicon_extensions[0] || ".png";
      img.src = `${AO_HOST}characters/${encodeURI(player.charName.toLowerCase())}/char_icon${iconExt}`;
      img.alt = player.charName;
      img.title = player.charName;
    }
    imgCell.appendChild(img);

    const charNameCell = playerRow.insertCell(1);
    charNameCell.textContent =
      player.charName ? `[${playerID}] ${player.charName}` : "";

    const showNameCell = playerRow.insertCell(2);
    showNameCell.textContent = player.showName;

    const oocNameCell = playerRow.insertCell(3);
    oocNameCell.textContent = player.name;

    const kickCell = playerRow.insertCell(4);
    kickCell.style.width = "64px";
    const kick = document.createElement("button");
    kick.innerText = "Kick";
    kick.onclick = () => window.kickPlayer(playerID);
    kickCell.appendChild(kick);

    const banCell = playerRow.insertCell(5);
    banCell.style.width = "64px";
    const ban = document.createElement("button");
    ban.innerText = "Ban";
    ban.onclick = () => window.banPlayer(playerID);
    banCell.appendChild(ban);
  }
}