Skip to content

Commit

Permalink
Merge pull request #72 from AngryBeaver/dr
Browse files Browse the repository at this point in the history
Dr
  • Loading branch information
AngryBeaver authored Jul 24, 2023
2 parents eb5bf36 + 5675eb1 commit e2c60e8
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 67 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ Or can start a crafting process by clicking on a recipe in your inventory (depre

You will see a chat message with your result

Items updated or created in a successfull crafting process are flagged:
flags.beavers-crafting.status = "created" or "updated"


### AnyOf
AnyOf is an Item that is intended to be used as ingredient to create recipes that do not need a specific ingredient but any ingredient of... e.g. specific type.

Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog
## 3.2.x simple or
## 3.2.2
- automatically fix broken tools (dnd5e)
- add flag to created or updated items
- fix broken anyOf precast status
- fix recipes returning results that are based on items that do not have quantity
## 3.2.1
- recipe edit quantity
## 3.2.0
Expand Down
9 changes: 9 additions & 0 deletions css/crafting.css
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@
width: 14px;
padding: 0px 0px 0px 3px;
}

.beavers-crafting .fa-question{
color: #3f678e;
width:14px;
padding-left:2px;
font-size:small;
margin: auto;
}

.beavers-crafting .fa-check{
color:#468847;
margin: auto;
Expand Down
32 changes: 25 additions & 7 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"title": "Beaver's Crafting Module",
"description": "A Crafting Module",
"description": "A Module for not only Crafting. But also Tracking any activities, Skill challenges, Quest and Progress, Faction reputation and more",
"id": "beavers-crafting",
"version": "3.2.1",
"version": "3.2.2",
"authors": [
{
"name": "angryBeaver",
Expand Down Expand Up @@ -44,24 +44,42 @@
"type": "module",
"manifest": "https://github.com/AngryBeaver/beavers-system-interface/releases/latest/download/module.json",
"compatibility": {
"minimum" : "2.1.1",
"verified": "2.1.1"
"minimum" : "2.1.2",
"verified": "2.1.2"
}
},
}
],
"recommends": [
{
"id": "bsa-dnd5e",
"type": "module",
"manifest": "https://github.com/AngryBeaver/bsa-dnd5e/releases/latest/download/module.json",
"compatibility": {
"verified": "2.0.0"
"verified": "2.0.1"
}
},
{
"id": "bsa-pf2e",
"type": "module",
"manifest": "https://github.com/AngryBeaver/bsa-pf2e/releases/latest/download/module.json",
"compatibility": {
"verified": "1.0.0"
"verified": "1.0.1"
}
},
{
"id": "bsa-pf1",
"type": "module",
"manifest": "https://github.com/AngryBeaver/bsa-pf1/releases/latest/download/module.json",
"compatibility": {
"verified": "1.0.1"
}
},
{
"id": "bsa-swade",
"type": "module",
"manifest": "https://github.com/AngryBeaver/bsa-swade/releases/latest/download/module.json",
"compatibility": {
"verified": "1.0.2"
}
}
]
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions 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.2.1",
"version": "3.2.2",
"description": "Crafting",
"devDir": "C:\\Users\\Riess\\AppData\\Local\\FoundryVTT\\Data\\modules",
"#devDir": "C:\\data\\Data\\modules",
Expand All @@ -24,7 +24,7 @@
"printWidth": 120
},
"devDependencies": {
"beavers-system-interface": "^2.1.1",
"beavers-system-interface": "^2.1.2",
"@ethaks/fvtt-quench": "^0.6.0",
"@league-of-foundry-developers/foundry-vtt-types": "^0.8.8-9",
"@types/jest": "^27.4.1",
Expand Down
21 changes: 20 additions & 1 deletion src/Crafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ export class Crafting implements CraftingData {
}
}
try{
await beaversSystemInterface.actorComponentListAdd(this.actor,componentList);
const itemChange = await beaversSystemInterface.actorComponentListAdd(this.actor,componentList);
const actor = await fromUuid(this.actor.uuid);
this._flagCreatedItems(actor, itemChange);
}catch(e){
// @ts-ignore
ui.notifications.error(e.message)
Expand Down Expand Up @@ -368,6 +370,23 @@ export class Crafting implements CraftingData {
}
}
}
async _flagCreatedItems(actor: any, itemChange:ItemChange){
const updates:any[] = [];
if(!this.result.hasError()) {
for (const u of itemChange.update) {
const update = {_id: u._id};
beaversSystemInterface.objectAttributeSet(update, "flags.beavers-crafting.status", "updated");
updates.push(update);
}
for (const c of itemChange.create) {
const update = {_id: c._id || c.id}
beaversSystemInterface.objectAttributeSet(update, "flags.beavers-crafting.status", "created");
updates.push(update);
}
await actor.updateEmbeddedDocuments("Item", updates);
}
}

get chatData(): ChatData {
return this.getChatData();
}
Expand Down
78 changes: 39 additions & 39 deletions src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ export class Settings {
name: "ToolConfig",
scope: "world",
config: false,
default: getSystemSetting().toolConfig,
default: Settings.getSystemSetting().toolConfig,
type: Object
});
if (getSystemSetting().hasTool) {
if (Settings.getSystemSetting().hasTool) {
game.settings.registerMenu(this.NAMESPACE, this.TOOL_CONFIG_BUTTON, {
name: game.i18n.localize('beaversCrafting.settings.toolButton.name'),
label: game.i18n.localize("beaversCrafting.settings.toolButton.label"),
Expand All @@ -137,43 +137,43 @@ export class Settings {
return Settings.get(Settings.DISABLED_ACTOR).split(",").includes(actor.type);
}

}

export function getSystemSetting() {
if (game["system"].id === "dnd5e") {
static getSystemSetting() {
if (game["system"].id === "dnd5e") {
return {
toolConfig: [
"Compendium.dnd5e.items.8NS6MSOdXtUqD7Ib",
"Compendium.dnd5e.items.rTbVrNcwApnuTz5E",
"Compendium.dnd5e.items.fC0lFK8P4RuhpfaU",
"Compendium.dnd5e.items.YfBwELTgPFHmQdHh",
"Compendium.dnd5e.items.hM84pZnpCqKfi8XH",
"Compendium.dnd5e.items.PUMfwyVUbtyxgYbD",
"Compendium.dnd5e.items.skUih6tBvcBbORzA",
"Compendium.dnd5e.items.YHCmjsiXxZ9UdUhU",
"Compendium.dnd5e.items.hJS8yEVkqgJjwfWa",
"Compendium.dnd5e.items.woWZ1sO5IUVGzo58",
"Compendium.dnd5e.items.KndVe2insuctjIaj",
"Compendium.dnd5e.items.0d08g1i5WXnNrCNA",
"Compendium.dnd5e.items.ap9prThUB2y9lDyj",
"Compendium.dnd5e.items.xKErqkLo4ASYr5EP",
"Compendium.dnd5e.items.SztwZhbhZeCqyAes",
"Compendium.dnd5e.items.Y9S75go1hLMXUD48",
"Compendium.dnd5e.items.jhjo20QoiD5exf09",
"Compendium.dnd5e.items.ccm5xlWhx74d6lsK",
"Compendium.dnd5e.items.ugzwHl8vYaPu2GNd",
"Compendium.dnd5e.items.i89okN7GFTWHsvPy",
"Compendium.dnd5e.items.IBhDAr7WkhWPYLVn",
"Compendium.dnd5e.items.cG3m4YlHfbQlLEOx",
"Compendium.dnd5e.items.il2GNi8C0DvGLL9P",
"Compendium.dnd5e.items.V13fjV5oSmvbRdgP",
"Compendium.dnd5e.items.6rocoBx5jdzG1QQH",
],
hasTool: true,
}
}
return {
toolConfig: [
"Compendium.dnd5e.items.8NS6MSOdXtUqD7Ib",
"Compendium.dnd5e.items.rTbVrNcwApnuTz5E",
"Compendium.dnd5e.items.fC0lFK8P4RuhpfaU",
"Compendium.dnd5e.items.YfBwELTgPFHmQdHh",
"Compendium.dnd5e.items.hM84pZnpCqKfi8XH",
"Compendium.dnd5e.items.PUMfwyVUbtyxgYbD",
"Compendium.dnd5e.items.skUih6tBvcBbORzA",
"Compendium.dnd5e.items.YHCmjsiXxZ9UdUhU",
"Compendium.dnd5e.items.hJS8yEVkqgJjwfWa",
"Compendium.dnd5e.items.woWZ1sO5IUVGzo58",
"Compendium.dnd5e.items.KndVe2insuctjIaj",
"Compendium.dnd5e.items.0d08g1i5WXnNrCNA",
"Compendium.dnd5e.items.ap9prThUB2y9lDyj",
"Compendium.dnd5e.items.xKErqkLo4ASYr5EP",
"Compendium.dnd5e.items.SztwZhbhZeCqyAes",
"Compendium.dnd5e.items.Y9S75go1hLMXUD48",
"Compendium.dnd5e.items.jhjo20QoiD5exf09",
"Compendium.dnd5e.items.ccm5xlWhx74d6lsK",
"Compendium.dnd5e.items.ugzwHl8vYaPu2GNd",
"Compendium.dnd5e.items.i89okN7GFTWHsvPy",
"Compendium.dnd5e.items.IBhDAr7WkhWPYLVn",
"Compendium.dnd5e.items.cG3m4YlHfbQlLEOx",
"Compendium.dnd5e.items.il2GNi8C0DvGLL9P",
"Compendium.dnd5e.items.V13fjV5oSmvbRdgP",
"Compendium.dnd5e.items.6rocoBx5jdzG1QQH",
],
hasTool: true,
toolConfig: [],
hasTool: false,
}
}
return {
toolConfig: [],
hasTool: false,
}
}

}
16 changes: 11 additions & 5 deletions src/apps/CraftingApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class CraftingApp extends Application {
return;
}
const crafting = await Crafting.fromRecipe(this.data.actor.id, this.data.recipe);
RecipeCompendium.validateRecipeToItemList(RecipeCompendium._filterData(this.data.recipe.input,(c)=>true), this.data.actor.items,crafting.result);
RecipeCompendium.validateRecipeToItemList(RecipeCompendium._filterData(this.data.recipe.input,(c)=>c.type==="Item"), this.data.actor.items,crafting.result);
await crafting.checkTool();
await crafting.checkAttendants();
await crafting.checkCurrency();
Expand Down Expand Up @@ -323,16 +323,22 @@ export class CraftingApp extends Application {
preCastData.input[group] = {};
for(const key in recipe.input[group]){
const component = recipe.input[group][key];
preCastData.input[group][key]= result._components.consumed.hasError(component)?'error':'success'
if( result._components.consumed.findComponentResult(component)){
preCastData.input[group][key]= result._components.consumed.hasError(component)?'error':'success'
}else{
preCastData.input[group][key]= 'unknown';
}
}


}
for(const group in recipe.required){
preCastData.required[group] = {};
for(const key in recipe.required[group]){
const component = recipe.required[group][key];
preCastData.required[group][key]=result._components.required.hasError(component)?'error':'success'
if( result._components.required.findComponentResult(component)) {
preCastData.required[group][key] = result._components.required.hasError(component) ? 'error' : 'success'
}else{
preCastData.required[group][key]= 'unknown';
}
}
}
return preCastData;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/RecipeSheet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Recipe} from "../Recipe.js";
import {getSystemSetting, Settings} from "../Settings.js";
import {Settings} from "../Settings.js";
import {getDataFrom} from "../helpers/Utility.js";
import {AnyOf} from "../AnyOf.js";
import {getToolConfig} from "./ToolConfig.js";
Expand Down Expand Up @@ -97,7 +97,7 @@ export class RecipeSheet {
displayResults:Settings.get(Settings.DISPLAY_RESULTS),
displayIngredients:Settings.get(Settings.DISPLAY_RESULTS),
useAttendants: Settings.get(Settings.USE_ATTENDANTS),
canRollTool:getSystemSetting().hasTool,
canRollTool:Settings.getSystemSetting().hasTool,
canRollAbility:beaversSystemInterface.configCanRollAbility,
});
let description = await renderTemplate('modules/beavers-crafting/templates/recipe-description.hbs',
Expand Down
9 changes: 8 additions & 1 deletion src/apps/ToolConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,16 @@ export async function getToolConfig(): Promise<ComponentData[]>{
async function _setToolConfig(){
components.length = 0;
const tools = Settings.get(Settings.TOOL_CONFIG) || [];
const resultTools : string[] = [];
for (const uuid of tools) {
await _addToolConfig(uuid);
try {
await _addToolConfig(uuid);
resultTools.push(uuid);
} catch( e ){
console.warn("Could not find tool uuid, automatically fixed by removing it");
}
}
Settings.set(Settings.TOOL_CONFIG,resultTools);
}
async function _addToolConfig(uuid){
const item = await beaversSystemInterface.uuidToDocument(uuid);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type DataType = "required" | "input" | "output";

type TestType = "skill" | "tool" | "ability" | "hit";

type ComponentStatus = "success"|"error"|"locked"|"undefined";
type ComponentStatus = "success"|"error"|"locked"|"undefined"|"unknown";


interface ComponentChatData {
Expand Down
2 changes: 2 additions & 0 deletions templates/beavers-recipe-component.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<i class="fas fa-times"></i>
{{else if (eq status 'locked') }}
<i class="fa-regular fa-lock"></i>
{{else if (eq status 'unknown') }}
<i class="fa-regular fa-question"></i>
{{/if}}
</div>
{{#if editable}}
Expand Down

0 comments on commit e2c60e8

Please sign in to comment.