Comments (6)
Fixed in v0.2.0
from ammo-swapper.
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.
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.
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.
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.
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)
- Style - show a list of options for Weapons ranged when click on the weapon and show a list of ammunition when click on the little icon of the ammunition
- [BUG] Module does not appear on some machines HOT 2
- Make the bar draggable or otherwise movable to other areas of the screen HOT 1
- Display charges for weapons that have it HOT 1
- Add in Hud For GM aswell HOT 1
- [BUG] Does not work with PF2E anymore ("An error occurred while rendering AmmoSwapper. Cannot read properties of undefined (reading 'value')") HOT 2
- HUD not showing up HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ammo-swapper.