Skip to content

Commit

Permalink
Merge pull request #26 from MrPrimate/jack/monster
Browse files Browse the repository at this point in the history
Monster Parsing
  • Loading branch information
MrPrimate authored Nov 28, 2020
2 parents 4ac2eb1 + c3a56d8 commit 6d2c787
Show file tree
Hide file tree
Showing 30 changed files with 2,652 additions and 60 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# v 0.0.27

* Improvements to broken source name lookup
* Items/Weapons can now download/use D&D Beyond images
* Use remote dndbeyond images rather than downloading
* Monster parsing moved into git

# v 0.0.26

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.26",
"download": "https://github.com/mrprimate/ddb-importer/releases/download/0.0.26/ddb-importer.zip",
"version": "0.0.27",
"download": "https://github.com/mrprimate/ddb-importer/releases/download/0.0.27/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
13 changes: 13 additions & 0 deletions src/character/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getSRDCompendiumItems,
copySRDIcons,
download,
getDDBIcons,
} from "../muncher/import.js";

const EQUIPMENT_TYPES = ["equipment", "consumable", "tool", "loot", "backpack"];
Expand Down Expand Up @@ -388,6 +389,12 @@ export default class CharacterImport extends Application {
description: "Use icons from the SRD compendium. (This can take a while).",
enabled: true,
},
{
name: "use-ddb-icons",
isChecked: game.settings.get("ddb-importer", "character-update-policy-use-ddb-icons"),
description: "Use icons from D&DBeyond for items (where they exist).",
enabled: true,
},
];

const advancedImportConfig = [
Expand Down Expand Up @@ -647,11 +654,17 @@ export default class CharacterImport extends Application {
if (items.length > 0) {
CharacterImport.showCurrentTask(html, "Copying existing data flags");
await this.copySupportedCharacterItemFlags(items);

if (useSRDCompendiumIcons && !useSRDCompendiumItems) {
CharacterImport.showCurrentTask(html, "Adding SRD Icons");
items = await copySRDIcons(items);
}

if (game.settings.get("ddb-importer", "character-update-policy-use-ddb-icons")) {
CharacterImport.showCurrentTask(html, "Fetching DDB Inventory Images");
items = await getDDBIcons(items, true);
}

CharacterImport.showCurrentTask(html, "Adding items to character");
await this.importItems(items);
}
Expand Down
24 changes: 21 additions & 3 deletions src/hooks/ready/registerGameSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ export default function () {
default: false,
});

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

game.settings.register("ddb-importer", "character-update-policy-dae-copy", {
name: "ddb-importer.character-update-policy-dae-copy.name",
hint: "ddb-importer.character-update-policy-dae-copy.hint",
Expand Down Expand Up @@ -320,15 +329,24 @@ export default function () {
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",
game.settings.register("ddb-importer", "munching-policy-remote-images", {
name: "ddb-importer.munching-policy-remote-images.name",
hint: "ddb-importer.munching-policy-remote-images.hint",
scope: "player",
config: false,
type: Boolean,
default: true,
});

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

game.settings.register("ddb-importer", "munching-policy-dae-copy", {
name: "ddb-importer.munching-policy-dae-copy.name",
hint: "ddb-importer.munching-policy-dae-copy.hint",
Expand Down
80 changes: 55 additions & 25 deletions src/muncher/ddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,31 @@ export default class DDBMuncher extends Application {
html.find("#munch-monsters-start").click(async () => {
munchNote(`Please be patient downloading monsters!`, true);
$('button[id^="munch-"]').prop('disabled', true);
this.parseCritters();
DDBMuncher.parseCritters();
});
html.find("#munch-spells-start").click(async () => {
munchNote(`Please be patient downloading spells!`, true);
$('button[id^="munch-"]').prop('disabled', true);
this.parseSpells();
DDBMuncher.parseSpells();
});
html.find("#munch-items-start").click(async () => {
munchNote(`Please be patient downloading items!`, true);
$('button[id^="munch-"]').prop('disabled', true);
this.parseItems();
DDBMuncher.parseItems();
});

// watch the change of the import-policy-selector checkboxes
html.find('.munching-generic-config input[type="checkbox"]').on("change", (event) => {
game.settings.set(
"ddb-importer",
"munching-policy-" + event.currentTarget.dataset.section,
event.currentTarget.checked
);
const selection = event.currentTarget.dataset.section;
const checked = event.currentTarget.checked;
game.settings.set("ddb-importer", "munching-policy-" + selection, checked);
if (selection == "remote-images" && checked) {
game.settings.set("ddb-importer", "munching-policy-download-images", false);
$('#munching-generic-policy-download-images').prop('checked', false);
} else if (selection == "download-images" && checked) {
game.settings.set("ddb-importer", "munching-policy-remote-images", false);
$('#munching-generic-policy-remote-images').prop('checked', false);
}
});

html.find('.munching-spell-config input[type="checkbox"]').on("change", (event) => {
Expand All @@ -61,6 +66,7 @@ export default class DDBMuncher extends Application {
"munching-policy-" + event.currentTarget.dataset.section,
event.currentTarget.checked
);

});

html.find('.munching-item-config input[type="checkbox"]').on("change", (event) => {
Expand All @@ -73,35 +79,54 @@ export default class DDBMuncher extends Application {
this.close();
}

static enableButtons() {
const cobalt = game.settings.get("ddb-importer", "cobalt-cookie") != "";
const betaKey = game.settings.get("ddb-importer", "beta-key") != "";

if (cobalt) {
$('button[id^="munch-spells-start"]').prop('disabled', false);
$('button[id^="munch-items-start"]').prop('disabled', false);
}
if (cobalt && betaKey) {
// $('button[id^="munch-features-start"]').prop('disabled', false);
$('button[id^="munch-monsters-start"]').prop('disabled', false);
}
}

async parseCritters() {
static async parseCritters() {
try {
logger.info("Munching monsters!");
await parseCritters();
this.close();
const result = await parseCritters();
munchNote(`Finised importing ${result} monsters!`, true);
munchNote("");
DDBMuncher.enableButtons();
} catch (error) {
logger.error(error);
logger.error(error.stack);
}

}

async parseSpells() {
static async parseSpells() {
try {
logger.info("Munching spells!");
await parseSpells();
this.close();
const result = await parseSpells();
munchNote(`Finised importing ${result.length} spells!`, true);
munchNote("");
DDBMuncher.enableButtons();
} catch (error) {
logger.error(error);
logger.error(error.stack);
}
}

async parseItems() {
static async parseItems() {
try {
logger.info("Munching items!");
await parseItems();
this.close();
const result = await parseItems();
munchNote(`Finised importing ${result.length} items!`, true);
munchNote("");
DDBMuncher.enableButtons();
} catch (error) {
logger.error(error);
logger.error(error.stack);
Expand All @@ -124,14 +149,7 @@ export default class DDBMuncher extends Application {
},
];

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

const genericConfig = [
{
Expand All @@ -158,6 +176,18 @@ export default class DDBMuncher extends Application {
description: "Use Iconizer (if installed).",
enabled: iconizerInstalled,
},
{
name: "download-images",
isChecked: game.settings.get("ddb-importer", "munching-policy-download-images"),
description: "Download D&D Beyond images (takes longer and needs space)",
enabled: true,
},
{
name: "remote-images",
isChecked: game.settings.get("ddb-importer", "munching-policy-remote-images"),
description: "Use D&D Beyond remote images (a lot quicker)",
enabled: true,
},
// {
// name: "dae-copy",
// isChecked: game.settings.get("ddb-importer", "munching-policy-dae-copy"),
Expand Down
1 change: 1 addition & 0 deletions src/muncher/ddb_munch.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<h3>Munching flavours</h3>
{{#each genericConfig}}
<div class="munching-generic-config"><input {{#if this.isChecked}}checked{{/if}} type="checkbox"
id="munching-generic-policy-{{this.name}}"
name="munching-policy-{{this.name}}"
data-section="{{this.name}}" {{#if this.enabled}}enabled{{else}}disabled{{/if}}>{{this.description}}
</div>
Expand Down
Loading

0 comments on commit 6d2c787

Please sign in to comment.