PhilippeKr / TorchLight

Slightly enhanced Torch and Light Module for Foundry VTT, based on the excellent work of RealDeuce on the Torch Module.
4 stars 18 forks source link

Bug on 0.8.7 after a couple of activations #33

Open gioppoluca opened 3 years ago

gioppoluca commented 3 years ago

Works correctly but a couple of test of activating de-activating and so on the module stop working with this error:

Clicked on the light button when the light is on.
foundry.js:19229 You are calling PlaceableObject#setFlag which has been deprecated in favor of Document#setFlag. Support will be removed in 0.9.0
setFlag @ foundry.js:19229
8foundry.js:19220 You are calling PlaceableObject#getFlag which has been deprecated in favor of Document#getFlag. Support will be removed in 0.9.0
getFlag @ foundry.js:19220
foundry.js:19202 You are calling PlaceableObject#update which has been deprecated in favor of Document#update or Scene#updateEmbeddedDocuments. Support will be removed in 0.9.0
update @ foundry.js:19202
foundry.js:8769 Error: [lVshhuXQdrAsSPdZ] TokenData lightColor "16777215" is not a valid hexadecimal color string
    at TokenData._validateField (data.mjs:376)
    at TokenData.validate (data.mjs:267)
    at ClientDatabaseBackend._preUpdateDocumentArray (foundry.js:8766)
    at ClientDatabaseBackend._updateEmbeddedDocuments (foundry.js:8728)
    at ClientDatabaseBackend.update (backend.mjs:153)
    at async Function.updateDocuments (document.mjs:365)
    at async TokenDocument5e.update (document.mjs:447)
_preUpdateDocumentArray @ foundry.js:8769
eduardopato41 commented 3 years ago

Hi, i'm not a developer but I figured out a "solution" when I encountered this situation. On the torchlight.js file on the module folder, I changed the line 367 inside the function storeTokenLighting: app.object.setFlag("torchlight", "InitialLightColor", app.object.light.color); to: app.object.setFlag("torchlight", "InitialLightColor", "");

Based in my understanding, the "remember the last config" thingy was messing with setting of the "new" color hex. But I don't really know haha

Gray-Geist commented 2 years ago

@eduardopato41 Thank you for this. I actually took a look into the code myself and found that it seems that line is no longer 367, but 376. Can you please confirm how to fix the specific promises.push(app.object.document.setFlag("torchlight", "InitialLightColor that is below?

// Store the initial status of illumination for the token to restore if all light sources are extinguished async function storeTokenLighting() { let promises = []; const tokenData = app.object.data; promises.push(app.object.document.setFlag("torchlight", "InitialBrightRadius", tokenData.brightLight)); promises.push(app.object.document.setFlag("torchlight", "InitialDimRadius", tokenData.dimLight)); promises.push(app.object.document.setFlag("torchlight", "InitialLightColor", tokenData.lightColor ? tokenData.lightColor.toString(16).padStart(6, 0) : null)); promises.push(app.object.document.setFlag("torchlight", "InitialColorIntensity", Math.sqrt(tokenData.lightAlpha))); promises.push(app.object.document.setFlag("torchlight", "InitialLightAngle", tokenData.lightAngle)); promises.push(app.object.document.setFlag("torchlight", "InitialAnimationType", tokenData.lightAnimation.type ?? null)); promises.push(app.object.document.setFlag("torchlight", "InitialAnimationSpeed", tokenData.lightAnimation.speed)); promises.push(app.object.document.setFlag("torchlight", "InitialAnimationIntensity", tokenData.lightAnimation.intensity));