Skip to content

Commit

Permalink
v0.0.21
Browse files Browse the repository at this point in the history
Add more icon options
  • Loading branch information
MrPrimate committed Nov 23, 2020
1 parent 74b0c8e commit 8b314e3
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 81 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v 0.0.21

* Compendium import will now use Iconizer if it's installed and active for missing icons
* Even more SRD icon matching
* Allow use of DDB Spell School icons

# v 0.0.20

* Override HP not working correctly
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "ddb-importer",
"title": "D&D Beyond Importer",
"description": "Import your dndbeyond.com characters, spells and monsters at super speed!",
"version": "0.0.20",
"download": "https://github.com/mrprimate/ddb-importer/releases/download/0.0.20/ddb-importer.zip",
"version": "0.0.21",
"download": "https://github.com/mrprimate/ddb-importer/releases/download/0.0.21/ddb-importer.zip",
"manifest": "https://github.com/mrprimate/ddb-importer/releases/download/latest/module.json",
"url": "https://github.com/mrprimate/ddb-importer",
"minimumCoreVersion": "0.7.5",
Expand Down
16 changes: 8 additions & 8 deletions src/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,14 @@ const DICTIONARY = {
},
spell: {
schools: [
{ id: "abj", name: "abjuration" },
{ id: "con", name: "conjuration" },
{ id: "div", name: "divination" },
{ id: "enc", name: "enchantment" },
{ id: "evo", name: "evocation" },
{ id: "ill", name: "illusion" },
{ id: "nec", name: "necromancy" },
{ id: "trs", name: "transmutation" },
{ id: "abj", name: "abjuration", img: "https://www.dndbeyond.com/content/1-0-1337-0/skins/waterdeep/images/spell-schools/35/abjuration.png" },
{ id: "con", name: "conjuration", img: "https://www.dndbeyond.com/content/1-0-1337-0/skins/waterdeep/images/spell-schools/35/conjuration.png" },
{ id: "div", name: "divination", img: "https://www.dndbeyond.com/content/1-0-1337-0/skins/waterdeep/images/spell-schools/35/divination.png" },
{ id: "enc", name: "enchantment", img: "https://www.dndbeyond.com/content/1-0-1337-0/skins/waterdeep/images/spell-schools/35/enchantment.png" },
{ id: "evo", name: "evocation", img: "https://www.dndbeyond.com/content/1-0-1337-0/skins/waterdeep/images/spell-schools/35/evocation.png" },
{ id: "ill", name: "illusion", img: "https://www.dndbeyond.com/content/1-0-1337-0/skins/waterdeep/images/spell-schools/35/illusion.png" },
{ id: "nec", name: "necromancy", img: "https://www.dndbeyond.com/content/1-0-1337-0/skins/waterdeep/images/spell-schools/35/necromancy.png" },
{ id: "trs", name: "transmutation", img: "https://www.dndbeyond.com/content/1-0-1337-0/skins/waterdeep/images/spell-schools/35/transmutation.png" },
],
progression: [
{ name: "Artificer", value: "artificer" },
Expand Down
18 changes: 18 additions & 0 deletions src/hooks/ready/registerGameSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,24 @@ export default function () {
default: true,
});

game.settings.register("ddb-importer", "munching-policy-use-iconizer", {
name: "ddb-importer.munching-policy-use-iconizer.name",
hint: "ddb-importer.munching-policy-use-iconizer.hint",
scope: "player",
config: false,
type: Boolean,
default: true,
});

game.settings.register("ddb-importer", "munching-policy-use-ddb-icons", {
name: "ddb-importer.munching-policy-use-ddb-icons.name",
hint: "ddb-importer.munching-policy-use-ddb-icons.hint",
scope: "player",
config: false,
type: Boolean,
default: true,
});

game.settings.register("ddb-importer", "munching-policy-download-monster-images", {
name: "ddb-importer.munching-policy-download-monster-images.name",
hint: "ddb-importer.munching-policy-download-monster-images.hint",
Expand Down
40 changes: 32 additions & 8 deletions src/muncher/ddb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Main module class
import logger from "../logger.js";
import utils from "../utils.js";
import { parseItems } from "./items.js";
import { parseSpells } from "./spells.js";
import { parseCritters } from "./monsters.js";
Expand Down Expand Up @@ -86,9 +87,29 @@ export default class DDBMuncher extends Application {
getData() { // eslint-disable-line class-methods-use-this
const cobalt = game.settings.get("ddb-importer", "cobalt-cookie") != "";
const betaKey = game.settings.get("ddb-importer", "beta-key") != "";
// const daeInstalled = game.modules.get('dae').active && game.modules.get('Dynamic-Effects-SRD').active;
// const daeInstalled = utils.isModuleInstalledAndActive('dae') && utils.isModuleInstalledAndActive('Dynamic-Effects-SRD');
const iconizerInstalled = utils.isModuleInstalledAndActive("vtta-iconizer");

const importConfig = [
const itemConfig = [];
const spellConfig = [
{
name: "use-ddb-icons",
isChecked: game.settings.get("ddb-importer", "munching-policy-use-ddb-icons"),
description: "If no other icon, use the D&DBeyond spell school icon.",
enabled: true,
},
];

const monsterConfig = [
{
name: "download-monster-images",
isChecked: game.settings.get("ddb-importer", "munching-policy-download-monster-images"),
description: "Download Monster Images",
enabled: true,
},
];

const genericConfig = [
{
name: "update-existing",
isChecked: game.settings.get("ddb-importer", "munching-policy-update-existing"),
Expand All @@ -103,15 +124,15 @@ export default class DDBMuncher extends Application {
},
{
name: "use-srd-icons",
isChecked: game.settings.get("ddb-importer", "munching-policy-use-srd-icons"),
isChecked: (iconizerInstalled) ? game.settings.get("ddb-importer", "munching-policy-use-srd-icons") : false,
description: "Use icons from the SRD compendiums.",
enabled: true,
},
{
name: "download-monster-images",
isChecked: game.settings.get("ddb-importer", "munching-policy-download-monster-images"),
description: "Download Monster Images",
enabled: true,
name: "use-iconizer-icons",
isChecked: game.settings.get("ddb-importer", "munching-policy-use-iconizer"),
description: "If installed use Iconizer.",
enabled: iconizerInstalled,
},
// {
// name: "dae-copy",
Expand All @@ -122,7 +143,10 @@ export default class DDBMuncher extends Application {
];
return {
cobalt: cobalt,
importConfig: importConfig,
genericConfig: genericConfig,
monsterConfig: monsterConfig,
spellConfig: spellConfig,
itemConfig: itemConfig,
beta: betaKey && cobalt,
};
}
Expand Down
29 changes: 20 additions & 9 deletions src/muncher/ddb_munch.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,22 @@
<li>While you wait, why not join me on <a href="https://www.patreon.com/MrPrimate">Patreon</a>? Active Patreon supports will get beta access to Monster Munching in December.</li>
</ul>
<hr>
<br />
<div class="munching-task-name" id="munching-task-name">
<b> </b>
<br />
</div>
<div class="munching-task-notes" id="munching-task-notes">
<b> </b>
<br />
</div>
<br />

<hr>
<div>
<h3>Munching flavours</h3>
{{#each importConfig}}
<div class="munching-import-config"><input {{#if this.isChecked}}checked{{/if}} type="checkbox"
{{#each genericConfig}}
<div class="munching-generic-config"><input {{#if this.isChecked}}checked{{/if}} type="checkbox"
name="munching-policy-{{this.name}}"
data-section="{{this.name}}" {{#if this.enabled}}enabled{{else}}disabled{{/if}}>{{this.description}}
</div>
{{/each}}
</div>
<hr>

<div>
<hr>
Expand All @@ -39,9 +35,18 @@
<div class="form-description">
<div class="form-description"></div>
<div>
<div>
{{#each spellConfig}}
<div class="munching-spell-config"><input {{#if this.isChecked}}checked{{/if}} type="checkbox"
name="munching-policy-{{this.name}}"
data-section="{{this.name}}" {{#if this.enabled}}enabled{{else}}disabled{{/if}}>{{this.description}}
</div>
{{/each}}

<button type="button" id="munch-spells-start" class="munch-button"
{{#if cobalt}}enabled{{else}}disabled{{/if}}>Spell Munch</button>
</div>
<hr>
<div>
<button type="button" id="munch-items-start" class="munch-button"
{{#if cobalt}}enabled{{else}}disabled{{/if}}>Item Munch</button>
Expand All @@ -53,15 +58,21 @@
<hr>
<div>
<h4>Monster Search Filter (leave blank for all)</h4>
Make sure you have imported spells before Monsters!
</div>
<div class="form-content" style="display: flex">
<input type="text" name="monster-filter" id="monster-munch-filter" style="flex: 0 1 auto" ;value="" />
</div>
{{#each monsterConfig}}
<div class="munching-spell-config"><input {{#if this.isChecked}}checked{{/if}} type="checkbox"
name="munching-policy-{{this.name}}"
data-section="{{this.name}}" {{#if this.enabled}}enabled{{else}}disabled{{/if}}>{{this.description}}
</div>
{{/each}}
<div>
<button type="button" id="munch-monsters-start" class="munch-button"
{{#if beta}}enabled{{else}}disabled{{/if}}><s>Monster Munch</s> SOON!</button>
</div>
Make sure you have imported spells before Monsters!
</div>
</div>
</div>
Expand Down
83 changes: 80 additions & 3 deletions src/muncher/import.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import utils from "../utils.js";
import logger from "../logger.js";
import DICTIONARY from "../dictionary.js";

const EQUIPMENT_TYPES = ["equipment", "consumable", "tool", "loot", "backpack"];

Expand Down Expand Up @@ -143,7 +144,7 @@ export function getLooseNames(name) {
refactNameArray.unshift(refactNameArray.pop());
const refactName = refactNameArray.join(" ").trim();
looseNames.push(refactName, refactName.toLowerCase());
looseNames.push(refactName.replace(/\+\d*\s*/, "").trim().toLowerCase())
looseNames.push(refactName.replace(/\+\d*\s*/, "").trim().toLowerCase());

let refactNamePlusArray = name.replace(/\+\d*\s*/, "").trim().split("(")[0].trim().split(", ");
refactNamePlusArray.unshift(refactNamePlusArray.pop());
Expand Down Expand Up @@ -471,6 +472,51 @@ export async function getSRDIconMatch(type) {
return items;
}

/**
* Sends a event request to Iconizer to add the correct icons
* @param {*} names
*/
function queryIconizer(names) {
return new Promise((resolve, reject) => {
let listener = (event) => {
resolve(event.detail);
// cleaning up
document.removeEventListener("deliverIcon", listener);
};

setTimeout(() => {
document.removeEventListener("deliverIcon", listener);
reject("Tokenizer not responding");
}, 500);
document.addEventListener("deliverIcon", listener);
document.dispatchEvent(new CustomEvent("queryIcons", { detail: { names: names } }));
});
}

async function getIconizerIcons(items) {
// replace icons by iconizer, if available
const itemNames = items.map((item) => {
return {
name: item.name,
};
});
try {
logger.debug("Querying iconizer for icons");
const icons = await queryIconizer(itemNames);
logger.verbose("Icons found", icons);

// replace the icons
items.forEach((item) => {
const icon = icons.find((icon) => icon.name === item.name);
if (icon && (!item.img || item.img == "" || item.img == "icons/svg/mystery-man.svg")) {
item.img = icon.img;
}
});
} catch (exception) {
logger.debug("Iconizer not responding");
}
return items;
}

export async function copySRDIcons(items) {
const compendiumFeatureItems = await getSRDIconMatch("features");
Expand All @@ -497,12 +543,43 @@ export async function copySRDIcons(items) {
});
}

export async function getDDBIcons(items) {
items.forEach((item) => {
if (!item.type == "spell") return;
const school = DICTIONARY.spell.schools.find((school) => school.id === item.data.school);
if (school && (!item.img || item.img == "" || item.img == "icons/svg/mystery-man.svg")) {
item.img = school.img;
}
});
return items;
}


export async function updateIcons(items) {
// check for SRD icons
const srdIcons = game.settings.get("ddb-importer", "munching-policy-use-srd-icons");
// eslint-disable-next-line require-atomic-updates
if (srdIcons) items = await copySRDIcons(items);

// use iconizer
const iconizerInstalled = utils.isModuleInstalledAndActive("vtta-iconizer");
const useIconizer = game.settings.get("ddb-importer", "munching-policy-use-iconizer");
if (iconizerInstalled && useIconizer) items = await getIconizerIcons(items);

// this will use ddb spell school icons as a fall back
const ddbIcons = game.settings.get("ddb-importer", "munching-policy-use-ddb-icons");
if (ddbIcons) items = await getDDBIcons(items);

return items;
}


export async function srdFiddling(items, type) {
const updateBool = game.settings.get("ddb-importer", "munching-policy-update-existing");
const useSrd = game.settings.get("ddb-importer", "munching-policy-use-srd");
const srdIcons = game.settings.get("ddb-importer", "munching-policy-use-srd-icons");
const iconItems = (srdIcons) ? await copySRDIcons(items) : items;
// const srdIcons = game.settings.get("ddb-importer", "munching-policy-use-srd-icons");
// const iconItems = (srdIcons) ? await copySRDIcons(items) : items;
const iconItems = updateIcons(items);

if (useSrd) {
logger.debug("Removing compendium items");
Expand Down
Loading

0 comments on commit 8b314e3

Please sign in to comment.