Skip to content

Commit

Permalink
individual anyOf
Browse files Browse the repository at this point in the history
  • Loading branch information
AngryBeaver committed Oct 18, 2022
1 parent 75e5834 commit f8ebc04
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "Beaver's Crafting System",
"description": "A Crafting Module for DnD",
"id": "beavers-crafting",
"version": "0.3.0",
"version": "0.3.1",
"authors": [
{
"name": "angryBeaver",
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": "0.3.0",
"version": "0.3.1",
"description": "Crafting",
"devDir": "C:\\Users\\User\\AppData\\Local\\FoundryVTT\\Data\\modules",
"main": "src/main.js",
Expand Down
10 changes: 9 additions & 1 deletion src/Crafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ export class Crafting {
const item = await fromUuid(component.uuid);
const anyOf = new AnyOf(item);
let results = await anyOf.filter(this.actor.items);
results = results.filter(c=>c.quantity >= component.quantity);
results = results.filter(c=>{
let quantity = c.quantity;
toAdd.forEach(a=>{
if(a.id === c.id){
quantity = quantity-a.quantity;
}
});
return quantity >= component.quantity
});
if(results.length >= 0) {
const result = results[Math.floor(Math.random() * results.length)];
result.quantity = component.quantity;
Expand Down
2 changes: 1 addition & 1 deletion src/Recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class DefaultComponent implements Component {

constructor(entity, uuid, type) {
this.id = entity.id;
this.uuid = uuid;
this.uuid = entity.uuid;
this.type = type;
this.name = entity.name;
this.img = entity.img;
Expand Down
4 changes: 3 additions & 1 deletion src/apps/RecipeSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ export class RecipeSheet {
if (entity) {
if (isIngredient) {
let type = data.type;
let uuid = data.uuid;
if(isAnyOf(entity)){
type = Settings.ANYOF_SUBTYPE;
uuid = foundry.utils.randomID();
}
this.recipe.addIngredient(entity, data.uuid,type);
this.recipe.addIngredient(entity, uuid,type);
}
if (isResult) {
this.recipe.addResult(entity, data.uuid, data.type);
Expand Down

0 comments on commit f8ebc04

Please sign in to comment.