I made an error in calculating the new position that caused the formation to appear mirrored. This is now fixed...
Code: Select all
[h: abort(isGM())]
[h: tokenId = if(getSelected()=="",getPC(),getSelected())]
[h: tokenNm = ""]
[h: CoordinatesInUnits = 0]
[h: jsonAllOffsets = ""]
[h: referenceToken = listGet(tokenId, 0)]
[h: xOrigin = getTokenX(CoordinatesInUnits, referenceToken)]
[h: yOrigin = getTokenY(CoordinatesInUnits, referenceToken)]
[h, foreach(in,tokenId), code: {
[h: tokenNm = listAppend(tokenNm,getName(in))]
[h: xOffset = getTokenX(CoordinatesInUnits, in)]
[h: yOffset = getTokenY(CoordinatesInUnits, in)]
[h: jsonOffset = json.set("", "x", xOrigin - xOffset, "y", yOrigin - yOffset)]
[h: jsonAllOffsets = json.set( jsonAllOffsets, in, jsonOffset )]
}]
[h: Lst = ""]
[h: in =0]
[h, while(tbl("Mapa",in)!=tbl("Mapa",in+2)),code:{
[h: in=in+1]
[h: Lst=listAppend(Lst,listGet(tbl("Mapa",in),3))]
}]
[h: bla=input(
"Fichas|"+tokenNm+"||Label",
"map|"+Lst+"|Destino|Radio"
)]
[h: abort(bla)]
[h: map=map+1]
[h: Dest=listGet(tbl("Mapa",map),0)]
[h: x=listGet(tbl("Mapa",map),1)]
[h: y=listGet(tbl("Mapa",map),2)]
[r,if(getCurrentMapName()==Dest),code:{
[h,foreach(in,tokenId),code:{
[h: jsonOffset = json.get(jsonAllOffsets, in)]
[h: xOffset = json.get(jsonOffset, "x")]
[h: yOffset = json.get(jsonOffset, "y")]
[moveToken(x-xOffset, y-yOffset,0,in)]
}]
[r:tokenNm] movido(s) a [r:Dest] [goto(x,y)]
};{
[h,foreach(in,tokenId),code:{
[h: jsonOffset = json.get(jsonAllOffsets, in)]
[h: xOffset = json.get(jsonOffset, "x")]
[h: yOffset = json.get(jsonOffset, "y")]
[moveTokenToMap(in, Dest, x-xOffset, y-yOffset)]
}]
[r:tokenNm] llevado(s) al mapa [r:setCurrentMap(Dest)] [goto(x,y)]
}]