Code Monkey home page Code Monkey logo

Comments (6)

Forien avatar Forien commented on July 26, 2024 1

Fixed in v0.2.0

from ammo-swapper.

davidR1974 avatar davidR1974 commented on July 26, 2024

Have tested a bit around that..
When clicking on ammo for a weapon, the ammunition is correctly updated (can be confirmed in character sheet or with Token HUD that shows the correct number of "charges" on the bow)
However ammoSwapper does not renders correctly after the update of the character sheet
If you hit refresh (F5) it shows correct ammo.

Same when changing the amount of ammo in character sheet. ammoSwapper does not reflect automatically but does if you take another action (like swapping ammo)

Maybe a matter of forcing rendering after ammo selection.

from ammo-swapper.

davidR1974 avatar davidR1974 commented on July 26, 2024

managed to make it work by calling the setAmmunition function in the html on click ammo event listener

    html.on('click', '.ammo', (event) => {
      event.stopPropagation();
      const ammo = $(event.currentTarget);
      const weapon = ammo.closest('.weapon');
      const weaponId = weapon.data("weapon-id");
      const ammoId = ammo.data("ammo-id");
      this.manager.setAmmunition(weaponId, ammoId);
      this.manager.setAmmunition(weaponId, ammoId);    /* This line new */
    });

from ammo-swapper.

benpope3 avatar benpope3 commented on July 26, 2024

Thanks for looking at this davidR1974. Curious why the "this.manager.setAmmunition(weaponId, ammoId);" added line needs to be repeated twice as shown above. I can see where it gets inserted in the original code, but how do I add this patch to the code in my world if the module is not updated?

from ammo-swapper.

davidR1974 avatar davidR1974 commented on July 26, 2024

i modified the AmmoSwapper.js ( ($FOUNDRYDATA)\modules\workshop-ammo-swapper\modules )

as for why you need two calls, i have no explanation and it's probably not the right way correct this (just a workaround with my limited knowledge of the framework).
The first call get things right (ammo is changed in the item sheet if you open it) but the Ammoswapper does not render to reflect those changes. That second call somewhat forces that.

from ammo-swapper.

Vilyandil avatar Vilyandil commented on July 26, 2024

i modified the AmmoSwapper.js ( ($FOUNDRYDATA)\modules\workshop-ammo-swapper\modules )

as for why you need two calls, i have no explanation and it's probably not the right way correct this (just a workaround with my limited knowledge of the framework).
The first call get things right (ammo is changed in the item sheet if you open it) but the Ammoswapper does not render to reflect those changes. That second call somewhat forces that.

I think i have a somewhat explanation to what is happening here.
I used your workaround for a while, then today i tried to understand what happens, and I think is the following:
->click on new ammo triggers ammo swap
->ammo swap triggers re-rendering (hooked event), render is performed with old ammo because it has not changed yet
Maybe weapon.update() (called in setAmmunition) calls an handler on which the rendering is hooked before the actual swap, but i'm wildly guessing since i don't know the framework.
So I tried to force the rendering to happen after the ammo-update chain by tampering with Init.js, so that when the rendering is requested finds the new ammo: I changed the hooks on "updateActor" and "updateOwnedItem" in this way:

`
Hooks.on("updateActor", (actor, data, options, userId) => {
if (actor.id === game.user.character?.id)
setTimeout(()=>{ui.ammoSwapper?.render()});
});

Hooks.on("updateOwnedItem", (actor, item, data, options, userId) => {
if (actor.id === game.user.character?.id)
setTimeout(()=>{ui.ammoSwapper?.render()});
});
`
That setTimeout avoids the immediate render() execution, which is scheduled after the current execution chain.
in the attachment you can find the modified Init.js: init.zip

from ammo-swapper.

Related Issues (8)

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.