-
Notifications
You must be signed in to change notification settings - Fork 0
/
FoundryGui.mjs
94 lines (87 loc) · 4.12 KB
/
FoundryGui.mjs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
var __defProp2 = Object.defineProperty, __name2 = __name((target, value) =>
__defProp2(target, "name", {
value,
configurable: !0
}),
"__name");
import { c as compare } from "./vendor.mjs";
import Importer from "./importer.mjs";
const minimumVersion = "1.5.1", _PdfImporter = class {
static { __name(this, "_PdfImporter") } constructor() {
Hooks.once("init", () => {
this.hookImportButton(),
game.settings.register("shadowdark-pdf-importer", "useAlias", {
name: "Use Common Names",
hint: "Use common names for creatures rather than their headings in their statblock. For instance, \"Brown Bear\" instead of \"Bear, Brown\"",
scope: "world",
config: !0,
default: true,
type: Boolean
}),
game.settings.register("shadowdark-pdf-importer", "useSizeData", {
name: "Include Size Data",
hint: "Grow the token to match the creature's physical size. *NOTE* since creature size rules are not part of the rules as written, these are assumptions based on artwork and common sense. If unselected, all creatures will be the same size as player character tokens.",
scope: "world",
config: !0,
default: true,
type: Boolean
}),
game.pdfImporter = {
import: () => this.importFromPDFDialog()
}
})
}
hookImportButton() {
Hooks.on("renderSettings", (app, html, data) => {
console.log("Shadowdark PDF Importer | Adding pdf import button to settings tab");
const importButton = $('<div><button class="bestiary-browser-btn"><i class="fa-solid fa-book-skull"></i> Shadowdark PDF Importer</button></div>');
game.user.isGM && html.find("ul#game-details").after(importButton), importButton.click(ev => {
if (ev.preventDefault(), !compare(game.system.version, minimumVersion, ">=")) return ui.notifications.error(`You need to be using a version of the Shadowdark system at least ${minimumVersion}. You are only using version ${game.system.version}!`);
this.importFromPDFDialog()
})
})
}
async importFromPDFDialog() {
new Dialog({
title: "Import PDF (version 0.0.6)",
content: await renderTemplate("modules/shadowdark-pdf-importer/import-window.html", {}),
buttons: {
import: {
icon: '<i class="fas fa-file-import"></i>',
label: "Import PDF",
callback: async html => {
if (html instanceof HTMLElement) return;
const form = html.find("form")[0];
if (!form.data.files.length) return ui.notifications.error("You did not upload a data file!");
const file = form.data.files[0]
if (file) {
file.arrayBuffer().then(buff => {
let x = new Uint8Array(buff);
const imp = new Importer();
imp.getTextFromPDF(x)
});
}
}
},
no: { icon: '<i class="fas fa-times"></i>', label: "Cancel" }
},
default: "import"
},
{
id: "pdftofoundry-importdialog",
width: 460,
height: "fit-content",
resizable: !1,
tabs: [{
navSelector: "nav",
contentSelector: "section.pdftofoundry-content",
initial: "summary"
}]
}).render(!0)
}
};
__name2(_PdfImporter, "PdfImporter");
let PdfImporter = _PdfImporter;
new PdfImporter;