Overriding onDropItem & onSortItem

You'd override them in your sheet class.
7 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Mana
Mana3y ago
There's no such thing as preventDefault() global function. Overriding itself prevents the normal function unless you call it.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Calego
Calego3y ago
This is what that super thing you've seen around is for. Without the "super.whatever()", you're completely overriding the method and none of the inherited behavior will fire
Calego
Calego3y ago
super - JavaScript | MDN
The super keyword is used to access and call functions on an object's parent.
Calego
Calego3y ago
class MySheetClass extends ActorSheet {
// ...

/** Extends `activateListeners` with additional logic */
activateListeners(html) {
super.activateListeners(html); // effectively calling `ActorSheet`'s `activateListeners` method

_someOtherMethod(html);
}

/** Replaces `_onDropItem` with different logic */
_onDropItem() {
// custom logic without the `super`
}
}
class MySheetClass extends ActorSheet {
// ...

/** Extends `activateListeners` with additional logic */
activateListeners(html) {
super.activateListeners(html); // effectively calling `ActorSheet`'s `activateListeners` method

_someOtherMethod(html);
}

/** Replaces `_onDropItem` with different logic */
_onDropItem() {
// custom logic without the `super`
}
}
What you saw with Inventory+ and libwrapper is how modules tend to override methods in existing classes which they do not control. Inventory+ doesn't have control of the ActorSheet5e class, so it had to work around that by 'monkeypatching' the method after it's already been defined. Since you're writing a system, it's unlikely you'll need libwrapper. Systems are the first-class citizens and don't really worry much about conflicts, modules are second class and do have to worry about conflicts.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View