DANG IT!. I just spent the last 45 minutes typing a 3 page response to this with many many examples and details... and the browser lost it. =( So, I'm going to summarize and say "Oh, that won't work, try this:" on('ready', () => {
const getCleanImgsrc = (imgsrc) => {
let parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)([^?]*)(\?[^?]+)?$/);
if(parts) {
return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`);
}
return;
};
on('chat:message', (msg) => {
if('api' !== msg.type || !playerIsGM(msg.playerid) || !/^!update-tokens-to-default/i.test(msg.content)){
return;
}
let characters = findObjs({type:'character'});
let handleCharacter = ()=>{
let c = characters.shift();
if(c){
c.get('defaulttoken',(deftok) => {
const dt = JSON.parse(deftok);
const dtimgsrc = getCleanImgsrc((dt||{imgsrc:’’}).imgsrc);
if(dtimgsrc){
findObjs({
type: 'graphic',
represents: c.id
}).forEach((t)=>{
if(getCleanImgsrc(t.get('imgsrc')) !== dtimgsrc){
t.set({imgsrc: dtimgsrc});
}
});
}
});
}
if(characters.length){
_.defer(handleCharacter);
}
};
handleCharacter();
});
});
Slightly more details: I forgot that defaulttoken was one of the properties you have to fetch asynchronously, so it won't work to filter with it. The intent of that line was go get a list of all the characters, then trim it down to only the ones with a default token with an imgsrc in a user library. How well do you know Javascript? Since I'm super frustrated about my great description getting sacrificed on the alter of the internet, rather than recreate it I'll just ask that and tailor to what you know. =D If the answer is "I don't really know Javascript that well" then I'll come back later after a few shots of something and post a better discussion then! =D