Fixed bug with tokens that were attatched to a vehicle being rendered on top of fog

This commit is contained in:
Mitchell McCaffrey 2020-07-20 19:14:46 +10:00
parent 7252efc7e9
commit 58ac649aa8
2 changed files with 36 additions and 33 deletions

View File

@ -1,4 +1,5 @@
import React, { useState, useContext, useEffect } from "react";
import { Group } from "react-konva";
import MapControls from "./MapControls";
import MapInteraction from "./MapInteraction";
@ -208,37 +209,39 @@ function Map({
}
}
const mapTokens =
mapState &&
Object.values(mapState.tokens)
.sort(sortMapTokenStates)
.map((tokenState) => (
<MapToken
key={tokenState.id}
token={tokensById[tokenState.tokenId]}
tokenState={tokenState}
tokenSizePercent={tokenSizePercent}
onTokenStateChange={onMapTokenStateChange}
onTokenMenuOpen={handleTokenMenuOpen}
onTokenDragStart={(e) =>
setDraggingTokenOptions({
dragging: true,
tokenState,
tokenGroup: e.target,
})
}
onTokenDragEnd={() =>
setDraggingTokenOptions({
...draggingTokenOptions,
dragging: false,
})
}
draggable={
selectedToolId === "pan" && !(tokenState.id in disabledTokens)
}
mapState={mapState}
/>
));
const mapTokens = mapState && (
<Group>
{Object.values(mapState.tokens)
.sort(sortMapTokenStates)
.map((tokenState) => (
<MapToken
key={tokenState.id}
token={tokensById[tokenState.tokenId]}
tokenState={tokenState}
tokenSizePercent={tokenSizePercent}
onTokenStateChange={onMapTokenStateChange}
onTokenMenuOpen={handleTokenMenuOpen}
onTokenDragStart={(e) =>
setDraggingTokenOptions({
dragging: true,
tokenState,
tokenGroup: e.target,
})
}
onTokenDragEnd={() =>
setDraggingTokenOptions({
...draggingTokenOptions,
dragging: false,
})
}
draggable={
selectedToolId === "pan" && !(tokenState.id in disabledTokens)
}
mapState={mapState}
/>
))}
</Group>
);
const tokenMenu = (
<TokenMenu

View File

@ -78,12 +78,12 @@ function MapToken({
const mountChanges = {};
if (token && token.isVehicle) {
const layer = tokenGroup.getLayer();
const parent = tokenGroup.getParent();
const mountedTokens = tokenGroup.find(".token");
for (let mountedToken of mountedTokens) {
// Save and restore token position after moving layer
const position = mountedToken.absolutePosition();
mountedToken.moveTo(layer);
mountedToken.moveTo(parent);
mountedToken.absolutePosition(position);
mountChanges[mountedToken.id()] = {
...mapState.tokens[mountedToken.id()],