Skip to content

Commit

Permalink
Merge pull request #82 from p4535992/main
Browse files Browse the repository at this point in the history
Fix annoying flags null pointer errors for better integration with other modules
  • Loading branch information
AngryBeaver authored Sep 15, 2023
2 parents 88dea3d + 51e0dfe commit 4111a7c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/AnyOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export class AnyOf {
return (
item?.type === beaversSystemInterface.configLootItemType && (
item?.system?.source === Settings.ANYOF_SUBTYPE ||
item?.flags["beavers-crafting"]?.subtype === Settings.ANYOF_SUBTYPE
getProperty(item,`flags.beavers-crafting.subtype`) === Settings.ANYOF_SUBTYPE
)
);
}

constructor(item) {
const flags = item.flags[Settings.NAMESPACE]?.anyOf;
const flags = getProperty(item,`flags.${Settings.NAMESPACE}.anyOf`) || {};
const data = mergeObject(this.defaultData(), flags || {}, {inplace: false});
this.macro = data.macro;
this.img = item.img;
Expand Down
2 changes: 1 addition & 1 deletion src/Crafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export class Crafting implements CraftingData {
}
}
};
update.flags["beavers-crafting"].crafting[uuid] = this.serialize();
setProperty(update, `flags.beavers-crafting.crafting.${uuid}`, this.serialize());
await this.actor.update(update);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ export class Recipe implements RecipeData {
// @ts-ignore
return (item?.type === beaversSystemInterface.configLootItemType && (
item?.system?.source === Settings.RECIPE_SUBTYPE ||
item?.flags["beavers-crafting"]?.subtype === Settings.RECIPE_SUBTYPE
getProperty(item, `flags.beavers-crafting.subtype`) === Settings.RECIPE_SUBTYPE
)
)
}

static fromItem(item): Recipe {
const flags = item.flags[Settings.NAMESPACE]?.recipe;
const flags = getProperty(item,`flags.${Settings.NAMESPACE}.recipe`) || {};
const data = mergeObject({input: {}, output: {}, required: {}}, flags || {}, {inplace: false});
return new Recipe(item.uuid, item.id, item.name, item.img, data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/ActorSheetTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ActorSheetTab {

async init() {
const label = game["i18n"].localize("beaversCrafting.actorSheet.tab");
const flag = this.app.actor.flags["beavers-crafting"]?.crafting || {};
const flag = getProperty(this.app.actor,`flags.beavers-crafting.crafting`) || {};
const unsortedFolders = {};
for(const [x,y] of Object.entries(flag)){
const craftingData = (y as CraftingData);
Expand Down
6 changes: 3 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Hooks.once("beavers-system-interface.ready", async function(){

//Recipe remap use action
Hooks.on(`dnd5e.preUseItem`, (item, config, options) => {
if(item.flags[Settings.NAMESPACE]?.recipe){
if(getProperty(item, `flags.${Settings.NAMESPACE}.recipe`)){
Crafting.fromOwned(item).craft();
return false;
}
Expand All @@ -83,10 +83,10 @@ Hooks.once("beavers-system-interface.ready", async function(){

//add Subtype to create Item
Hooks.on("preCreateItem", (doc, createData, options, user) => {
if (createData.flags["beavers-crafting"]?.subtype === 'recipe' ) {
if (getProperty(createData, `flags.beavers-crafting.subtype`) === 'recipe' ) {
doc.updateSource({"flags.beavers-crafting.subtype": Settings.RECIPE_SUBTYPE,"img":"icons/sundries/scrolls/scroll-worn-tan.webp"});
}
if (createData.flags["beavers-crafting"]?.subtype === 'anyOf' ) {
if (getProperty(createData,`flags.beavers-crafting.subtype`) === 'anyOf' ) {
doc.updateSource({"flags.beavers-crafting.subtype": Settings.ANYOF_SUBTYPE,"img":"modules/beavers-crafting/icons/anyOf.png"});
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function migrateRecipeSkillToTests() {
ui.notifications?.warn("Beavers Crafting |" + e);
}
}
const flag = actor.flags["beavers-crafting"]?.crafting || {};
const flag = getProperty(actor, `flags.beavers-crafting.crafting`) || {};
for (const [x, y] of Object.entries(flag)) {
try {
const craftingData = (y as CraftingData);
Expand Down Expand Up @@ -120,7 +120,7 @@ export async function migrateDeprecateTools() {
ui.notifications?.warn("Beavers Crafting |" + e);
}
}
const flag = actor.flags["beavers-crafting"]?.crafting || {};
const flag = getProperty(actor, `flags.beavers-crafting.crafting`) || {};
for (const [x, y] of Object.entries(flag)) {
try {
const craftingData = (y as CraftingData);
Expand Down

0 comments on commit 4111a7c

Please sign in to comment.