Skip to content

Commit

Permalink
Update module to work with Foundry 8.6
Browse files Browse the repository at this point in the history
Module is now updated to work with Foundry v8.6.

[#10] Added support for new swarm creature type details.
[#11] Items are now loaded correctly from actors.
Added ammo damage (when relevant) to the item attack description.
Updated height of blueprint to account for smaller footer.
  • Loading branch information
giffyglyph committed Jun 1, 2021
1 parent 50fee30 commit 9093dca
Show file tree
Hide file tree
Showing 16 changed files with 412 additions and 353 deletions.
4 changes: 2 additions & 2 deletions gmm.css
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,7 @@
transition: width 100ms ease-in-out, height 100ms ease-in-out;
width: 0;
top: 0;
height: calc(100% - 2.75rem);
height: calc(100% - 2.25rem);
padding: 0; }
.gmm-forge.layout--slide-in-left .forge__blueprint .blueprint__form, .gmm-forge.layout--slide-in-right .forge__blueprint .blueprint__form {
max-width: 420px;
Expand Down Expand Up @@ -2421,7 +2421,7 @@
position: absolute;
right: 0;
top: 0;
height: calc(100% - 2.75rem);
height: calc(100% - 2.25rem);
background: black;
padding: 0.25rem;
border-radius: 0 1.2rem 1.2rem 0;
Expand Down
50 changes: 34 additions & 16 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,21 +414,36 @@
"gmm.common.time_period.spec": "Special",
"gmm.common.time_period.turn": "Turn",
"gmm.common.time_period.year": "Year",
"gmm.common.type.aberration": "Aberration",
"gmm.common.type.beast": "Beast",
"gmm.common.type.celestial": "Celestial",
"gmm.common.type.construct": "Construct",
"gmm.common.type.custom": "Custom",
"gmm.common.type.dragon": "Dragon",
"gmm.common.type.elemental": "Elemental",
"gmm.common.type.fey": "Fey",
"gmm.common.type.fiend": "Fiend",
"gmm.common.type.giant": "Giant",
"gmm.common.type.humanoid": "Humanoid",
"gmm.common.type.monstrosity": "Monstrosity",
"gmm.common.type.ooze": "Ooze",
"gmm.common.type.plant": "Plant",
"gmm.common.type.undead": "Undead",
"gmm.common.category.single.aberration": "Aberration",
"gmm.common.category.single.beast": "Beast",
"gmm.common.category.single.celestial": "Celestial",
"gmm.common.category.single.construct": "Construct",
"gmm.common.category.single.custom": "Custom",
"gmm.common.category.single.dragon": "Dragon",
"gmm.common.category.single.elemental": "Elemental",
"gmm.common.category.single.fey": "Fey",
"gmm.common.category.single.fiend": "Fiend",
"gmm.common.category.single.giant": "Giant",
"gmm.common.category.single.humanoid": "Humanoid",
"gmm.common.category.single.monstrosity": "Monstrosity",
"gmm.common.category.single.ooze": "Ooze",
"gmm.common.category.single.plant": "Plant",
"gmm.common.category.single.undead": "Undead",
"gmm.common.category.multiple.aberration": "Aberrations",
"gmm.common.category.multiple.beast": "Beasts",
"gmm.common.category.multiple.celestial": "Celestials",
"gmm.common.category.multiple.construct": "Constructs",
"gmm.common.category.multiple.custom": "Custom",
"gmm.common.category.multiple.dragon": "Dragons",
"gmm.common.category.multiple.elemental": "Elementals",
"gmm.common.category.multiple.fey": "Fey",
"gmm.common.category.multiple.fiend": "Fiends",
"gmm.common.category.multiple.giant": "Giants",
"gmm.common.category.multiple.humanoid": "Humanoids",
"gmm.common.category.multiple.monstrosity": "Monstrosities",
"gmm.common.category.multiple.ooze": "Oozes",
"gmm.common.category.multiple.plant": "Plants",
"gmm.common.category.multiple.undead": "Undead",
"gmm.common.use_period.charges": "Charges",
"gmm.common.use_period.day": "Day",
"gmm.common.use_period.lr": "Long Rest",
Expand Down Expand Up @@ -562,6 +577,7 @@
"gmm.monster.artifact.inventory.items.uses": "Uses",
"gmm.monster.artifact.inventory.title": "Inventory",
"gmm.monster.artifact.inventory.weight": "Weight",
"gmm.monster.artifact.description.swarm": "swarm of {size} {category}",
"gmm.monster.artifact.lair_actions.activation": "Activation",
"gmm.monster.artifact.lair_actions.add": "Add",
"gmm.monster.artifact.lair_actions.blurb": "On initiative count {initiative} (losing initiative ties), you can take one of the lair actions listed below. You can't take the same lair action two rounds in a row.",
Expand Down Expand Up @@ -705,7 +721,9 @@
"gmm.monster.blueprint.description.size": "Size",
"gmm.monster.blueprint.description.tags": "Tags",
"gmm.monster.blueprint.description.title": "Description",
"gmm.monster.blueprint.description.type": "Type",
"gmm.monster.blueprint.description.type": "Creature Type",
"gmm.monster.blueprint.description.category": "Category",
"gmm.monster.blueprint.description.swarm": "Swarm Size",
"gmm.monster.blueprint.display.colors.primary": "Primary",
"gmm.monster.blueprint.display.colors.secondary": "Secondary",
"gmm.monster.blueprint.display.colors.title": "Colors",
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"type": "system"
}
],
"minimumCoreVersion": "0.7.6",
"compatibleCoreVersion": "0.7.9",
"minimumCoreVersion": "0.8.6",
"compatibleCoreVersion": "0.8.6",
"url": "https://patreon.com/giffyglyph",
"manifest": "https://raw.githubusercontent.com/giffyglyph/foundry_5e_monster_maker/dev/module.json",
"download": "https://github.com/giffyglyph/foundry_5e_monster_maker/archive/refs/tags/v0.5.2-dev.zip"
Expand Down
39 changes: 19 additions & 20 deletions scripts/classes/ActionSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export default class ActionSheet extends ItemSheet {
const data = super.getData();

data.gmm = {
blueprint: data.item.data.gmm?.blueprint ? data.item.data.gmm.blueprint.data : null,
action: data.item.data.gmm?.blueprint ? ActionForge.createArtifact(data.item.data.gmm.blueprint).data : null,
blueprint: data.item.data.data.gmm?.blueprint ? data.item.data.data.gmm.blueprint.data : null,
action: data.item.data.data.gmm?.blueprint ? ActionForge.createArtifact(data.item.data.data.gmm.blueprint).data : null,
gui: this._gui,
enums: {
colors: GMM_GUI_COLORS,
Expand All @@ -98,11 +98,12 @@ export default class ActionSheet extends ItemSheet {
if (data.gmm.action) {
data.gmm.action.gmmLabels = this.item.getGmmLabels();
}

return data;
}

_getActionConsumptionTargets(item) {
const consume = item.data.consume || {};
const consume = item.data.data.consume || {};
if ( !consume.type ) {
return [];
}
Expand All @@ -118,22 +119,22 @@ export default class ActionSheet extends ItemSheet {
ammo[i.id] = `${i.name} (${i.data.data.quantity})`;
}
return ammo;
}, {[item._id]: `${item.name} (${item.data.quantity})`});
}, {[item.id]: `${item.name} (${item.data.data.quantity})`});
} else if ( consume.type === "attribute" ) {
const attributes = Object.values(CombatTrackerConfig.prototype.getAttributeChoices())[0]; // Bit of a hack
return attributes.reduce((obj, a) => {
obj[a] = a;
return obj;
}, {});
} else if ( consume.type === "material" ) {
return actor.items.reduce((obj, i) => {
return actor.items.contents.reduce((obj, i) => {
if ( ["consumable", "loot"].includes(i.data.type) && !i.data.data.activation ) {
obj[i.id] = `${i.name} (${i.data.data.quantity})`;
}
return obj;
}, {});
} else if ( consume.type === "charges" ) {
return actor.items.reduce((obj, i) => {
return actor.items.contents.reduce((obj, i) => {
const uses = i.data.data.uses || {};
if ( uses.per && uses.max ) {
const label = uses.per === "charges" ?
Expand All @@ -159,20 +160,18 @@ export default class ActionSheet extends ItemSheet {
this._gui.updateFrom(event.currentTarget.closest(".gmm-window"));
}

let formData = {
data: {
gmm: {
blueprint: {
vid: 1,
type: "action",
data: expandObject(form).gmm.blueprint
}
}
}
};

$.extend(true, formData, ActionBlueprint.getItemDataFromBlueprint(formData.data.gmm.blueprint));
let formData = expandObject(form);
if (hasProperty(formData, "gmm.blueprint")) {
setProperty(formData, "data.gmm.blueprint", {
vid: 1,
type: "action",
data: getProperty(formData, "gmm.blueprint")
});
delete formData.gmm.blueprint;

$.extend(true, formData, ActionBlueprint.getItemDataFromBlueprint(formData.data.gmm.blueprint));
}

return this.entity.update(formData);
return this.document.update(formData);
}
}
2 changes: 1 addition & 1 deletion scripts/classes/GmmActor.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const GmmActor = (function () {
actorData.attributes.spelldc = monsterData.spellbook.spellcasting.dc.value;

// Compute owned item attributes which depend on prepared Actor data
actor.items.forEach((item) => {
actor.items.contents.forEach((item) => {
item.getSaveDC();
item.getAttackToHit();
item.prepareShortcodes();
Expand Down
34 changes: 24 additions & 10 deletions scripts/classes/GmmItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { simplifyRollFormula, damageRoll } from "./../../../../systems/dnd5e/module/dice.js";
import ActionBlueprint from './ActionBlueprint.js';
import Shortcoder from './Shortcoder.js';
import ActionForge from './ActionForge.js';

/**
* A patcher which controls item data based on the selected sheet.
Expand Down Expand Up @@ -85,10 +84,24 @@ const GmmItem = (function () {
let damage = simplifyRollFormula(gmmMonster ? Shortcoder.replaceShortcodes(x[0], gmmMonster) : x[0], rollData).trim();
return `${damage}${x[1] ? ` ${game.i18n.format(`gmm.common.damage.${x[1]}`).toLowerCase()}` : ``} damage`;
});
if ((itemData.consume?.type === 'ammo') && !!this.actor?.items) {
const ammoItemData = this.actor.items.get(itemData.consume.target)?.data;
if (ammoItemData) {
const ammoItemQuantity = ammoItemData.data.quantity;
const ammoCanBeConsumed = ammoItemQuantity && (ammoItemQuantity - (itemData.consume.amount ?? 0) >= 0);
const ammoIsTypeConsumable = (ammoItemData.type === "consumable") && (ammoItemData.data.consumableType === "ammo")
if ( ammoCanBeConsumed && ammoIsTypeConsumable ) {
damages.push(...ammoItemData.data.damage.parts.map(x => {
let damage = simplifyRollFormula(gmmMonster ? Shortcoder.replaceShortcodes(x[0], gmmMonster) : x[0], rollData).trim();
return `${damage}${x[1] ? ` ${game.i18n.format(`gmm.common.damage.${x[1]}`).toLowerCase()}` : ``} damage`;
}));
}
}
}
labels.damage = damages.join(" plus ");
}

switch (itemData.target.type) {
switch (itemData.target?.type) {
case "":
case "none":
switch (itemData.range.units) {
Expand Down Expand Up @@ -129,7 +142,7 @@ const GmmItem = (function () {
}
break;
default:
if (itemData.target.units) {
if (itemData.target?.units) {
if (["ft", "mi"].includes(itemData.target.units)) {
let size = game.i18n.format(`gmm.action.labels.target.size.${itemData.target.units}.single`, { x: Math.max(1, itemData.target.value) });
labels.target = game.i18n.format(`gmm.action.labels.target.${itemData.target.type}`, { size: size });
Expand All @@ -138,7 +151,7 @@ const GmmItem = (function () {
break;
}

switch (itemData.range.units) {
switch (itemData.range?.units) {
case "any":
case "self":
case "touch":
Expand All @@ -157,7 +170,7 @@ const GmmItem = (function () {
break;
}

labels.description = this.getChatData({secrets: this.actor?.owner}).description.value;
labels.description = this.getChatData({secrets: this.actor?.isOwner}).description.value;

if (this.hasLimitedUses) {
labels.uses = {
Expand Down Expand Up @@ -213,10 +226,10 @@ const GmmItem = (function () {
}

function _prepareShortcodes() {
if (this.getSheetId() == "gmm.ActionSheet" && this.isOwnedByGmmMonster()) {
let monster = this.getOwningGmmMonster();
if (this.data.data.description && this.data.data.description.value) {
this.data.data.description.value = Shortcoder.replaceShortcodes(this.data.data.description.value, monster);
if (this.getSheetId() == "gmm.ActionSheet") {
let gmmMonster = this.getOwningGmmMonster();
if (gmmMonster && this.data.data.description && this.data.data.description.value) {
this.data.data.description.value = Shortcoder.replaceShortcodes(this.data.data.description.value, gmmMonster);
}
}
}
Expand Down Expand Up @@ -351,8 +364,9 @@ const GmmItem = (function () {
const gmmActionBlueprint = item.getGmmActionBlueprint();

// Get roll data
const gmmMonster = item.getOwningGmmMonster();
const parts = itemData.damage.parts.map((x) => x[0].replace(/\[.*?\]/g, (token) => {
return Shortcoder.replaceShortcodes(token, item.actor.data.data.gmm.monster.data);
return (gmmMonster) ? Shortcoder.replaceShortcodes(token, gmmMonster) : token;
}));
const rollData = item.getRollData();

Expand Down
2 changes: 1 addition & 1 deletion scripts/classes/Gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class Gui {
});
section.classList.add("opened");
section.querySelector(".accordion-section__body").style.removeProperty("display");
section.scrollIntoView();
section.scrollIntoView({ block: 'nearest' });
this._updateAccordions(event.currentTarget.closest(".gmm-window"));
}
}
Expand Down
Loading

0 comments on commit 9093dca

Please sign in to comment.