Skip to content

Commit

Permalink
Merge branch '0.8-delete-owned' into 'foundry-0.8.x-conversion'
Browse files Browse the repository at this point in the history
Change deleteOwnedItem to alternatives and correct some types

See merge request hooking/foundry-vtt---pathfinder-2e!3470
  • Loading branch information
nikolaj-a committed May 22, 2021
2 parents c60dfc6 + 4c43f29 commit 69d162f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
9 changes: 4 additions & 5 deletions src/module/actor/sheet/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ export abstract class ActorSheetPF2e<ActorType extends ActorPF2e> extends ActorS
}).render(true);
} else if (item instanceof ItemPF2e) {
const deleteItem = async (): Promise<void> => {
await this.actor.deleteOwnedItem(itemId);
await item.delete();
if (item.type === 'lore') {
// normalize skill name to lower-case and dash-separated words
const skill = item.name.toLowerCase().replace(/\s+/g, '-');
Expand Down Expand Up @@ -1628,11 +1628,10 @@ export abstract class ActorSheetPF2e<ActorType extends ActorPF2e> extends ActorS
itemsToDelete.push(item.id);
}
}

await this.actor.deleteOwnedItem(itemsToDelete);

// Delete item container
await this.actor.deleteOwnedItem(item.id);
itemsToDelete.push(item.id);
await this.actor.deleteEmbeddedDocuments('Item', itemsToDelete);

li.slideUp(200, () => this.render(false));
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/sheet/familiar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class FamiliarSheetPF2e extends ActorSheet<FamiliarPF2e> {
icon: '<i class="fas fa-trash"></i>',
label: 'Remove',
callback: () => {
this.actor.deleteOwnedItem(itemID);
item.delete();
},
},
cancel: {
Expand Down
10 changes: 5 additions & 5 deletions src/module/item/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ItemPF2e extends Item<ActorPF2e, ActiveEffectPF2e> {

// Changing the createData does not change the resulting item; the data has to be updated.
if (!isObjectEmpty(updateData)) {
(itemData as any).update(updateData); // TODO: Fix type
itemData.update(updateData);
}
}

Expand All @@ -137,10 +137,10 @@ export class ItemPF2e extends Item<ActorPF2e, ActiveEffectPF2e> {
// Rule Elements
if (!(isCreatureData(this.actor.data) && this.canUserModify(game.user, 'update'))) return;
const rules = RuleElements.fromRuleElementData(this.data.data?.rules ?? [], this.data);
const tokens = (this.actor as any).getActiveTokens(); // TODO: Fix any type
const tokens = this.actor.getActiveTokens(true); // TODO: Ensure that this affects all tokens of this actor in all scenes
const actorUpdates = {};
for (const rule of rules) {
rule.onCreate(this.actor.data, this.data, actorUpdates, Object.values(tokens));
rule.onCreate(this.actor.data, this.data, actorUpdates, tokens);
}
this.actor.update(actorUpdates);

Expand Down Expand Up @@ -171,10 +171,10 @@ export class ItemPF2e extends Item<ActorPF2e, ActiveEffectPF2e> {

if (!(isCreatureData(this.actor.data) && this.canUserModify(game.user, 'update'))) return;
const rules = RuleElements.fromRuleElementData(this.data.data?.rules ?? [], this.data);
const tokens = (this.actor as any).getActiveTokens(); // TODO: Fix any type
const tokens = this.actor.getActiveTokens(true); // TODO: Ensure that this affects all tokens of this actor in all scenes
const actorUpdates = {};
for (const rule of rules) {
rule.onDelete(this.actor.data, this.data, actorUpdates, Object.values(tokens));
rule.onDelete(this.actor.data, this.data, actorUpdates, tokens);
}
this.actor.update(actorUpdates);

Expand Down
2 changes: 1 addition & 1 deletion src/module/system/npc-skills-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class NPCSkillsEditor extends FormApplication<NPCPF2e> {

if (skillItem) {
skillContainer.remove();
await this.npc.deleteOwnedItem(skillItem.id);
await skillItem.delete();

this.render(true);
} else {
Expand Down
20 changes: 11 additions & 9 deletions src/pf2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,18 @@ Hooks.on('preCreateToken', (_scene: Scene, token: TokenData) => {
}
});

Hooks.on('updateToken', (tokenDocument: any, updateData: any, _options: EntityUpdateOptions, userID: string) => {
if ('disposition' in updateData && game.userId === userID) {
const actor = tokenDocument.getActor();
if (actor instanceof NPCPF2e) {
actor.updateNPCAttitudeFromDisposition(updateData.disposition);
Hooks.on(
'updateToken',
(tokenDocument: any, updateData: Partial<TokenData>, _options: EntityUpdateOptions, userID: string) => {
if (updateData.disposition && game.userId === userID) {
const actor = tokenDocument.getActor();
if (actor instanceof NPCPF2e) {
actor.updateNPCAttitudeFromDisposition(updateData.disposition);
}
}
}

game.pf2e.effectPanel.refresh();
});
game.pf2e.effectPanel.refresh();
},
);

Hooks.on('controlToken', () => {
game.pf2e?.effectPanel.refresh();
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/macros/raise-a-shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function raiseAShield(options: ActionDefaultOptions): Promise<void>
(effect) => effect.getFlag('core', 'sourceId') === ITEM_UUID,
);
if (existingEffect) {
await actor.deleteOwnedItem(existingEffect.id);
await existingEffect.delete();
return false;
} else {
const effect = await fromUuid(ITEM_UUID);
Expand Down

0 comments on commit 69d162f

Please sign in to comment.