Skip to content

Commit

Permalink
v0.3.11
Browse files Browse the repository at this point in the history
- Further steps to improve CTG compatibility
- Added setting for autosaving CTG groups as mobs
  • Loading branch information
Stendarpaval committed Sep 26, 2021
1 parent 7af70ee commit 733822f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 17 deletions.
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,7 @@
"SETTINGS.MAT.ctrlKey": "Ctrl",

"SETTINGS.MAT.noResultsMessage": "Don't send Results chat message",
"SETTINGS.MAT.noResultsMessageHint": "Enable this setting to prevent the Mob Attack Results message from being sent to the chat log at all."
"SETTINGS.MAT.noResultsMessageHint": "Enable this setting to prevent the Mob Attack Results message from being sent to the chat log at all. (Client specific setting)",
"SETTINGS.MAT.autoSaveCTGgroups": "Autosave Combat Tracker Group as mobs",
"SETTINGS.MAT.autoSaveCTGgroupsHint": "If this setting is enabled, then the initiative groupings (toggable containers) that the Combat Tracker Groups module creates will be automatically saved as mobs. These automatically saved mobs are also automatically deleted when the combat encounter ends or is deleted."
}
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"url": "https://github.com/Stendarpaval/mob-attack-tool",
"version": "0.3.10",
"version": "0.3.11",
"minimumCoreVersion": "0.8.8",
"compatibleCoreVersion": "0.8.9",
"system": ["dnd5e"],
Expand All @@ -27,5 +27,5 @@
"styles/mob-attack-tool.css"
],
"manifest": "https://raw.githubusercontent.com/Stendarpaval/mob-attack-tool/main/module.json",
"download": "https://github.com/Stendarpaval/mob-attack-tool/releases/download/0.3.10/module.zip"
"download": "https://github.com/Stendarpaval/mob-attack-tool/releases/download/0.3.11/module.zip"
}
34 changes: 31 additions & 3 deletions scripts/mobAttack.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@ Hooks.once("init", () => {

Hooks.on("ready", async () => {
window.MobAttacks = MobAttacks();

// check if CTG's groups have changed
Hooks.on("groupUpdate", async (args) => {
if (!game.settings.get(moduleName, "autoSaveCTGgroups")) return;
if (args.groups[0]) {
if (args.groups[0].filter(c => c.initiative).length > 0) {
await MobAttacks().createSavedMobsFromCTGgroups(args.groups);
const dialogId = game.settings.get(moduleName, "currentDialogId");
let mobDialog = game.mobAttackTool.dialogs.get(dialogId);
if (mobDialog) mobDialog.render();
}
}
});

Hooks.on("deleteCombat", async () => {
if (!game.settings.get(moduleName, "autoSaveCTGgroups")) return;
if (game.modules.get("ctg")?.active) {
let mobList = game.settings.get(moduleName, "hiddenMobList");

// delete existing CTG groups
for (let ctgMobName of Object.keys(mobList)) {
if (mobList[ctgMobName]?.type === "ctg") {
await MobAttacks().deleteSavedMob(ctgMobName);
}
}
}
})
})

// update dialog windows if new tokens are selected
Expand Down Expand Up @@ -81,6 +108,7 @@ Hooks.on("updateCombat", async (combat, changed) => {
}
}
if (nextMobName === "") return;

const dialogId = game.settings.get(moduleName, "currentDialogId");
let mobDialog = game.mobAttackTool.dialogs.get(dialogId);

Expand All @@ -99,6 +127,7 @@ Hooks.on("updateCombat", async (combat, changed) => {
if (mobDialog) {
mobDialog.numSelected = canvas.tokens.controlled.length;
mobDialog.currentlySelectingTokens = false;
mobDialog.render();
}
})

Expand All @@ -111,7 +140,7 @@ Hooks.on('diceSoNiceRollStart', (messageId, context) => {
});

// group initiative: override roll methods from combat tracker
Hooks.on("renderCombatTracker", ( app, html, options ) => {
Hooks.on("renderCombatTracker", async ( app, html, options ) => {
let combat = options.combat;
if (!combat) return;

Expand All @@ -125,8 +154,7 @@ Hooks.on("renderCombatTracker", ( app, html, options ) => {
if (game.settings.get(moduleName, "enableMobInitiative")) {
combat.rollNPC = rollNPC.bind(combat);
combat.rollAll = rollAll.bind(combat);
}
else {
} else {
// reset the methods
if (combat.originalRollNPC) {
combat.rollNPC = combat.originalRollNPC;
Expand Down
25 changes: 15 additions & 10 deletions scripts/mobAttackTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export class MobAttackDialog extends FormApplication {
mobList[mobName] = {mobName: mobName, monsters: monsterArray, selectedTokenIds: selectedTokenIds, numSelected: numSelected, userId: game.user.id};
await game.settings.set(moduleName,"hiddenMobList",mobList);
Hooks.call("mobUpdate", {mobList, mobName, type: "save"});
await game.combat.update();
if (game.combat) await game.combat.update();
ui.notifications.info(game.i18n.format("MAT.savedMobNotify",{mobName: mobName}));
}

Expand Down Expand Up @@ -581,7 +581,6 @@ export class MobAttackDialog extends FormApplication {
}
await game.settings.set(moduleName,"hiddenMobList",mobList);
Hooks.call("mobUpdate", {mobList, mobName: mobSelected, type: "delete"});
await game.combat.update();
ui.notifications.info(game.i18n.format("MAT.deleteMobNotify",{mobName: mobSelected}));
mobSelected = Object.keys(mobList)[0];
await game.settings.set(moduleName,'hiddenMobName',mobSelected);
Expand All @@ -593,18 +592,17 @@ export class MobAttackDialog extends FormApplication {
}
await game.settings.set(moduleName,"hiddenMobList",mobList);
Hooks.call("mobUpdate", {mobList, mobName: mobSelected, type: "reset"});
await game.combat.update();
ui.notifications.info(game.i18n.localize("MAT.resetAllMobsNotify"));
mobSelected = initialMobName;
await game.settings.set(moduleName,'hiddenMobName',mobSelected);
} else if (html.find(`input[name="resetAllMobs"]`)[0]?.checked) {
await game.settings.set(moduleName,"hiddenMobList",{});
Hooks.call("mobUpdate", {mobList, mobName: mobSelected, type: "resetAll"});
await game.combat.update();
ui.notifications.info(game.i18n.localize("MAT.resetMobsNotify"));
mobSelected = initialMobName;
await game.settings.set(moduleName,'hiddenMobName',mobSelected);
}
if (game.combat) await game.combat.update();
resolve(mobSelected);
}
}
Expand Down Expand Up @@ -883,18 +881,18 @@ export function MobAttacks() {
- mobList [Object (Promise)] The complete data object of all saved mobs, including the one that was just saved to it.
*/
async function saveMob(mobName, actorList, selectedTokenIds, numSelected) {
async function saveMob(mobName, actorList, selectedTokenIds, numSelected, type = "") {
let mobList = game.settings.get(moduleName, "hiddenMobList");
let monsters, weapons, availableAttacks;
[monsters, weapons, availableAttacks] = await prepareMonsters(actorList);
let monsterArray = [];
for (let [monsterID, monsterData] of Object.entries(monsters)) {
monsterArray.push(monsterData);
}
mobList[mobName] = {mobName: mobName, monsters: monsterArray, selectedTokenIds: selectedTokenIds, numSelected: numSelected, userId: game.user.id};
mobList[mobName] = {mobName: mobName, monsters: monsterArray, selectedTokenIds: selectedTokenIds, numSelected: numSelected, userId: game.user.id, type: type};
await game.settings.set(moduleName,"hiddenMobList",mobList);
Hooks.call("mobUpdate", {mobList, mobName, type: "save"});
await game.combat.update();
if (game.combat) await game.combat.update();
return mobList;
}

Expand Down Expand Up @@ -926,12 +924,19 @@ export function MobAttacks() {
await game.settings.set(moduleName, "hiddenChangedMob", false);
mobDialog.render();
}
await game.combat.update();
if (game.combat) await game.combat.update();
return mobList;
}

async function createSavedMobsFromCTGgroups(groups, mobNames = []) {
let mobList;
let mobList = game.settings.get(moduleName, "hiddenMobList");

// delete existing CTG groups first
for (let ctgMobName of Object.keys(mobList)) {
if (mobList[ctgMobName]?.type === "ctg") {
await deleteSavedMob(ctgMobName);
}
}
let dupNameNum = 2;
if (!groups.length || !groups[0].length) return;

Expand All @@ -953,7 +958,7 @@ export function MobAttacks() {
actorList.push(combatant?.actor);
selectedTokenIds.push(combatant.data?.tokenId);
}
mobList = await saveMob(mobNames[i], actorList, selectedTokenIds, numSelected);
mobList = await saveMob(mobNames[i], actorList, selectedTokenIds, numSelected, "ctg");
}
return mobList;
}
Expand Down
16 changes: 16 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ const matSettings = {
config: false,
type: Boolean,
default: false
},
"autoSaveCTGgroups": {
name: "SETTINGS.MAT.autoSaveCTGgroups",
hint: "SETTINGS.MAT.autoSaveCTGgroupsHint",
scope: "world",
config: false,
type: Boolean,
default: false
}
};

Expand Down Expand Up @@ -458,6 +466,14 @@ class RollSettingsMenu extends FormApplication {
isCheckbox: true,
client: game.user.isGM
},
autoSaveCTGgroups: {
name: matSettings.autoSaveCTGgroups.name,
hint: matSettings.autoSaveCTGgroups.hint,
value: game.settings.get(moduleName,"autoSaveCTGgroups"),
id: "autoSaveCTGgroups",
isCheckbox: true,
client: game.user.isGM
},
enableMobInitiative: {
name: matSettings.enableMobInitiative.name,
hint: matSettings.enableMobInitiative.hint,
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export async function loadMob(event, selectedMob) {
mobDialog.actorList = actorList;
await game.settings.set(moduleName,"hiddenMobList",mobList);
Hooks.call("mobUpdate", {mobList, mobName: selectedMob, type: "load"});
await game.combat.update();
if (game.combat) await game.combat.update();

for (let i = 0; i < Object.keys(mobList).length; i++) {
if (Object.keys(mobList)[i] === selectedMob) {
Expand Down

0 comments on commit 733822f

Please sign in to comment.