Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V12 tentative support #17

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"compatibility": {
"minimum": 10,
"verified": 11,
"maximum": 11
"maximum": 12
},
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function setActorItemToGroupAttack(item, isGroupAttack = false) {
* @returns {boolean}
*/
export function isItemGroupAttack(item) {
return getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
return foundry.utils.getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions scripts/initiative.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function refreshInitiativeGroupGraphics(t) {
const tokenDocument = t?.document ?? t;
const tokenObject = t?.object ?? t;

const minionTurn = foundry.utils.deepClone(getProperty(tokenDocument, CONSTANTS.FLAGS.GROUP_NUMBER));
const minionTurn = foundry.utils.deepClone(foundry.utils.getProperty(tokenDocument, CONSTANTS.FLAGS.GROUP_NUMBER));
const existingSprite = tokenObject.children.find(graphic => graphic.minionGroupCircle);

if (existingSprite && !minionTurn) {
Expand Down Expand Up @@ -61,11 +61,11 @@ export function initializeInitiative() {
if (!game.combats.viewed) return;
const combatUpdates = {};
for (const createdToken of tokensCreated) {
const groupNumber = getProperty(createdToken, CONSTANTS.FLAGS.GROUP_NUMBER);
const groupNumber = foundry.utils.getProperty(createdToken, CONSTANTS.FLAGS.GROUP_NUMBER);
if (!groupNumber || !game.combats.viewed) continue;
const existingCombatant = game.combats.viewed.combatants.find(combatant => getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
const existingCombatant = game.combats.viewed.combatants.find(combatant => foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
if (!existingCombatant) continue;
combatUpdates[existingCombatant.id] = combatUpdates[existingCombatant.id] ?? foundry.utils.deepClone(getProperty(existingCombatant, CONSTANTS.FLAGS.COMBATANTS) ?? []);
combatUpdates[existingCombatant.id] = combatUpdates[existingCombatant.id] ?? foundry.utils.deepClone(foundry.utils.getProperty(existingCombatant, CONSTANTS.FLAGS.COMBATANTS) ?? []);
combatUpdates[existingCombatant.id].push(createdToken.uuid);
}
await game.combats.viewed.updateEmbeddedDocuments("Combatant", Object.entries(combatUpdates).map(([_id, uuids]) => ({
Expand All @@ -81,7 +81,7 @@ export function initializeInitiative() {

Hooks.on("deleteCombatant", async (combatant) => {
const tokenUpdates = [];
for (const subCombatantUuid of (getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS) ?? [])) {
for (const subCombatantUuid of (foundry.utils.getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS) ?? [])) {
const combatantToken = fromUuidSync(subCombatantUuid);
if (!combatantToken) continue;
tokenUpdates.push({
Expand All @@ -100,25 +100,25 @@ export function initializeInitiative() {

Hooks.on("preCreateCombatant", (doc) => {
const createdCombatantToken = doc.token;
const groupNumber = getProperty(createdCombatantToken, CONSTANTS.FLAGS.GROUP_NUMBER);
const groupNumber = foundry.utils.getProperty(createdCombatantToken, CONSTANTS.FLAGS.GROUP_NUMBER);
if (!groupNumber || !game.combats.viewed) return true;
return !game.combats.viewed.combatants.some(combatant => getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
return !game.combats.viewed.combatants.some(combatant => foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
})

let tokenBeingDeleted = false;
Hooks.on("preDeleteToken", (doc) => {
const groupNumber = getProperty(doc, CONSTANTS.FLAGS.GROUP_NUMBER);
const groupNumber = foundry.utils.getProperty(doc, CONSTANTS.FLAGS.GROUP_NUMBER);
if (!groupNumber || !game.combats.viewed) return true;
const tokenCombatant = game.combats.viewed.combatants.find(combatant => getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
const tokenCombatant = game.combats.viewed.combatants.find(combatant => foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
if(!tokenCombatant) return true;
tokenBeingDeleted = doc.id;
});

Hooks.on("deleteToken", async (doc) => {
if(doc.id !== tokenBeingDeleted) return;
const groupNumber = getProperty(doc, CONSTANTS.FLAGS.GROUP_NUMBER);
const tokenCombatant = game.combats.viewed.combatants.find(combatant => getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
const subCombatants = foundry.utils.deepClone(getProperty(tokenCombatant, CONSTANTS.FLAGS.COMBATANTS) ?? [])
const groupNumber = foundry.utils.getProperty(doc, CONSTANTS.FLAGS.GROUP_NUMBER);
const tokenCombatant = game.combats.viewed.combatants.find(combatant => foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
const subCombatants = foundry.utils.deepClone(foundry.utils.getProperty(tokenCombatant, CONSTANTS.FLAGS.COMBATANTS) ?? [])
subCombatants.splice(subCombatants.indexOf(doc.uuid), 1);
await tokenCombatant.update({
[CONSTANTS.FLAGS.COMBATANTS]: subCombatants
Expand All @@ -128,7 +128,7 @@ export function initializeInitiative() {

Hooks.on("preDeleteCombatant", (combatant) => {
if (tokenBeingDeleted !== combatant.tokenId) return true;
const existingSubCombatants = foundry.utils.deepClone(getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS));
const existingSubCombatants = foundry.utils.deepClone(foundry.utils.getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS));
if (!existingSubCombatants?.length) return true;
const newToken = existingSubCombatants.map(uuid => fromUuidSync(uuid)).filter(foundToken => foundToken?.actor?.id);
if (!newToken.length) return true;
Expand Down
20 changes: 10 additions & 10 deletions scripts/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function initializeInterface() {
app.element.find(".combatant").each(function () {
const combatant = game.combats.viewed ? game.combats.viewed.combatants.get($(this).data("combatantId")) : null;
if (!combatant) return;
const minionGroup = foundry.utils.deepClone(getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER));
const minionGroup = foundry.utils.deepClone(foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER));
if (!minionGroup) return;
const tokenImageDiv = $("<div class='token-image'></div>");
tokenImageDiv.append($(this).find(".token-image"));
Expand All @@ -24,7 +24,7 @@ export function initializeInterface() {
event.stopPropagation();
const isOn = !combatant.isDefeated;
const status = CONFIG.statusEffects.find(e => e.id === CONFIG.specialStatusEffects.DEFEATED);
for (const uuid of foundry.utils.deepClone(getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS)) ?? []) {
for (const uuid of foundry.utils.deepClone(foundry.utils.getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS)) ?? []) {
const combatantToken = fromUuidSync(uuid);
if (!combatantToken || combatantToken === combatant.token) continue;
combatantToken.toggleActiveEffect(status, { overlay: true, active: isOn });
Expand All @@ -47,22 +47,22 @@ export function initializeInterface() {
const newGroupNumber = Number(index) + 1;

const groupAlreadyExists = game.combats.viewed ? game.combats.viewed.combatants.some(combatant => {
return getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === newGroupNumber;
return foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === newGroupNumber;
}) : false;

const colorBox = $(`<div class="minion-group ${groupAlreadyExists ? 'minion-group-used' : ''}" style='background-image: url(modules/${CONSTANTS.MODULE_NAME}/assets/${newGroupNumber}.svg);'></div>`);

colorBox.on("click", async () => {

const existingGroupNumber = getProperty(clickedTokenDocument, CONSTANTS.FLAGS.GROUP_NUMBER);
const existingGroupNumber = foundry.utils.getProperty(clickedTokenDocument, CONSTANTS.FLAGS.GROUP_NUMBER);
const newTokens = canvas.tokens.controlled.map(t => t.document);
const tokensKeptInOldGroup = canvas.scene.tokens.filter(oldToken => {
const tokenGroupNumber = getProperty(oldToken, CONSTANTS.FLAGS.GROUP_NUMBER);
const tokenGroupNumber = foundry.utils.getProperty(oldToken, CONSTANTS.FLAGS.GROUP_NUMBER);
return !newTokens.includes(oldToken) && existingGroupNumber && tokenGroupNumber && existingGroupNumber === tokenGroupNumber;
});

const existingCombatantGroup = game.combats.viewed ? game.combats.viewed.combatants.find(combatant => {
return existingGroupNumber && getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === existingGroupNumber;
return existingGroupNumber && foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === existingGroupNumber;
}) : false;

if (existingCombatantGroup && !tokensKeptInOldGroup.length) {
Expand Down Expand Up @@ -94,11 +94,11 @@ export function initializeInterface() {
}

const existingCombatantInNewGroup = game.combats.viewed.combatants.find(combatant => {
return getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === newGroupNumber;
return foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === newGroupNumber;
})

if (existingCombatantInNewGroup) {
const existingUuids = foundry.utils.deepClone(getProperty(existingCombatantInNewGroup, CONSTANTS.FLAGS.COMBATANTS) ?? []);
const existingUuids = foundry.utils.deepClone(foundry.utils.getProperty(existingCombatantInNewGroup, CONSTANTS.FLAGS.COMBATANTS) ?? []);
const newUuids = newTokens.map(selectedToken => {
return `Scene.${selectedToken.parent.id}.Token.${selectedToken.id}`;
});
Expand Down Expand Up @@ -134,7 +134,7 @@ export function initializeInterface() {
for (const turn of data.turns) {
const combatant = game.combats.viewed ? game.combats.viewed.combatants.get(turn.id) : false;
if (!combatant) continue;
const subCombatants = foundry.utils.deepClone(getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS) ?? [])
const subCombatants = foundry.utils.deepClone(foundry.utils.getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS) ?? [])
if (!subCombatants.length) continue;
const documents = subCombatants.map((uuid) => fromUuidSync(uuid)).filter(Boolean);
turn.defeated = documents.every(subTokenDocument => {
Expand All @@ -153,7 +153,7 @@ export function initializeInterface() {

Hooks.on("preUpdateCombatant", (combatant, data) => {
if (overrideDefeatedClick) return;
const existingSubCombatants = foundry.utils.deepClone(getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS));
const existingSubCombatants = foundry.utils.deepClone(foundry.utils.getProperty(combatant, CONSTANTS.FLAGS.COMBATANTS));
if (!existingSubCombatants?.length) return;
if (data.defeated) return false;
});
Expand Down
20 changes: 10 additions & 10 deletions scripts/minion.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ export function initializeMinions() {

Hooks.on("preUpdateActor", (doc, change) => {
const actorIsMinion = api.isMinion(doc);
if (!actorIsMinion || !hasProperty(change, "system.attributes.hp.value")) return true;
if (getProperty(change, "system.attributes.hp.value") < getProperty(doc, "system.attributes.hp.value")) {
if (!actorIsMinion || !foundry.utils.hasProperty(change, "system.attributes.hp.value")) return true;
if (foundry.utils.getProperty(change, "system.attributes.hp.value") < foundry.utils.getProperty(doc, "system.attributes.hp.value")) {
change["system.attributes.hp.value"] = 0;
}
return true;
});

Hooks.on("updateActor", (doc) => {
const actorIsMinion = api.isMinion(doc);
if (!doc.token || !actorIsMinion || getProperty(doc, "system.attributes.hp.value") > 0) return true;
const groupNumber = getProperty(doc.token, CONSTANTS.FLAGS.GROUP_NUMBER);
if (!doc.token || !actorIsMinion || foundry.utils.getProperty(doc, "system.attributes.hp.value") > 0) return true;
const groupNumber = foundry.utils.getProperty(doc.token, CONSTANTS.FLAGS.GROUP_NUMBER);
if (!groupNumber || !game.combats.viewed) return true;
const existingCombatant = game.combats.viewed.combatants.find(combatant => getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
const existingCombatant = game.combats.viewed.combatants.find(combatant => foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
if (!existingCombatant) return true;
const existingSubCombatants = foundry.utils.deepClone(getProperty(existingCombatant, CONSTANTS.FLAGS.COMBATANTS));
const existingSubCombatants = foundry.utils.deepClone(foundry.utils.getProperty(existingCombatant, CONSTANTS.FLAGS.COMBATANTS));
if (!existingSubCombatants?.length) return true;
const newToken = existingSubCombatants.map(uuid => fromUuidSync(uuid)).filter(foundToken => {
return foundToken?.actor?.id && getProperty(foundToken?.actor, "system.attributes.hp.value") > 0;
return foundToken?.actor?.id && foundry.utils.getProperty(foundToken?.actor, "system.attributes.hp.value") > 0;
});
if (!newToken.length) return true;
existingCombatant.update({
Expand All @@ -45,13 +45,13 @@ export function initializeMinions() {
const actorIsMinion = api.isMinion(doc);
if(!actorIsMinion) return;

const groupNumber = getProperty(doc.token, CONSTANTS.FLAGS.GROUP_NUMBER);
const groupNumber = foundry.utils.getProperty(doc.token, CONSTANTS.FLAGS.GROUP_NUMBER);
if (!groupNumber) return;

const existingCombatant = game.combats.viewed.combatants.find(combatant => getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
const existingCombatant = game.combats.viewed.combatants.find(combatant => foundry.utils.getProperty(combatant.token, CONSTANTS.FLAGS.GROUP_NUMBER) === groupNumber);
if (!existingCombatant) return;

const subCombatants = foundry.utils.deepClone(getProperty(existingCombatant, CONSTANTS.FLAGS.COMBATANTS) ?? [])
const subCombatants = foundry.utils.deepClone(foundry.utils.getProperty(existingCombatant, CONSTANTS.FLAGS.COMBATANTS) ?? [])
if (!subCombatants.length) return;

const documents = subCombatants.map((uuid) => fromUuidSync(uuid)).filter(Boolean);
Expand Down
12 changes: 6 additions & 6 deletions scripts/plugins/midiqol.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {

if (!lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACKS)) return true;

const isGroupAttack = getProperty(workflow.item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
const isGroupAttack = foundry.utils.getProperty(workflow.item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;

if (!workflow?.actor || !api.isMinion(workflow?.actor) || !isGroupAttack) return true;

Expand All @@ -37,7 +37,7 @@ export default {
if (rolledItem !== workflow.item) return true;
rollConfig.data.numberOfMinions = numberOfMinions;
const containsNumberOfMinions = rollConfig.parts.some(part => part[0].includes(CONSTANTS.NUMBER_MINIONS_BONUS))
if(!containsNumberOfMinions) rollConfig.parts.push(numberOfMinions > 1 ? CONSTANTS.NUMBER_MINIONS_BONUS : '');
if(!containsNumberOfMinions && numberOfMinions > 1) rollConfig.parts.push( CONSTANTS.NUMBER_MINIONS_BONUS);
Hooks.off("dnd5e.preRollAttack", attackHookId);
return true;
});
Expand All @@ -51,7 +51,7 @@ export default {

if (!lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACKS)) return true;

const isGroupAttack = getProperty(workflow.item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
const isGroupAttack = foundry.utils.getProperty(workflow.item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;

if (!api.isMinion(workflow.actor) || !isGroupAttack) return true;

Expand Down Expand Up @@ -92,9 +92,9 @@ export default {
Hooks.on("midi-qol.preCheckSaves", async (workflow) => {
if (!lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACKS)) return true;

const isGroupAttack = getProperty(workflow.item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
const isGroupAttack = foundry.utils.getProperty(workflow.item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;

const isScaleDC = getProperty(workflow.item, CONSTANTS.FLAGS.DC_SCALING_ENABLED) ?? false;
const isScaleDC = foundry.utils.getProperty(workflow.item, CONSTANTS.FLAGS.DC_SCALING_ENABLED) ?? false;

if (!workflow.actor || !api.isMinion(workflow?.actor) || !isGroupAttack || !isScaleDC) return true;

Expand Down Expand Up @@ -144,7 +144,7 @@ export default {

let damageTotal = workflow.damageTotal;

const minionHP = getProperty(hitTarget?.actor, "system.attributes.hp.value");
const minionHP = foundry.utils.getProperty(hitTarget?.actor, "system.attributes.hp.value");

if ((minionHP - damageTotal) > 0) return true;

Expand Down
10 changes: 5 additions & 5 deletions scripts/plugins/vanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {

if (!lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACKS)) return true;

const isGroupAttack = getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
const isGroupAttack = foundry.utils.getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;

if (!api.isMinion(item.parent) || !isGroupAttack) return true;

Expand Down Expand Up @@ -71,7 +71,7 @@ export default {

if (item.system?.damage?.parts?.length < 1) return true;
if (!lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACKS)) return true;
const isGroupAttack = getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
const isGroupAttack = foundry.utils.getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
if (!api.isMinion(item.parent) || !isGroupAttack) return true;

if (minionAttacks?.[item.parent.uuid] && minionAttacks?.[item.parent.uuid].attacked) {
Expand Down Expand Up @@ -116,9 +116,9 @@ export default {
Hooks.on("dnd5e.preUseItem", (item, config, options) => {
if (!lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACKS)) return true;

const isGroupAttack = getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
const isGroupAttack = foundry.utils.getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;

const isScaleDC = getProperty(item, CONSTANTS.FLAGS.DC_SCALING_ENABLED) ?? false;
const isScaleDC = foundry.utils.getProperty(item, CONSTANTS.FLAGS.DC_SCALING_ENABLED) ?? false;

if (!api.isMinion(item.parent) || !isGroupAttack || !isScaleDC) return true;

Expand Down Expand Up @@ -176,7 +176,7 @@ export default {

let damageTotal = damageRoll.total;

const minionHP = getProperty(hitTarget.actor, "system.attributes.hp.value");
const minionHP = foundry.utils.getProperty(hitTarget.actor, "system.attributes.hp.value");

if ((minionHP - damageTotal) > 0) return true;

Expand Down
6 changes: 3 additions & 3 deletions scripts/sheet-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ function patchTidyGroupAttack(element, item) {
}

function patchDCScaling(html, item) {
if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_DC_BONUS) && getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK)) {
if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_DC_BONUS) && foundry.utils.getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK)) {
let targetElem = html.find('[name="system.save.ability"]')?.parent()?.parent()?.[0];
if (!targetElem) return;
$(getDCScalingHtml(item)).insertAfter(targetElem);
}
}

function patchTidyDCScaling(element, item) {
if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_DC_BONUS) && getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK)) {
if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_DC_BONUS) && foundry.utils.getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK)) {
const html = $(element);
const markupToInject = `
<div style="display: contents;" data-tidy-render-scheme="handlebars">
Expand Down Expand Up @@ -109,4 +109,4 @@ function getDCScalingHtml(item) {
</div>
</div>
`;
}
}