foundry-vtt-tidy-5e-sheets icon indicating copy to clipboard operation
foundry-vtt-tidy-5e-sheets copied to clipboard

Lazy Money Compatability

Open KellethDregar opened this issue 11 months ago • 7 comments

Since Lazy money is no longer built into the module, are there plans for compatibility with the standalone Lazy Money module?

KellethDregar avatar Mar 05 '24 09:03 KellethDregar

This is probably on my side

p4535992 avatar Mar 05 '24 10:03 p4535992

This is probably on my side

Let me know if I can help. If I'm missing anything in the API, I can add it in.

kgar avatar Mar 05 '24 15:03 kgar

Quick update: We found an approach that might work really well, and p4535992 is trying it out.

kgar avatar Mar 13 '24 01:03 kgar

Still in a waiting pattern for this. Adding repo for quicker cross-referencing: https://github.com/p4535992/foundryvtt-lazymoney-dnd5e

kgar avatar Mar 29 '24 20:03 kgar

Cross-post: https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/issues/9

kgar avatar Mar 29 '24 20:03 kgar

Nothing to much problems with others modules using the hooks. i tried the following code, but the preUpdateActor, but it seem to not work well with other modules, and also pass to me the number no the string.

Hooks.on("preUpdateActor", (actor, update, ...rest) => {
    if (!game.settings.get(CONSTANTS.MODULE_ID, "enable")) {
        return;
    }
    if (game.system.id === "dnd5e") {
        const currency = foundry.utils.getProperty(update, API.ACTOR_CURRENCY_ATTRIBUTE) || undefined;
        if (currency) {
            const currencyActor = foundry.utils.getProperty(actor, API.ACTOR_CURRENCY_ATTRIBUTE) || {};
            Object.entries(currency).forEach(([key, value]) => {
               // Also i must do this because the update object has number not string
                const currencyData = foundry.utils.getProperty(currency, key);
                const currencyActorData = foundry.utils.getProperty(currencyActor, key);
                let currencyDataS = String(currencyData);
                if(currencyData < currencyActorData) {
                    currencyDataS = "-"+(currencyActorData-currencyData);
                }
                else if(currencyData > currencyActorData) {
                    currencyDataS = "+"+(currencyData-currencyActorData);
                }
                else if(currencyData === currencyActorData) {
                    currencyDataS = "="+(currencyData);
                }
                LazyMoneyHelpers.manageCurrencySync(actor, currencyDataS, key);
            });
            foundry.utils.setProperty(update, API.ACTOR_CURRENCY_ATTRIBUTE, undefined);
        }
    } 
    else {
        Logger.warn(`The system '${game.system.id }' is not supported open a issue on the project`, false);
    }
    // TODO ADD OTHER SYSTEM
});

the best solution is some html selector i can use on the tidysheet5e like i'm doing on the standard one with this code:

export function applyLazyMoney(app, html, actorData, itemSelector) {
    if (!game.settings.get(CONSTANTS.MODULE_ID, "enable")) {
        return;
    }
    html.find(itemSelector).off("change"); // Stop default sheet behaviour 
    html.find(itemSelector).change(
        {
            app: app,
            data: actorData,
        },
        _onChangeCurrency, // my code
    );
}

function _onChangeCurrency(ev) {
    const input = ev.target;
    const actor = ev.data.app.actor;
    const sheet = ev.data.app.options;
    const denom = input.name.split(".")[2];
    const value = input.value;
   // DO SOMETHING
}

p4535992 avatar Mar 30 '24 10:03 p4535992

I'll see what I can do to make the necessary changes to allow lazy money to hook in and control the currency inputs. I should be able to provide something that will work for your use case, but because of the way svelte is with event handling, I will need a little extra time to figure out an approach. Directly calling off() via jquery will typically not remove svelte's event wiring, to my knowledge. Forien and I learned this with Item Macro.

I'll be in touch when I've got something released for you to test. Thanks for posting the sample code and recommendations. I hope to help get this resolved soon. Also, for everyone else reading, I apologize for the wait. Tidy development has been going nonstop, especially with dnd5e 3.x having recently come out.

kgar avatar Apr 02 '24 03:04 kgar