Giter Club home page Giter Club logo

Comments (7)

p4535992 avatar p4535992 commented on August 21, 2024 1

This is probably on my side

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on August 21, 2024 1

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

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on August 21, 2024

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.

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on August 21, 2024

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

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on August 21, 2024

Cross-post: p4535992/foundryvtt-lazymoney-dnd5e#9

from foundry-vtt-tidy-5e-sheets.

p4535992 avatar p4535992 commented on August 21, 2024

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
}

from foundry-vtt-tidy-5e-sheets.

kgar avatar kgar commented on August 21, 2024

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.

from foundry-vtt-tidy-5e-sheets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.