aboutsummaryrefslogtreecommitdiff
path: root/webAO/client/createArea.ts
blob: 9a40bef4ed057ad9cc3a05b5d2287274db59bd45 (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
import { client } from "../client";
import { area_click } from "../dom/areaClick";
import { safeTags } from "../encoding";

export const createArea = (id: number, aname: string) => {
  const name = safeTags(aname);
  const thisarea = {
    name,
    players: 0,
    status: "IDLE",
    cm: "",
    locked: "FREE",
  };

  client.areas.push(thisarea);

  // Create area button
  const newarea = document.createElement("SPAN");
  newarea.className = "area-button area-default";
  newarea.id = `area${id}`;
  newarea.innerText = thisarea.name;
  newarea.title =
    `Players: ${thisarea.players}\n` +
    `Status: ${thisarea.status}\n` +
    `CM: ${thisarea.cm}\n` +
    `Area lock: ${thisarea.locked}`;
  newarea.onclick = function () {
    area_click(newarea);
  };

  document.getElementById("areas")!.appendChild(newarea);
};