KayelGee / token-attacher

MIT License
11 stars 18 forks source link

More Aggressive Purge and/or Better Multilevel Tokens Purge Needed #45

Closed tjlanza closed 3 years ago

tjlanza commented 3 years ago

Foundry 0.8.7, TA 4.1.2, MLT 1.5.1

image

With the understanding that MLT and TA are not completely compatible, there is a need for a more powerful tool to correct TA issues when conflicts arise. I had a token with a few attached tokens that did not get loaded properly despite TA saying it had (an issue issue I will post separately when I can reproduce it reliably). When I tried to move them, I got the above error message, and did as it says.

Unfortunately, it did not work. I deleted all the TA-configured tokens in the scene I was working with, but it didn't help. In my current world, I now get that message six to ten times (or more) any time I change scenes, alter a scene's properties, or refresh my browser. The message occurs even with all scenes removed from the navigation bar and only a single non-MLT Obviously, the error goes away with MLT disabled.

I suspect there's an issue with cloned tokens, as the tokens were in an MLT cloning region. Unfortunately, I don't have the technical expertise to provide any specifics.

In my use case, MLT is the higher priority of the two modules - TA provides convenience, but MLT provides important functionality. I would like a more aggressive method of removing TA-related flags from any and all actors and token. At this point, a scorched earth nuclear option would be acceptable. I don't have a problem setting things up again, but this persistent error message makes TA effectively unusable. The only option available to me now appears to be disabling TA and never using it again.

tjlanza commented 3 years ago

With TA disabled, a browser refresh is now giving the below errors. Fortunately, it only happens once and only on a browser refresh, instead of 6+ times every scene transition.

image

image

While it's likely caused by something MLT-related, as TA is disabled, I'm posting it here because TA is the genesis of the issue. I suspect it is the object that the "(TA)Delete missing Links" macro failed to clean up.

Note that I have created an issue on the MLT git and provided a link to this issue.

KayelGee commented 3 years ago

I haven't done any testing related to this yet but I want to say that there's a foundry core bug in 0.8.7: When deleting doors an exception will be thrown and only one door will seemingly be deleted. The rest will remain until a page refresh. The second error you posted may stem from that. You have to refresh after deleting a door or you'll see a lot of unexpected behaviour.

I honestly don't intend to touch foundry 0.8.7 because this bug is really annoying to work with when you use prefabs.

tjlanza commented 3 years ago

I haven't done any testing related to this yet but I want to say that there's a foundry core bug in 0.8.7: When deleting doors an exception will be thrown and only one door will seemingly be deleted. The rest will remain until a page refresh. The second error you posted may stem from that. You have to refresh after deleting a door or you'll see a lot of unexpected behaviour.

I honestly don't intend to touch foundry 0.8.7 because this bug is really annoying to work with when you use prefabs.

I only use TA for token-token attachments; there are no doors involved.

KayelGee commented 3 years ago

That's good to know. Here's a macro that you can use to remove all token attacher related data in the scene:

(async () =>{       
    const base_layer =  canvas.getLayerByEmbeddedName("Token");
    const moduleName = 'token-attacher';
    let updates = {};
    const pushUpdate = (key, update, updateObj) => {
        if(!updateObj.hasOwnProperty(key)) updateObj[key] = [];
        const dupIndex = updateObj[key].findIndex(item => update._id=== item._id);
        if(dupIndex === -1) updateObj[key].push(update);
    };
    for (const type of ["AmbientLight", "AmbientSound", "Drawing", "MeasuredTemplate", "Note", "Tile", "Token", "Wall"]) {
        const layer = canvas.getLayerByEmbeddedName(type);
        const deleteLinks = (layer) => {
                for (let i = 0; i < layer.placeables.length; i++) {
                    const element = layer.placeables[i];
                    if(getProperty(element, `data.flags.${moduleName}`)) pushUpdate(type, {_id:element.data._id, [`flags.-=${moduleName}`]:null}, updates);
                }
            }
        deleteLinks(layer);
        if(type === "Tile"){
            deleteLinks(canvas.foreground);
        }
    }
    //Fire updates
    for (const key in updates){
        if (updates.hasOwnProperty(key)) {
            await canvas.scene.updateEmbeddedDocuments(key, updates[key], {[moduleName]:{}});
        }
    }
})();

See if that fixes your issue.

tjlanza commented 3 years ago

That seems to have done the job. In fact, tokens appeared that were not visible before running it - tokens that correspond to the one I was trying to work with when things went all squirrelly. I'm guessing they were MLT's cloned tokens or something that was linked to them somehow. Either way, when I deleted them, the other message went away as well. Thanks.

KayelGee commented 3 years ago

I'll add the purge function to the gm menu and also the purge macro to the example macros(so one can purge even without token attacher being enabled) in the next update.

If you find a way to recreate the issue you were having, open a new issue for that and hopefully we can work out a fix.

KayelGee commented 3 years ago

Purge macro and button in gm menu will be in next update.