Skip to content

Commit

Permalink
[#1626, 1689] Adjust how some drop errors are handled, remove develop…
Browse files Browse the repository at this point in the history
…ment logging
  • Loading branch information
arbron committed Aug 27, 2022
1 parent 5597ddf commit c17285c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
22 changes: 11 additions & 11 deletions module/advancement/advancement-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class AdvancementConfig extends FormApplication {
super.activateListeners(html);

// Remove an item from the list
if ( this.options.dropKeyPath ) html.on("click", ".item-delete", this._onItemDelete.bind(this));
if ( this.options.dropKeyPath ) html.on("click", "[data-action='delete']", this._onItemDelete.bind(this));
}

/* -------------------------------------------- */
Expand Down Expand Up @@ -132,7 +132,6 @@ export default class AdvancementConfig extends FormApplication {
const updates = { configuration: await this.prepareConfigurationUpdate({
[this.options.dropKeyPath]: items.filter(uuid => uuid !== uuidToDelete)
}) };
console.log(updates);
await this.advancement.update(updates);
this.render();
}
Expand All @@ -148,7 +147,7 @@ export default class AdvancementConfig extends FormApplication {

/** @inheritdoc */
async _onDrop(event) {
if ( !this.options.dropKeyPath ) return console.error(
if ( !this.options.dropKeyPath ) throw new Error(
"AdvancementConfig#options.dropKeyPath must be configured or #_onDrop must be overridden to support"
+ " drag and drop on advancement config items."
);
Expand All @@ -164,14 +163,17 @@ export default class AdvancementConfig extends FormApplication {
if ( data.type !== "Item" ) return false;
const item = await Item.implementation.fromDropData(data);

const verified = this._verifyDroppedItem(event, item);
if ( !verified ) return false;
try {
this._validateDroppedItem(event, item);
} catch(err) {
return ui.notifications.error(err.message);
}

const existingItems = foundry.utils.getProperty(this.advancement.data.configuration, this.options.dropKeyPath);

// Abort if this uuid is the parent item
if ( item.uuid === this.item.uuid ) {
return ui.notifications.warn(game.i18n.localize("DND5E.AdvancementItemGrantRecursiveWarning"));
return ui.notifications.error(game.i18n.localize("DND5E.AdvancementItemGrantRecursiveWarning"));
}

// Abort if this uuid exists already
Expand All @@ -186,14 +188,12 @@ export default class AdvancementConfig extends FormApplication {
/* -------------------------------------------- */

/**
* Called when an item is dropped to verify the Item before it is saved.
* Called when an item is dropped to validate the Item before it is saved. An error should be thrown
* if the item is invalid.
* @param {Event} event Triggering drop event.
* @param {Item5e} item The materialized Item that was dropped.
* @returns {boolean} Is the dropped Item valid?
* @protected
*/
_verifyDroppedItem(event, item) {
return true;
}
_validateDroppedItem(event, item) {}

}
5 changes: 2 additions & 3 deletions module/advancement/types/item-grant.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ export class ItemGrantConfig extends AdvancementConfig {
/* -------------------------------------------- */

/** @inheritdoc */
_verifyDroppedItem(event, item) {
_validateDroppedItem(event, item) {
if ( this.advancement.constructor.VALID_TYPES.has(item.type) ) return true;
const type = game.i18n.localize(`ITEM.Type${item.type.capitalize()}`);
ui.notifications.warn(game.i18n.format("DND5E.AdvancementItemTypeInvalidWarning", { type }));
return false;
throw new Error(game.i18n.format("DND5E.AdvancementItemTypeInvalidWarning", { type }));
}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/advancement/item-grant-config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<li class="item flexrow" data-item-uuid="{{this}}">
<div class="item-name">{{{dnd5e-linkForUuid this}}}</div>
<div class="item-controls flexrow">
<a class="item-control item-delete" title="{{localize 'DND5E.ItemDelete'}}">
<a class="item-control item-action" data-action="delete" title="{{localize 'DND5E.ItemDelete'}}">
<i class="fas fa-trash"></i>
</a>
</div>
Expand Down

0 comments on commit c17285c

Please sign in to comment.