Definitely! 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;
};
const findContains = (obj,filter,layer) => {
if(obj) {
let cx = obj.get('left'),
cy = obj.get('top');
filter = filter || (() => true);
layer = layer || 'gmlayer';
return findObjs({
_pageid: obj.get('pageid'),
_type: "graphic",
layer: layer
})
.filter(filter)
.reduce((m,o) => {
let l=o.get('left');
let t=o.get('top');
let w=o.get('width');
let h=o.get('height');
let ol=l-(w/2);
let or=l+(w/2);
let ot=t-(h/2);
let ob=t+(h/2);
if( ol <= cx && cx <= or
&& ot <= cy && cy <= ob
){
m.push(o);
}
return m;
},[]);
}
return [];
};
const onMoveGraphic = (obj,prev) => {
if(
['objects','gm'].includes(obj.get('layer')) && (
parseInt(obj.get('left')) !== parseInt(prev.left) ||
parseInt(obj.get('top')) !== parseInt(prev.top)
)
) {
let tiles = findContains(obj,(o)=>o.get('sides').length,'map');
if(tiles.length){
let sides = tiles[0].get('sides').split(/\|/).map(decodeURIComponent);
let nextSide = parseInt(tiles[0].get('currentSide'))+1;
if(nextSide>=sides.length){
nextSide = 0;
}
let imgsrc = getCleanImgsrc(sides[nextSide]);
if(imgsrc){
tiles[0].set({
currentSide: nextSide,
imgsrc: imgsrc
});
} else {
sendChat('',`/w gm <b>Error, failed to swap to marketplace side: <img style="max-width:3em;max-height:3em;" src="${sides[nextSide]}" />`);
}
}
}
};
on('change:graphic',onMoveGraphic);
});
This works by finding the graphics on the map layer (with multiple sides) under any token on the objects or gm layer that is moved, then cycling the image to the next one. Works only on the destination point, so move one tile at a time (or use the keyboard). It also doesn't check to see if the tile moved to is the same tile it's on already, but I could add that check. And it only changes the first tile it finds.