aboutsummaryrefslogtreecommitdiff
path: root/webAO/client/fetchLists.ts
blob: 2f2fd5953b7a0ee4a0b965803789b1c3c6bf0235 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { client } from "../client";
import { AO_HOST } from "./aoHost";
import { request } from "../services/request.js";

export const fetchBackgroundList = async () => {
  try {
    const bgdata = await request(`${AO_HOST}backgrounds.json`);
    const bg_array = JSON.parse(bgdata);
    // the try catch will fail before here when there is no file

    const bg_select = <HTMLSelectElement>document.getElementById("bg_select");
    bg_select.innerHTML = "";

    bg_select.add(new Option("Custom", "0"));
    bg_array.forEach((background: string) => {
      bg_select.add(new Option(background));
    });
  } catch (err) {
    console.warn("there was no backgrounds.json file");
  }
};

export const fetchCharacterList = async () => {
  const char_select = <HTMLSelectElement>(
    document.getElementById("client_iniselect")
  );
  char_select.innerHTML = "";

  char_select.add(new Option("Custom", "0"));

  try {
    const chardata = await request(`${AO_HOST}characters.json`);
    const char_array = JSON.parse(chardata);
    // the try catch will fail before here when there is no file

    char_array.forEach((character: string) => {
      char_select.add(new Option(character));
    });
  } catch (err) {
    console.warn("there was no characters.json file");
  }
};

export const fetchEvidenceList = async () => {
  const evi_select = <HTMLSelectElement>document.getElementById("evi_select");
  evi_select.innerHTML = "";

  evi_select.add(new Option("Custom", "0"));

  try {
    const evidata = await request(`${AO_HOST}evidence.json`);
    const evi_array = JSON.parse(evidata);
    evi_array.forEach((evi: string) => {
      evi_select.add(new Option(evi));
    });
  } catch (err) {
    console.warn("there was no evidence.json file");
  }
};

export const fetchExtensions = async () => {
  try {
    const extensiondata = await request(`${AO_HOST}extensions.json`);
    const allextensions = JSON.parse(extensiondata);
    client.charicon_extensions = allextensions.charicon_extensions || [".png", ".webp"];
    client.emote_extensions = allextensions.emote_extensions || [".gif", ".png", ".apng", ".webp", ".webp.static"];
    client.emotions_extensions = allextensions.emotions_extensions || [".png", ".webp"];
    client.background_extensions = allextensions.background_extensions || [".png", ".gif", ".webp", ".apng"];
    console.log("charicons "+client.charicon_extensions)
    console.log("emotes "+client.emote_extensions)
    console.log("emotions "+client.emotions_extensions)
    console.log("backgrounds "+client.background_extensions)
  } catch (err) {
    console.warn("there was no extensions.json file");
  }
};