From 74aaa75f812fc7eaea74da598cf9a46c57f43c2f Mon Sep 17 00:00:00 2001 From: Cody Swendrowski Date: Sat, 24 Apr 2021 16:38:33 -0500 Subject: [PATCH] Add Hazard PF2e integration. Add performance options. --- scripts/module.js | 24 ++++++++- scripts/pf2e.mjs | 81 +++++++++++++++++++++++-------- scripts/thirteenth-age.mjs | 8 +++ templates/compendium-settings.hbs | 11 +++++ vue/EncounterBuilder.vue | 19 ++++++-- 5 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 templates/compendium-settings.hbs diff --git a/scripts/module.js b/scripts/module.js index 1f437a2..67476a1 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -1,5 +1,7 @@ import ThirteenthAge from "./thirteenth-age.mjs"; import Pathfinder2E from "./pf2e.mjs"; +import DnD5e from "./dnd5e.mjs"; +import {CompendiumSettingsForm} from "./CompendiumSettingsForm.js"; class EncounterBuilder { static init() { @@ -90,9 +92,29 @@ Hooks.once('ready', function() { default: "worldName" }); + game.settings.registerMenu(moduleName, 'compendiumSettingsMenu', { + name: "Loaded Compendiums", + label: "Which compendiums to load from", + icon: "fas fa-book", + type: CompendiumSettingsForm, + restricted: true + }); + + game.packs.filter((x) => x.metadata.entity == "Actor" && !x.metadata.name.includes("baileywiki")) + .forEach(pack => { + game.settings.register("vue-encounter-builder", pack.metadata.name, { + scope: 'world', + config: false, + type: Boolean, + default: true + }); + }); + + window.dungeonMoon = { thirteenthAge: new ThirteenthAge(), - pathfinder2E: new Pathfinder2E() + pathfinder2E: new Pathfinder2E(), + dnd5e: new DnD5e() }; }); diff --git a/scripts/pf2e.mjs b/scripts/pf2e.mjs index 71e8e87..27c8d10 100644 --- a/scripts/pf2e.mjs +++ b/scripts/pf2e.mjs @@ -1,12 +1,20 @@ export default class Pathfinder2E { + histogramStep() { return 1; } + + histogramLabelPrettify(level) { return level; } + getPlayerCharacters() { return game.actors.entities.filter((x) => x.hasPlayerOwner && x.data.type == "character"); } getNpcs() { - return game.actors.entities.filter((x) => x.data.type == "npc"); + return game.actors.entities.filter((x) => x.data.type == "npc" || x.data.type == "hazard"); + } + + filterCompendiumActors(pack, packActors) { + return packActors; } filterAvailableActors(availableActors, filters) { @@ -89,22 +97,56 @@ export default class Pathfinder2E { if (actor == undefined) return -30; //console.log(actor); try { - let xpChart = [ - 10, - 15, - 20, - 30, - 40, // Same level - 60, - 80, - 120, - 160 - ]; - - let levelDifference = this.getSafeLevel(actor) - partyInfo.averagePartyLevel; - let xpIndex = levelDifference + 4; - - return xpChart[xpIndex]; + if (actor.data.type == "hazard") { + let simpleChart = [ + 2, + 3, + 4, + 6, + 8, // Same level + 12, + 16, + 24, + 30 + ]; + + let complexChart = [ + 10, + 15, + 20, + 30, + 40, // Same level + 60, + 80, + 120, + 150 + ]; + + let xpChart = actor.data.data.details.isComplex ? complexChart : simpleChart; + + let levelDifference = this.getSafeLevel(actor) - partyInfo.averagePartyLevel; + let xpIndex = levelDifference + 4; + + return xpChart[xpIndex]; + } + else { + let xpChart = [ + 10, + 15, + 20, + 30, + 40, // Same level + 60, + 80, + 120, + 160 + ]; + + let levelDifference = this.getSafeLevel(actor) - partyInfo.averagePartyLevel; + let xpIndex = levelDifference + 4; + + return xpChart[xpIndex]; + } } catch (error) { console.error(error); @@ -113,8 +155,9 @@ export default class Pathfinder2E { } getSafeLevel(actor) { - if (actor.data.data != undefined && actor.data.data.details != undefined && actor.data.data.details.level != undefined) { - return actor.data.data.details.level.value; + if (actor?.data?.data?.details?.level) { + if (actor.data.data.details.level?.value) return actor.data.data.details.level.value; + return actor.data.data.details.level; } return 0; } diff --git a/scripts/thirteenth-age.mjs b/scripts/thirteenth-age.mjs index ac9c3ea..5f28bfa 100644 --- a/scripts/thirteenth-age.mjs +++ b/scripts/thirteenth-age.mjs @@ -1,6 +1,10 @@ export default class ThirteenthAge { + histogramStep() { return 1; } + + histogramLabelPrettify(level) { return level; } + getPlayerCharacters() { return game.actors.entities.filter((x) => x.hasPlayerOwner && x.data.type == "character"); } @@ -9,6 +13,10 @@ export default class ThirteenthAge { return game.actors.entities.filter((x) => x.data.type == "npc"); } + filterCompendiumActors(pack, packActors) { + return packActors; + } + filterAvailableActors(availableActors, filters) { if (filters.selectedSources.length > 0) { availableActors = availableActors.filter(x => filters.selectedSources.includes(this.getActorSource(x).toLowerCase())); diff --git a/templates/compendium-settings.hbs b/templates/compendium-settings.hbs new file mode 100644 index 0000000..0d7f017 --- /dev/null +++ b/templates/compendium-settings.hbs @@ -0,0 +1,11 @@ +
+
+ {{#each compendiums}} + +
+ {{/each}} +
+ +
diff --git a/vue/EncounterBuilder.vue b/vue/EncounterBuilder.vue index 30f540c..3df04e5 100644 --- a/vue/EncounterBuilder.vue +++ b/vue/EncounterBuilder.vue @@ -113,8 +113,10 @@ 0) { let toPush = duplicate(actor); @@ -391,6 +397,8 @@ export default { }, async mounted() { + this.step = this.system.histogramStep(); + //console.log("Mounted!"); let characters = this.system.getPlayerCharacters(); //console.log(characters); @@ -410,15 +418,16 @@ export default { let allActors = npcs; this.sources.push(game.world.title); let actorCompendiums = game.packs.filter( - (x) => x.metadata.entity == "Actor" + (x) => x.metadata.entity == "Actor" && !x.metadata.name.includes("baileywiki") ); for (let index = 0; index < actorCompendiums.length; index++) { let pack = actorCompendiums[index]; + if (!game.settings.get("vue-encounter-builder", pack.metadata.name)) continue; //console.log(pack); - var packActors = await pack.getContent(); + let packActors = await pack.getContent(); //console.log(packActors); - allActors = allActors.concat(packActors); + allActors = allActors.concat(this.system.filterCompendiumActors(pack, packActors)); this.sources.push(pack.metadata.label); }