Skip to content

Commit

Permalink
release: v1.4.6 use new libwrapper chain property
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez committed Apr 9, 2021
1 parent cc47fac commit 013ce78
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions betterrolls5e/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "This module overhauls rolls for the D&D 5e system, allowing \"dual rolls\" for d20 rolls, buttons that support full output to chat, and customization for said outputs.",
"minimumCoreVersion": "0.7.7",
"compatibleCoreVersion": "0.7.9",
"version": "1.4.5",
"version": "1.4.6",
"author": "Red Reign#5128",
"languages": [
{
Expand Down Expand Up @@ -57,5 +57,5 @@
"packs": [],
"url": "https://github.com/RedReign/FoundryVTT-BetterRolls5e/tree/master/betterrolls5e",
"manifest": "https://raw.githubusercontent.com/RedReign/FoundryVTT-BetterRolls5e/master/betterrolls5e/module.json",
"download": "https://github.com/RedReign/FoundryVTT-BetterRolls5e/releases/download/v1.4.5/module.zip"
"download": "https://github.com/RedReign/FoundryVTT-BetterRolls5e/releases/download/v1.4.6/module.zip"
}
7 changes: 3 additions & 4 deletions betterrolls5e/scripts/patching/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export function patchCoreFunctions() {
* @param {*} fn A curried function that takes the original and returns a function to pass to libwrapper
*/
function override(target, fn) {
const original = libWrapper._create_wrapper?.(target, "betterrolls5e")._wrapped ?? eval(target);
libWrapper.register("betterrolls5e", target, fn(original), "OVERRIDE");
libWrapper.register("betterrolls5e", target, fn, "OVERRIDE", {chain: true});
}

/**
Expand All @@ -26,7 +25,7 @@ function override(target, fn) {
* @param {} wrapped
* @returns
*/
const itemRoll = (defaultRoll) => function (options) {
function itemRoll(defaultRoll, options) {
// Handle options, same defaults as core 5e
options = mergeObject({
configureDialog: true,
Expand Down Expand Up @@ -55,7 +54,7 @@ const itemRoll = (defaultRoll) => function (options) {
* @param {} wrapped
* @returns
*/
const itemRollAttack = (defaultRoll) => async function (options) {
async function itemRollAttack(defaultRoll, options) {
// Call the default version if chatMessage is enabled
if (options?.chatMessage !== false) {
return defaultRoll.bind(this)(options);
Expand Down
4 changes: 2 additions & 2 deletions betterrolls5e/scripts/patching/libWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Hooks.once('init', () => {
libWrapper = class {
static get is_fallback() { return true };

static register(module, target, fn, type="MIXED") {
static register(module, target, fn, type="MIXED", {chain=undefined}={}) {
const is_setter = target.endsWith('#set');
target = !is_setter ? target : target.slice(0, -4);
const split = target.split('.');
Expand All @@ -37,7 +37,7 @@ Hooks.once('init', () => {
if(!descriptor) throw `libWrapper Shim: '${target}' does not exist or could not be found.`;

let original = null;
const wrapper = (type == 'OVERRIDE') ? function() { return fn.call(this, ...arguments); } : function() { return fn.call(this, original.bind(this), ...arguments); }
const wrapper = (chain ?? type != 'OVERRIDE') ? function() { return fn.call(this, original.bind(this), ...arguments); } : function() { return fn.call(this, ...arguments); };

if(!is_setter) {
if(descriptor.value) {
Expand Down

0 comments on commit 013ce78

Please sign in to comment.