Skip to content

Commit

Permalink
feat: select menu to load a mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanistzed committed Aug 30, 2021
1 parent a761684 commit 2f47ace
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,37 @@ Hooks.on("renderSettingsConfig", () => {
oldTextBox.value = newTextBox.value;
});
};

// Create mapping select menu
const mappingSelect = document.createElement("select");
mappingSelect.style.margin = "10px 0";
oldTextBox.parentNode.before(mappingSelect);

// Add options for each finished mapping
Pdfconfig.MAPPINGS.forEach(name => {
// Create the option
const option = document.createElement("option");
mappingSelect.append(option);

// Add text
option.innerHTML = name;
});

// Add an event listener
mappingSelect.addEventListener("change", async () => {
const mapping = await fetch(`/modules/pdf-sheet/mappings/${mappingSelect.value}.mapping`)
.then(response => response.text());

// Copy the mapping to the old text box
oldTextBox.value = mapping;
if (game.modules.get("acelib")?.active) {
// Copy the mapping to the ace editor
editor.setValue(mapping);
} else {
// Copy the mapping to the new textbox
newTextBox.value = mapping;
};
});
};
});

Expand Down Expand Up @@ -106,6 +137,9 @@ class Pdfconfig extends FormApplication {
/** The module's ID */
static ID = "pdf-sheet";

/** Finished mappings */
static MAPPINGS = ["", "cyphersystem"];

/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
Expand Down

0 comments on commit 2f47ace

Please sign in to comment.