diff --git a/changelog.md b/changelog.md index 2fb5dd7..65d2473 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,11 @@ # Changelog +## 3.4.2 +- fix anyOf (broken macros can hinder rendering of item) +- feature: advanced macros now access the complete recipe + - this should allow dynamic dcs by manipulating the recipe.test during runtime. +- prepare recipeSheet and anyOfSheet for systems using sheets with none standard Applications + - A5E does not have anything usefull within parameter html or data. +- add dnd 3.5 support ## 3.4.1 - configurable TabName/TabIcon - Beavers-Crafting is no longer only for Crafting, it is and can be used for various other things like: quest Progress, Tech Trees, Downtime Activities, ... diff --git a/macros.md b/macros.md index 088ec3e..ac4ac53 100644 --- a/macros.md +++ b/macros.md @@ -12,7 +12,7 @@ console.log(actor); ### recipeData (!! try not to use !!) - recipe will be subject to changes (the module will evolve) -> depending too much on this property will lead to breaking changes. -A copy of recipeData from your actual recipe (readOnly changes will not have any effects) +The Recipe extending RecipeData from your actual recipe see [RecipeData](https://github.com/AngryBeaver/beavers-crafting/blob/main/src/types.ts) ``` @@ -136,6 +136,18 @@ Similar to update this will delete all appearance of that component in the craft - componentData: [ComponentData](https://github.com/AngryBeaver/beavers-crafting/blob/main/src/types.ts) ## Examples +### Dynamic DCs +with this code your crafting will change the crafting dc based on ingredients used here if Iron is used the dc drops to 1 +```` +//first non null element of first input. +const metalObject = Object.values(Object.values(recipeData.input)[0]).find(i=>i!==null); +if(metalObject.name === "Iron"){ + //first and + or test + const test = Object.values(Object.values(recipeData.tests.ands)[0].ors)[0]; + test.check = 1; +} +```` + ### Selectively keep ingredients on failed crafting with this code your crafting will not consume the first ingredient component when crafting fails. ````javascript diff --git a/module.json b/module.json index 45103bb..474e654 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "title": "Beaver's Crafting Module", "description": "A Module for crafting, brewing, harvesting, mining, fabricating, gathering, character advancement, tech tree, skill tree, ability tree, downtime activities, factions / organisation reputation, quest logs, skill training", "id": "beavers-crafting", - "version": "3.4.1", + "version": "3.4.2", "authors": [ { "name": "angryBeaver", @@ -55,6 +55,11 @@ "type": "module", "manifest": "https://github.com/AngryBeaver/bsa-cyberpunk-red-core/releases/latest/download/module.json" }, + { + "id": "bsa-d35e", + "type": "module", + "manifest": "https://github.com/AngryBeaver/bsa-d35e/releases/latest/download/module.json" + }, { "id": "bsa-dnd4e", "type": "module", diff --git a/package.json b/package.json index f3bff23..244d17e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "beavers-crafting", "title": "Beaver's Crafting", - "version": "3.4.1", + "version": "3.4.2", "description": "Crafting", "#devDir": "D:\\Vtts\\v10\\Data\\modules", "#devDir": "D:\\Vtts\\v11\\Data\\modules", diff --git a/src/AnyOf.ts b/src/AnyOf.ts index de844c2..43f1492 100644 --- a/src/AnyOf.ts +++ b/src/AnyOf.ts @@ -41,13 +41,13 @@ export class AnyOf { async executeMacro(item): Promise> { const AsyncFunction = (async function () {}).constructor; - // @ts-ignore - const fn = new AsyncFunction("item", this.macro); const result = { value:false, error: undefined } try { + // @ts-ignore + const fn = new AsyncFunction("item", this.macro); result.value = await fn(item); } catch (err) { // @ts-ignore diff --git a/src/Crafting.ts b/src/Crafting.ts index 01986c0..1eab8ba 100644 --- a/src/Crafting.ts +++ b/src/Crafting.ts @@ -220,7 +220,7 @@ export class Crafting implements CraftingData { } async executeMacro() { - const macroResult = await this.recipe.executeMacro(this.recipe.serialize(), this.result, this.actor); + const macroResult = await this.recipe.executeMacro(this.recipe, this.result, this.actor); if (macroResult.error !== undefined) { // @ts-ignore ui.notifications.error("Beavers Crafting | recipe Error see logs") diff --git a/src/Recipe.ts b/src/Recipe.ts index 61e5524..b0e749b 100644 --- a/src/Recipe.ts +++ b/src/Recipe.ts @@ -340,9 +340,9 @@ export class Recipe implements RecipeData { } const AsyncFunction = (async function () { }).constructor; - // @ts-ignore - const fn = new AsyncFunction("result", "actor", "recipeData", this.macro); try { + // @ts-ignore + const fn = new AsyncFunction("result", "actor", "recipeData", this.macro); macroResult.value = await fn(result, actor, recipeData); } catch (err) { // @ts-ignore diff --git a/src/apps/AnyOfSheet.ts b/src/apps/AnyOfSheet.ts index 2460c9c..880919a 100644 --- a/src/apps/AnyOfSheet.ts +++ b/src/apps/AnyOfSheet.ts @@ -12,21 +12,19 @@ export class AnyOfSheet { checkItem?; - static bind(app, html, data) { + static bind(app, html) { if (AnyOf.isAnyOf(app.item)) { if (!anyOfSheets[app.id]) { - anyOfSheets[app.id] = new AnyOfSheet(app, data); + anyOfSheets[app.id] = new AnyOfSheet(app); } anyOfSheets[app.id].init(html); } } - constructor(app, data) { + constructor(app) { this.app = app; this.item = app.item; - this.editable = data.editable; - this.addDragDrop(); - + this.editable = app.options.editable; } init(html) { @@ -40,7 +38,7 @@ export class AnyOfSheet { } this.anyOfElement = $('
'); beaversSystemInterface.itemSheetReplaceContent(this.app,html,this.anyOfElement); - this.render(); + this.render().then(()=>this.addDragDrop()); } async render() { @@ -62,9 +60,9 @@ export class AnyOfSheet { } addDragDrop() { - if (this.editable) { + if (this.editable &&!this.app._dragDrop?.find(d=>d.name === "anyOfSheet")) { const dragDrop = new DragDrop({ - dropSelector: '.sheet-body', + dropSelector: '', permissions: { dragstart: this.app._canDragStart.bind(this.app), drop: this.app._canDragDrop.bind(this.app) @@ -75,8 +73,9 @@ export class AnyOfSheet { drop: this._onDrop.bind(this) } }); + dragDrop["name"]="anyOfSheet"; this.app._dragDrop.push(dragDrop); - dragDrop.bind(this.app.form); + dragDrop.bind(this.anyOfElement[0]); } } diff --git a/src/apps/RecipeSheet.ts b/src/apps/RecipeSheet.ts index 3760214..1977d6d 100644 --- a/src/apps/RecipeSheet.ts +++ b/src/apps/RecipeSheet.ts @@ -19,7 +19,7 @@ export class RecipeSheet { static bind(app, html, data) { if(Recipe.isRecipe(app.item)){ if(!recipeSheets[app.id]){ - recipeSheets[app.id] = new RecipeSheet(app,data); + recipeSheets[app.id] = new RecipeSheet(app); } recipeSheets[app.id].init(html); if(!app.initialized){ @@ -36,14 +36,13 @@ export class RecipeSheet { } } - constructor(app, data) { + constructor(app) { this.app = app; this.item = app.item; - this.editable = data.editable; + this.editable = app.options.editable; this.sheet = { active : "main" }; - this.addDragDrop(); } init(html){ @@ -57,11 +56,11 @@ export class RecipeSheet { this.recipeElement = $('
'); beaversSystemInterface.itemSheetReplaceContent(this.app,html,this.recipeElement); this.recipe = Recipe.fromItem(this.item); - this.render(); + this.render().then(i=>this.addDragDrop()); } addDragDrop(){ - if(this.editable) { + if(this.editable && !this.app._dragDrop?.find(d=>d.name === "recipeSheet")) { const dragDrop = new DragDrop({ dropSelector: '', permissions: { @@ -74,8 +73,9 @@ export class RecipeSheet { drop: this._onDrop.bind(this) } }); + dragDrop["name"]="recipeSheet"; this.app._dragDrop.push(dragDrop); - dragDrop.bind(this.app.form); + dragDrop.bind(this.recipeElement[0]); } }