Skip to content

Commit

Permalink
Merge pull request #69 from AngryBeaver/dr
Browse files Browse the repository at this point in the history
simpleor
  • Loading branch information
AngryBeaver authored Jul 23, 2023
2 parents 28b1cc2 + 3f5579e commit 615bed5
Show file tree
Hide file tree
Showing 19 changed files with 659 additions and 285 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,20 @@ When you use a recipe with AnyOf you can customize it and by doing so define wha
![img.png](pictures/anyOfDrop1.png)
![img.png](pictures/anyOfDrop2.png)

**Drag And Drop**
- drag and drop an ingredient (e.g. from your inventar) to "anyOf" ingredient within your recipeCompendium.
**ChoiceWindow (3.2.x)**
- clicking the AnyOf will popup a multiple choice dialog of available matching items you can choose from.

- it will automatically check if that new ingredient is available in that quantity.
- it will stack same (identity) ingredients.
- none customized AnyOf ingredients will popup a multiple choice dialog of available matching items before starting
- when you reselect the recipe it will remove your customization and start over with anyOf Items again.
- none customized AnyOf ingredients will consume a random fitting ingredient of your inventory.
### Simple Or Condition (3.2.x)
Your recipe can have "or conditions" for required, cost and result items.
You can choose one of those or conditions in the RecipeCompendium by selecting on checkbox.

![img.png](pictures/simpleOr.png)


## Examples
The easiest way to get started with this module is with some examples.
Expand Down
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
## 3.2.0 simple or
- fix consistent name of attendants as required in ui.
- add Settings to disable actor types that should not have a crafting tab.

- add simple or
- simple or ui selection
- anyOf ui selection
## 3.1.x folders
## 3.1.7
- fix anyOf allow dropping for players
Expand Down
21 changes: 19 additions & 2 deletions css/crafting.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
height:100%;
}


.beavers-crafting .drop-area {
/* Center the content */
align-items: center;
Expand Down Expand Up @@ -243,7 +242,7 @@
flex:0;
}
.beavers-crafting .clickable{
cursor: pointer;
cursor: help;
}

.beavers-crafting .beavers-line {
Expand Down Expand Up @@ -508,6 +507,24 @@ beavers-recipe
padding: 1px;
}

.beavers-crafting .beavers-recipe .data-section {
border: 1px solid grey;
border-radius: 5px;
margin: 2px 2px 2px 0px;
padding:2px;
}
.beavers-crafting .beavers-recipe .data-section .choose {
cursor: pointer;
width:16px;
height:16px;
flex:0 16px;
margin-top:8px;
}

.beavers-crafting .beavers-recipe .data-section .chooseAnyOf {
cursor: pointer;
}

.beavers-crafting .beavers-recipe .text-section .test-header {
text-align: right;
flex-direction: row-reverse;
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"dc": "DC",
"results": "Results",
"dropItem": "drop item",
"addItem" : "add item",
"orItem": "or item",
"currency": "Cost",
"consumeOnFailedSaveHint": "Consumes Cost on failed Skill check",
"attendants": "Attendants",
Expand Down
Binary file added pictures/simpleOr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 10 additions & 35 deletions src/Crafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export class Crafting implements CraftingData {
}

async startCrafting() {
await this.evaluatePossibilities();
await this.checkTool();
await this.checkAttendants();
await this.evaluateAnyOf();
RecipeCompendium.validateRecipeToItemList(Object.values(this.recipe.ingredients), this.actor.items, this.result);
RecipeCompendium.validateRecipeToItemList(RecipeCompendium._filterData(this.recipe.input,component=>true), this.actor.items, this.result);
await this.payCurrency();
await this.addOutput();
await this.executeMacro();
Expand Down Expand Up @@ -192,38 +192,13 @@ export class Crafting implements CraftingData {
}

async checkAttendants() {
await RecipeCompendium.validateAttendants(this.recipe, this.actor.items, this.result);
await RecipeCompendium.validateAttendants(this.recipe, this.result);
}

async evaluateAnyOf() {
const toDelete: string[] = [];
const toAdd: Component[] = [];
for (const [key, component] of Object.entries(this.recipe.ingredients)) {
if (component.type === Settings.ANYOF_SUBTYPE) {
const item = await component.getEntity();
const anyOf = new AnyOf(item);
let results = await anyOf.filter(this.actor.items);
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;
toAdd.push(result);
toDelete.push(key);
}
}
}
toDelete.forEach(k => this.recipe.removeIngredient(k));
toAdd.forEach(component => {
this.recipe.addIngredientComponent(component)
});
async evaluatePossibilities(){
await RecipeCompendium.evaluateOptions("required",this.recipe,this.actor.items);
await RecipeCompendium.evaluateOptions("input",this.recipe,this.actor.items);
await RecipeCompendium.evaluateOptions("output",this.recipe,this.actor.items);
}

async checkCurrency() {
Expand Down Expand Up @@ -493,7 +468,7 @@ export class Crafting implements CraftingData {
{
data: this.getChatData(),
})
content = TextEditor.enrichHTML(content);
content = await TextEditor.enrichHTML(content);
await ChatMessage.create({
content: content,
speaker: {actor: this.actor.id},
Expand All @@ -514,8 +489,8 @@ export class Crafting implements CraftingData {
}

async _getResultComponents(result: Result): Promise<ComponentData[]> {
const items = Object.values(this.recipe.results).filter(component => component.type === "Item");
const tables = Object.values(this.recipe.results).filter(component => component.type === "RollTable");
const items = RecipeCompendium._filterData(this.recipe.output,c => c.type === "Item");
const tables = RecipeCompendium._filterData(this.recipe.output,c => c.type === "RollTable");
for (const component of tables) {
items.push(...await this._rollTableToComponents(component, result));
}
Expand Down
Loading

0 comments on commit 615bed5

Please sign in to comment.