Skip to content

Commit

Permalink
Merge pull request #97 from Jagusti/packs
Browse files Browse the repository at this point in the history
Add macro and table maintenance features
  • Loading branch information
Jagusti authored May 21, 2022
2 parents f5ade5f + 94d573a commit e6cd393
Show file tree
Hide file tree
Showing 17 changed files with 268 additions and 36 deletions.
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ See [Issue Backlog](../../issues) and [Roadmap](../../milestones).
- *Changed* Advantage UI notifications to only present to GM users. This is introduced to prevent token or actor names being revealed to players. This will not prevent names being revealed in chat log messages, such as for opposed test results. [[#87](https://github.com/Jagusti/fvtt-wfrp4e-gmtoolkit/issues/87)]
- *Fixed* compatibility with Advanced Macros [[#85](https://github.com/Jagusti/fvtt-wfrp4e-gmtoolkit/issues/85)]
- Add XP, Reset Fortune and Session Turnover macros no longer throw an error if the Advanced Macros module is also active.
- These macros will need to be manually re-imported from the compendium for changes to apply.
- These macros will need to be re-imported from the compendium for changes to apply.
- *Changed* references to Global Illumination to Unrestricted Token Vision, to align with changes in Foundry scene configuration options.
- This affects the Toggle Scene Visibility and Light macro, which should be manually re-imported from the compendium for changes to apply.
- This affects the Toggle Scene Visibility and Light macro, which should be re-imported from the compendium for changes to apply.
- *Changed* compendium pack definitions to use field 'type' instead of deprecated 'entity'.
- *Added* Japanese language support, including including localisation improvements to Pull Everyone to Scene and GM Toolbox macros. Thanks @Yasnen for contributing these!
- The Pull Everyone to Scene and GM Toolbox macros will need to be manually re-imported from the compendium for localization and related improvements to apply.
- The Pull Everyone to Scene and GM Toolbox macros will need to be re-imported from the compendium for localization and related improvements to apply.
- *Added* new Maintenance option in module settings to re-import GM Toolkit macros and tables. It is **recommended** to use this option when upgrading to a new version to reset content.
- Content is imported from compendium packs into the GM Toolkit Macro Directory folder or RollTable folder, depending on document type being imported.
- Existing content in the folder is removed, so any customizations should be moved to a separate location first.
- The Maintenance dialog shows version numbers for world and compendium content, so you can more easily identify if an item has been updated for a release.
- The Maintenance dialog also shows the database ID of the item. This can be used to identify existing duplicate world content (such as customised table or macro in a different folder location) that prevents re-importing.
- *Added* notes footer to Advantage suite and Toggle Scene Visibility and Light macros
- This includes macro decsription, version number and date plus usage tips
- This change standardises the presentation of in-context macro documentation across the suite.

## Version 0.9.2
- *Fixed* duplicate results numbering in Dark Whispers table and localization omission [#79] (Thanks @Txus5012).
Expand Down
75 changes: 75 additions & 0 deletions apps/gm-toolkit-maintenance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import GMToolkit from "../modules/gm-toolkit.mjs";
import { refreshToolkitContent, strip } from "../modules/utility.mjs";

export default class GMToolkitMaintenanceWrapper extends FormApplication {
async render() {
let listToolkitContent = new Array()
listToolkitContent.macros = await buildLocalizedContent(game.macros)
listToolkitContent.tables = await buildLocalizedContent(game.tables)

let html = await renderTemplate("modules/wfrp4e-gm-toolkit/templates/gm-toolkit-maintenance.html", listToolkitContent)

new GMToolkitMaintenance("wfrp4e-gm-toolkit", `${GMToolkit.MODULE_NAME_FULL} Maintenance`,html).render(true);
}
} // end class GMToolkitMaintenanceWrapper

class GMToolkitMaintenance extends Dialog {

constructor(module = GMToolkit.MODULE_ID, title, html) {
super({
title,
content: html,
module: game.modules.get(module),
buttons: {
macros: {
label: "Macros",
callback: async () => {
await refreshToolkitContent("Macro")
}
},
tables: {
label: "Tables",
callback: async () => {
await refreshToolkitContent("RollTable")
}
}
}
})
}

} // end class GMToolkitMainenance

async function buildLocalizedContent(documentType) {
GMToolkit.log(false, "Starting buildLocalizedContent")
let toolkitContent = (documentType.filter(m=>m.folder?.name==game.gmtoolkit.module.MODULE_NAME)).sort((a, b) => a.name.localeCompare(b.name))
let contentArray = []
let pack = []

// Set translationKey prefix
let translationKeyPrefix = ""
if (documentType === game.macros) {
translationKeyPrefix = "GMTOOLKIT.Macro"
pack = game.packs.get(`${game.gmtoolkit.module.MODULE_ID}.gm-toolkit-macros`);
}
if (documentType === game.tables) {
translationKeyPrefix = "GMTOOLKIT.Table"
pack = game.packs.get(`${game.gmtoolkit.module.MODULE_ID}.gm-toolkit-tables`);
}

// Get Compendium documents
let documents = await pack.getDocuments();

// build localized array
for (var content of toolkitContent) {
content.translationKey = strip(content.name, translationKeyPrefix, ".")
content.compendiumVersion = documents.filter(d => d.id == content.id).map(i => i.data.flags["wfrp4e-gm-toolkit"].version)

contentArray.push(content)
}

GMToolkit.log(false, "contentArray : ", contentArray)
GMToolkit.log(false, "Ending buildLocalizedContent")

return(contentArray)

} // end function buildLocalizedContent()
20 changes: 20 additions & 0 deletions css/gmtoolkit.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,23 @@
box-shadow: 0px 0px 10px inset black;
background: #352516;
}

/* 3. DIALOG */
/***************************/

/* 3a. List Data */

.gmtoolkit.list-metadata.id {
font-family: var(--actor-input-font-family);
color: #cbee8b75;
}

.gmtoolkit.list-metadata.version {
color: #006188;
font-weight: bold;
}

.gmtoolkit.list-thumbnail {
vertical-align: bottom;
max-height: 1.5em;
}
10 changes: 10 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@
"GMTOOLKIT.Macro.SetTokenVisionandLight": "Set Token Vision and Light",
"GMTOOLKIT.Macro.PullEveryonetoScene": "Pull Everyone to Scene",
"GMTOOLKIT.Macro.Simplyd100": "Simply d100",
"GMTOOLKIT.Macro.GMToolbox": "GM Toolbox",

"GMTOOLKIT.Table.DarkWhispers": "Dark Whispers",

"GMTOOLKIT.Dialog.Maintenance.Hint": "Remove all macros or tables in the 'GM Toolkit' Macro directory or RollTable folder, if that folder exists, and import the latest compendium versions.<br><br>Any customisations will be lost. Move these out of the GM Toolkit directory first if you want to preserve any changes you have made.",
"GMTOOLKIT.Dialog.Maintenance.Macros": "Macros",
"GMTOOLKIT.Dialog.Maintenance.Tables": "Tables",
"GMTOOLKIT.Settings.Maintenance.menu.name" : "Module Maintenance",
"GMTOOLKIT.Settings.Maintenance.menu.hint" : "Replace imported GM Toolkit macros and/or tables with latest compendium versions.",
"GMTOOLKIT.Settings.Maintenance.menu.label" : "Update GM Toolkit Content",

"ROLL.AstoundingSuccess" : "Astounding Success. 'Yes, perfectly!'",
"ROLL.ImpressiveSuccess" : "Impressive Success. 'Yes, and ...'",
Expand Down
10 changes: 10 additions & 0 deletions lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@
"GMTOOLKIT.Macro.SetTokenVisionandLight": "Set Token Vision and Light",
"GMTOOLKIT.Macro.PullEveryonetoScene": "Pull Everyone to Scene",
"GMTOOLKIT.Macro.Simplyd100": "Simply d100",
"GMTOOLKIT.Macro.GMToolbox": "GM Toolbox",

"GMTOOLKIT.Table.DarkWhispers": "Dark Whispers",

"GMTOOLKIT.Dialog.Maintenance.Hint": "Remove all macros or tables in the 'GM Toolkit' Macro directory or RollTable folder, if that folder exists, and import the latest compendium versions.<br><br>Any customisations will be lost. Move these out of the GM Toolkit directory first if you want to preserve any changes you have made.",
"GMTOOLKIT.Dialog.Maintenance.Macros": "Macros",
"GMTOOLKIT.Dialog.Maintenance.Tables": "Tables",
"GMTOOLKIT.Settings.Maintenance.menu.name" : "Module Maintenance",
"GMTOOLKIT.Settings.Maintenance.menu.hint" : "Replace imported GM Toolkit macros and/or tables with latest compendium versions.",
"GMTOOLKIT.Settings.Maintenance.menu.label" : "Update GM Toolkit Content",

"ROLL.AstoundingSuccess" : "Réussite Stupéfiante. \"Oui, absolument !\"",
"ROLL.ImpressiveSuccess" : "Réussite Impressionnant. \"Oui, et...\"",
Expand Down
10 changes: 10 additions & 0 deletions lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@
"GMTOOLKIT.Macro.SetTokenVisionandLight": "トークンの視界と光源を設定",
"GMTOOLKIT.Macro.PullEveryonetoScene": "全員をシーンに引き寄せる",
"GMTOOLKIT.Macro.Simplyd100": "100面ダイス",
"GMTOOLKIT.Macro.GMToolbox": "GM Toolbox",

"GMTOOLKIT.Table.DarkWhispers": "Dark Whispers",

"GMTOOLKIT.Dialog.Maintenance.Hint": "Remove all macros or tables in the 'GM Toolkit' Macro directory or RollTable folder, if that folder exists, and import the latest compendium versions.<br><br>Any customisations will be lost. Move these out of the GM Toolkit directory first if you want to preserve any changes you have made.",
"GMTOOLKIT.Dialog.Maintenance.Macros": "Macros",
"GMTOOLKIT.Dialog.Maintenance.Tables": "Tables",
"GMTOOLKIT.Settings.Maintenance.menu.name" : "Module Maintenance",
"GMTOOLKIT.Settings.Maintenance.menu.hint" : "Replace imported GM Toolkit macros and/or tables with latest compendium versions.",
"GMTOOLKIT.Settings.Maintenance.menu.label" : "Update GM Toolkit Content",

"ROLL.AstoundingSuccess" : "超大成功。「イエス、文句なしにな!」",
"ROLL.ImpressiveSuccess" : "大成功。「イエス。しかも……」",
Expand Down
11 changes: 11 additions & 0 deletions modules/gm-toolkit-settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import GMToolkitAdvantageSettings from "../apps/gm-toolkit-advantage-settings.js
import GMToolkitDarkWhispersSettings from "../apps/gm-toolkit-darkwhispers-settings.js";
import GMToolkitSessionManagementSettings from "../apps/gm-toolkit-session-management-settings.js";
import GMToolkitVisionSettings from "../apps/gm-toolkit-vision-settings.js";
import GMToolkitMaintenanceWrapper from "../apps/gm-toolkit-maintenance.js";

export default class GMToolkitSettings {

Expand Down Expand Up @@ -295,6 +296,16 @@ export default class GMToolkitSettings {
type: Boolean,
feature: "grouptests"
});

// Menu for Module Content Management
game.settings.registerMenu(GMToolkit.MODULE_ID, "menuMaintenance", {
name: "GMTOOLKIT.Settings.Maintenance.menu.name",
label: "GMTOOLKIT.Settings.Maintenance.menu.label",
hint: "GMTOOLKIT.Settings.Maintenance.menu.hint",
icon: "fas fa-cog",
type: GMToolkitMaintenanceWrapper,
restricted: true
});

}

Expand Down
3 changes: 2 additions & 1 deletion modules/gm-toolkit.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export default class GMToolkit {

static MODULE_ID = "wfrp4e-gm-toolkit";
static MODULE_NAME = "GM Toolkit (WFRP4e)";
static MODULE_ABBREV = "GMTOOLKIT";
static MODULE_NAME = "GM Toolkit";
static MODULE_NAME_FULL = "GM Toolkit (WFRP4e)";

/**
* A small helper function which leverages developer mode flags to gate debug logs.
Expand Down
50 changes: 49 additions & 1 deletion modules/utility.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,52 @@ export function inActiveCombat(character, notification = true) {
}
}
return inActiveCombat
}
}

/**
* Delete and re-import GM Toolkit macros
* @param {String} documentType : Actor object of the character
**/
export async function refreshToolkitContent(documentType) {

let toolkitContent = []

switch (documentType) {
case "Macro" :
// delete macros
await Macro.deleteDocuments(game.macros.filter(m=>m.folder?.name==GMToolkit.MODULE_NAME).map(m=>m.id))
// delete Macro folder
await Folder.deleteDocuments(game.folders.filter(f => f.name == GMToolkit.MODULE_NAME && f.type == "Macro").map(f => f.id))
// import macros from compendium
toolkitContent = await game.packs.get(`${GMToolkit.MODULE_ID}.gm-toolkit-macros`).importAll({
folderName: GMToolkit.MODULE_NAME,
options: {keepId : true}
});
break;
case "RollTable" :
// delete tables within GM Toolkit directory
await RollTable.deleteDocuments(game.tables.filter(t=>t.folder?.name==GMToolkit.MODULE_NAME).map(t=>t.id))
// delete RollTable folder
await Folder.deleteDocuments(game.folders.filter(f => f.name == GMToolkit.MODULE_NAME && f.type == "RollTable").map(f => f.id))
// import tables from compendium
toolkitContent = await game.packs.get(`${GMToolkit.MODULE_ID}.gm-toolkit-tables`).importAll({
folderName: GMToolkit.MODULE_NAME,
options: {keepId : true}
});
break;
}

GMToolkit.log(false, toolkitContent)

}

/**
* Remove all leading, trailing and internal whitespace from a string.
* Typical use is in constructing localization strings from, eg, macro names
* @param {String} originalText : string from which to remove all whitespace
* @param {String} prefix : optional prefix for building string
* @param {String} joiner : optional joining character to connect prefix and stripped string
**/
export function strip(originalText, prefix = "", joiner = "") {
return (prefix + joiner + originalText.replace(/\s+/g, ''))
}
26 changes: 13 additions & 13 deletions packs/gm-toolkit-macros.db

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packs/gm-toolkit-tables.db
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"_id":"9rXQv4uJcQoLBitt","name":"Dark Whispers","img":"icons/svg/d20-grey.svg","description":"Generic Dark Whispers that are used as placeholder prompts by the Send Dark Whispers macro.","results":[{"_id":"g9rsj2kp26oh6r3z","type":0,"text":"Let your quarry go.","range":[1,1],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":1,"rangeH":1},{"_id":"h3hvuahahukmiklq","type":0,"text":"'Accidentally' strike an ally.","range":[2,2],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":2,"rangeH":2},{"_id":"9ltv15jz9n4pkc7m","type":0,"text":"Fall asleep on watch.","range":[3,3],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":3,"rangeH":3},{"_id":"j1z9hqs65ife4pqx","type":0,"text":"Kneel before the Magister. Show your allegiance.","range":[4,4],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":4,"rangeH":4},{"_id":"ds7tn3xsonqyquvo","type":0,"text":"Nobody's that good or lucky. However popular or powerful they are. Call out the cheat!","range":[5,5],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":5,"rangeH":5},{"_id":"3cx7xfwzxscq40p2","type":0,"text":"You're not as prepared as you thought you were.","range":[6,6],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":6,"rangeH":6},{"_id":"2rq045im6k1pft53","type":0,"text":"Exert your authority. Make an example of the weakest or most vulnerable.","range":[7,7],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":7,"rangeH":7},{"_id":"5iq16gdx32qx83yv","type":0,"text":"The big indestructible one over there is looking at you funny. Don't stand for it. Defend your honour. Publicly and on your own.","range":[8,8],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":8,"rangeH":8},{"_id":"azxfuejsd1v28wym","type":0,"text":"You didn't come all this way to make friends. Sometimes you end up making enemies. This is one of those opportunities.","range":[9,9],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":9,"rangeH":9},{"_id":"gmfs74ty8wbm8eoy","type":0,"text":"Secrets are burdensome. Be generous and give them away.","range":[10,10],"drawn":false,"flags":{},"img":"icons/svg/d20-black.svg","collection":null,"resultId":null,"weight":null,"rangeL":10,"rangeH":10}],"formula":"1d10","replacement":true,"displayRoll":true,"folder":null,"sort":0,"permission":{"default":0,"Lngg3hbkX3DayZX9":3},"flags":{"wfrp4e":{"key":"darkwhispers"},"core":{"sourceId":"RollTable.9rXQv4uJcQoLBitt"}}}
{"_id":"9rXQv4uJcQoLBitt","name":"Dark Whispers","img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","description":"Generic Dark Whispers that are used as placeholder prompts by the Send Dark Whispers macro.","results":[{"_id":"g9rsj2kp26oh6r3z","type":0,"text":"Let your quarry go.","range":[1,1],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":1,"rangeH":1},{"_id":"h3hvuahahukmiklq","type":0,"text":"'Accidentally' strike an ally.","range":[2,2],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":2,"rangeH":2},{"_id":"9ltv15jz9n4pkc7m","type":0,"text":"Fall asleep on watch.","range":[3,3],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":3,"rangeH":3},{"_id":"j1z9hqs65ife4pqx","type":0,"text":"Kneel before the Magister. Show your allegiance.","range":[4,4],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":4,"rangeH":4},{"_id":"ds7tn3xsonqyquvo","type":0,"text":"Nobody's that good or lucky. However popular or powerful they are. Call out the cheat!","range":[5,5],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":5,"rangeH":5},{"_id":"3cx7xfwzxscq40p2","type":0,"text":"You're not as prepared as you thought you were.","range":[6,6],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":6,"rangeH":6},{"_id":"2rq045im6k1pft53","type":0,"text":"Exert your authority. Make an example of the weakest or most vulnerable.","range":[7,7],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":7,"rangeH":7},{"_id":"5iq16gdx32qx83yv","type":0,"text":"The big indestructible one over there is looking at you funny. Don't stand for it. Defend your honour. Publicly and on your own.","range":[8,8],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":8,"rangeH":8},{"_id":"azxfuejsd1v28wym","type":0,"text":"You didn't come all this way to make friends. Sometimes you end up making enemies. This is one of those opportunities.","range":[9,9],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":9,"rangeH":9},{"_id":"gmfs74ty8wbm8eoy","type":0,"text":"Secrets are burdensome. Be generous and give them away.","range":[10,10],"drawn":false,"flags":{},"img":"modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg","rangeL":10,"rangeH":10}],"formula":"1d10","replacement":true,"displayRoll":true,"folder":null,"sort":0,"permission":{"default":0,"Lngg3hbkX3DayZX9":3},"flags":{"wfrp4e":{"key":"darkwhispers"},"wfrp4e-gm-toolkit":{"version":"0.9.2"},"core":{"sourceId":"RollTable.9rXQv4uJcQoLBitt"}}}
13 changes: 9 additions & 4 deletions scripts/macros/add-advantage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* Increases Advantage for the selected token by 1.
* Caps at character's maximum advantage.
*/

game.gmtoolkit.advantage.updateAdvantage(token,`increase`);

/* ==========
* MACRO: Add Advantage
* VERSION: 0.8.0
* UPDATED: 2021-12-26
* DESCRIPTION: Increases Advantage for the selected token by 1.
* TIP: Token must be added to an encounter in the Combat Tracker.
* TIP: Caps at character's maximum advantage.
========== */
Loading

0 comments on commit e6cd393

Please sign in to comment.