Skip to content

Commit

Permalink
Merge pull request #111 from AngryBeaver/v11
Browse files Browse the repository at this point in the history
3.4.2
  • Loading branch information
AngryBeaver authored Jan 7, 2024
2 parents 55b4759 + cbbcf47 commit 3cbb517
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 25 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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, ...
Expand Down
14 changes: 13 additions & 1 deletion macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/AnyOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export class AnyOf {

async executeMacro(item): Promise<MacroResult<boolean>> {
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
Expand Down
2 changes: 1 addition & 1 deletion src/Crafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions src/Recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions src/apps/AnyOfSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -40,7 +38,7 @@ export class AnyOfSheet {
}
this.anyOfElement = $('<div class="beavers-crafting"></div>');
beaversSystemInterface.itemSheetReplaceContent(this.app,html,this.anyOfElement);
this.render();
this.render().then(()=>this.addDragDrop());
}

async render() {
Expand All @@ -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)
Expand All @@ -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]);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/apps/RecipeSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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){
Expand All @@ -57,11 +56,11 @@ export class RecipeSheet {
this.recipeElement = $('<div class="beavers-crafting recipe"></div>');
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: {
Expand All @@ -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]);
}
}

Expand Down

0 comments on commit 3cbb517

Please sign in to comment.