summaryrefslogtreecommitdiff
path: root/src/renderer/gameserver/serverView/screenshots.ts
blob: b2c0abf3da08429688ba7b280829ed1fc4331d92 (plain) (blame)
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
import { ML_Runtime } from "../../runtime";
import { GameServerPage } from "./serverPage";

export class ServerScreenshotPage extends GameServerPage {
  getPage(): HTMLElement {
    const screenshotContainer = document.createElement("div");
    screenshotContainer.classList.add("screenshotsContainer");
    screenshotContainer.id = "screenshots";

    ML_Runtime.getScreenshots(this.server.profile.address)
      .then(this.dataLoadedCallback.bind(null, screenshotContainer))
      .catch((err) => {
        // handle this?
        console.error(err);
      });

    return screenshotContainer;
  }

  private dataLoadedCallback(
    screenshotContainer: HTMLDivElement,
    data: { dir: string; screenshots: string[] }
  ) {
    console.log(data);
    if (screenshotContainer) {
      // Display screenshots if that tab is open
      if (data.screenshots.length !== 0) {
        data.screenshots.forEach((fileName: string) => {
          const screenshot = document.createElement("div");
          screenshot.classList.add("screenshot");
          screenshotContainer.appendChild(screenshot);
          const img = document.createElement("img");
          img.src = data.dir + fileName;
          screenshot.appendChild(img);

          // const text = document.createElement("span");
          // text.innerText = fileName;
          // screenshot.appendChild(text);
          screenshot.addEventListener("dragstart", (event) => {
            event.preventDefault();
            ML_Runtime.dragFileOut(data.dir + fileName);
          });
        });
      } else {
        const nothingHere = document.createElement("p");
        nothingHere.classList.add("nothingHere");
        nothingHere.innerText =
          "There is nothing here, yet. Make some screenshots in Game and come back here. The default key for snaping screenshots is 'P'.";

        screenshotContainer.appendChild(nothingHere);
      }

      const openFolderButton = document.createElement("button");
      openFolderButton.innerText = "Open folder to see all";
      openFolderButton.addEventListener("click", () => {
        ML_Runtime.openFolder(data.dir);
      });
      screenshotContainer.appendChild(openFolderButton);
    }
  }
}