Added token sorted based off of last modified

This commit is contained in:
Mitchell McCaffrey 2020-08-27 17:56:59 +10:00
parent 9ab584cbe7
commit b26a89f8ca

View File

@ -188,11 +188,29 @@ function Map({
}
// Sort so vehicles render below other tokens
function sortMapTokenStates(a, b) {
function sortMapTokenStates(a, b, draggingTokenOptions) {
const tokenA = tokensById[a.tokenId];
const tokenB = tokensById[b.tokenId];
if (tokenA && tokenB) {
// If one token is a vehicle and one isn't sort vehicles below
if (tokenB.isVehicle !== tokenA.isVehicle) {
return tokenB.isVehicle - tokenA.isVehicle;
} else if (
draggingTokenOptions &&
draggingTokenOptions.tokenState.id === a.id
) {
// If dragging token a move above
return 1;
} else if (
draggingTokenOptions &&
draggingTokenOptions.tokenState.id === b.id
) {
// If dragging token b move above
return -1;
} else {
// Else sort so last modified is on top
return a.lastModified - b.lastModified;
}
} else if (tokenA) {
return 1;
} else if (tokenB) {
@ -205,7 +223,7 @@ function Map({
const mapTokens = mapState && (
<Group>
{Object.values(mapState.tokens)
.sort(sortMapTokenStates)
.sort((a, b) => sortMapTokenStates(a, b, draggingTokenOptions))
.map((tokenState) => (
<MapToken
key={tokenState.id}