Skip to content

Commit

Permalink
Add Hazard PF2e integration. Add performance options.
Browse files Browse the repository at this point in the history
  • Loading branch information
cswendrowski committed Apr 24, 2021
1 parent 9981849 commit 74aaa75
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 25 deletions.
24 changes: 23 additions & 1 deletion scripts/module.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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()
};
});

Expand Down
81 changes: 62 additions & 19 deletions scripts/pf2e.mjs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions scripts/thirteenth-age.mjs
Original file line number Diff line number Diff line change
@@ -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");
}
Expand All @@ -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()));
Expand Down
11 changes: 11 additions & 0 deletions templates/compendium-settings.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<form autocomplete="off" class="customCssSettings" onsubmit="event.preventDefault()">
<section class="stylesheet-editor">
{{#each compendiums}}
<input type="checkbox" id="{{this.name}}" name="{{this.name}}" {{checked this.value}} data-dtype="Boolean">
<label for="{{this.name}}">{{this.label}}</label><br>
{{/each}}
</section>
<button type="submit" name="submit">
<i class="fas fa-save"></i> Save
</button>
</form>
19 changes: 14 additions & 5 deletions vue/EncounterBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@
<histogramslider
ref="levelHistogram"
:data="levelData"
:min="0"
:max="15"
:min="minimumLevel"
:max="maximumLevel"
:step="step"
:prettify="prettify"
:primary-color="colors.primary"
:holder-color="colors.holder"
:handle-color="colors.handle"
Expand Down Expand Up @@ -177,6 +179,7 @@ export default {
numberOfPartyMembers: 4,
},
step: 1,
minimumLevel: 100,
maximumLevel: 0,
minSelectedLevel: 0,
Expand All @@ -189,6 +192,9 @@ export default {
sortNameAsc: undefined,
}),
methods: {
prettify: function(level) {
return this.system.histogramLabelPrettify(level);
},
addActor: function (actor) {
if (actor.encounterScore > 0) {
let toPush = duplicate(actor);
Expand Down Expand Up @@ -391,6 +397,8 @@ export default {
},
async mounted() {
this.step = this.system.histogramStep();
//console.log("Mounted!");
let characters = this.system.getPlayerCharacters();
//console.log(characters);
Expand All @@ -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);
}
Expand Down

0 comments on commit 74aaa75

Please sign in to comment.