Skip to content

Commit

Permalink
Generate dynamic tables for items (no linking)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPrimate committed Aug 27, 2021
1 parent 335d640 commit 03ccbf5
Show file tree
Hide file tree
Showing 12 changed files with 1,346 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/character/update.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logger from "../logger.js";
import { getCharacterData } from "./import.js";
import { isEqual } from "../../vendor/isequal.js";
import { isEqual } from "../../vendor/lowdash/isequal.js";
import { getCampaignId } from "../muncher/utils.js";
import DICTIONARY from "../dictionary.js";
import { getCobalt, checkCobalt } from "../lib/Secrets.js";
Expand Down
1 change: 1 addition & 0 deletions src/hooks/ready/checkCompendiums.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default async function () {
createIfNotExists("entity-race-compendium", "Item", "Races"),
createIfNotExists("entity-monster-compendium", "Actor", "Monsters"),
createIfNotExists("entity-override-compendium", "Item", "Override"),
createIfNotExists("entity-table-compendium", "RollTable", "Tables"),
]);

const reload = results.some((result) => result.value);
Expand Down
26 changes: 8 additions & 18 deletions src/hooks/ready/registerGameSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: itemCompendiums,
});

game.settings.register("ddb-importer", "entity-feature-compendium", {
Expand All @@ -218,8 +216,6 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: itemCompendiums,
});

game.settings.register("ddb-importer", "entity-class-compendium", {
Expand All @@ -228,8 +224,6 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: itemCompendiums,
});

game.settings.register("ddb-importer", "entity-race-compendium", {
Expand All @@ -238,8 +232,6 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: itemCompendiums,
});

game.settings.register("ddb-importer", "entity-trait-compendium", {
Expand All @@ -248,8 +240,6 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: itemCompendiums,
});

game.settings.register("ddb-importer", "entity-feat-compendium", {
Expand All @@ -258,8 +248,6 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: itemCompendiums,
});

game.settings.register("ddb-importer", "entity-spell-compendium", {
Expand All @@ -268,8 +256,6 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: itemCompendiums,
});

game.settings.register("ddb-importer", "entity-override-compendium", {
Expand All @@ -278,8 +264,14 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: itemCompendiums,
});

game.settings.register("ddb-importer", "entity-table-compendium", {
name: "ddb-importer.entity-table-compendium.name",
hint: "ddb-importer.entity-table-compendium.hint",
scope: "world",
config: false,
type: String,
});

game.settings.register("ddb-importer", "entity-monster-compendium", {
Expand All @@ -288,8 +280,6 @@ export default function () {
scope: "world",
config: false,
type: String,
// isSelect: true,
// choices: actorCompendiums,
});

game.settings.register("ddb-importer", "adventure-import-path", {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ export class DDBCompendiumSetup extends FormApplication {
current: game.settings.get("ddb-importer", "entity-override-compendium"),
compendiums: getCompendiumLookups("Item", game.settings.get("ddb-importer", "entity-override-compendium")),
},
{
setting: "entity-table-compendium",
name: "Tables",
type: "RollTable",
current: game.settings.get("ddb-importer", "entity-table-compendium"),
compendiums: getCompendiumLookups("RollTable", game.settings.get("ddb-importer", "entity-table-compendium")),
},
];

return {
Expand Down
8 changes: 2 additions & 6 deletions src/muncher/adventure/import.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Helpers from "./common.js";
import logger from "../../logger.js";
import utils from "../../utils.js";
import { DirectoryPicker } from "../../lib/DirectoryPicker.js";
import { checkMonsterCompendium } from "../importMonster.js";
import { parseCritters } from "../monsters.js";
Expand Down Expand Up @@ -618,18 +619,13 @@ export default class AdventureMunch extends FormApplication {
return newTokens;
}

static _htmlToDoc(text) {
const parser = new DOMParser();
return parser.parseFromString(text, "text/html");
}

static _foundryCompendiumReplace(text) {
// replace the ddb:// entries with known compendium look ups if we have them
// ddb://spells
// ddb://magicitems || weapons || adventuring-gear || armor
// ddb://monsters

let doc = AdventureMunch._htmlToDoc(text);
let doc = utils.htmlToDoc(text);

const lookups = CONFIG.DDBI.ADVENTURE.TEMPORARY.lookups.lookups;

Expand Down
24 changes: 18 additions & 6 deletions src/muncher/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const compendiumLookup = [
{ type: "spell", name: "entity-spell-compendium" },
{ type: "equipment", name: "entity-item-compendium" },
{ type: "monsterfeatures", name: "entity-feature-compendium" },
{ type: "table", compendium: "entity-table-compendium" },
{ type: "tables", compendium: "entity-table-compendium" },
];

const srdCompendiumLookup = [
Expand Down Expand Up @@ -347,16 +349,26 @@ async function updateCompendiumItems(compendium, compendiumItems, index, matchFl
return Promise.all(promises);
}

async function createCompendiumItems(compendium, compendiumItems, index, matchFlags) {
async function createCompendiumItems(type, compendium, compendiumItems, index, matchFlags) {
let promises = [];
compendiumItems.forEach(async (item) => {
const existingItems = await getFilteredItems(compendium, item, index, matchFlags);
// we have a single match
if (existingItems.length === 0) {
const newItem = await Item.create(item, {
temporary: true,
displaySheet: false,
});
let newItem;
switch (type) {
case "table":
case "tables": {
newItem = new RollTable(item);
break;
}
default: {
newItem = await Item.create(item, {
temporary: true,
displaySheet: false,
});
}
}
munchNote(`Creating ${item.name}`);
promises.push(compendium.importDocument(newItem));
}
Expand All @@ -382,7 +394,7 @@ export async function updateCompendium(type, input, updateExisting = false, matc
}

// create new items
const createResults = await createCompendiumItems(compendium, compendiumItems, initialIndex, matchFlags);
const createResults = await createCompendiumItems(type, compendium, compendiumItems, initialIndex, matchFlags);

return createResults.concat(updateResults);
}
Expand Down
Loading

0 comments on commit 03ccbf5

Please sign in to comment.