-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shatter tool #142
Shatter tool #142
Changes from all commits
fbe1672
69e8ec6
2a85686
44c214d
a21e867
7a0b4aa
43c328d
899c29c
58ee6ba
f057811
b2571e7
5e9787f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,30 @@ import { | |
BLOCK_HOVER_LAYER_ID, | ||
BLOCK_HOVER_LAYER_ID_CHILD, | ||
} from "@constants/layers"; | ||
import { ActiveTool } from "@/app/constants/types"; | ||
|
||
/* | ||
MapEvent handling; these functions are called by the event listeners in the MapComponent | ||
*/ | ||
|
||
/** | ||
* Get the layer IDs to paint based on whether we have | ||
* a shatterable map (based on whether a child layer is | ||
* present) and the active tool. If the active tool is | ||
* shatter, we only want to paint the shatterable layer. | ||
* | ||
* @param child_layer - string | undefined | null, the child layer | ||
* @param activeTool - ActiveTool, the active tool | ||
* @returns string[], the layer IDs to paint | ||
*/ | ||
function getLayerIdsToPaint( | ||
child_layer: string | undefined | null, | ||
activeTool: ActiveTool, | ||
) { | ||
if (activeTool === "shatter") { | ||
return [BLOCK_HOVER_LAYER_ID]; | ||
} | ||
|
||
*/ | ||
function getLayerIdsToPaint(child_layer: string | undefined | null) { | ||
return child_layer | ||
? [BLOCK_HOVER_LAYER_ID, BLOCK_HOVER_LAYER_ID_CHILD] | ||
: [BLOCK_HOVER_LAYER_ID]; | ||
|
@@ -41,9 +56,13 @@ export const handleMapClick = ( | |
const mapStore = useMapStore.getState(); | ||
const activeTool = mapStore.activeTool; | ||
const sourceLayer = mapStore.mapDocument?.parent_layer; | ||
const handleShatter = mapStore.handleShatter; | ||
|
||
if (activeTool === "brush" || activeTool === "eraser") { | ||
const paintLayers = getLayerIdsToPaint(mapStore.mapDocument?.child_layer); | ||
const paintLayers = getLayerIdsToPaint( | ||
mapStore.mapDocument?.child_layer, | ||
activeTool, | ||
); | ||
const selectedFeatures = mapStore.paintFunction( | ||
map, | ||
e, | ||
|
@@ -57,6 +76,12 @@ export const handleMapClick = ( | |
SelectZoneAssignmentFeatures(mapStore); | ||
}); | ||
} | ||
} else if (activeTool === "shatter") { | ||
const documentId = mapStore.mapDocument?.document_id; | ||
const featureId = e.features?.[0].id?.toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PP: Highlight on mouse move? Eg. Select features, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
if (documentId && featureId) { | ||
handleShatter(documentId, [featureId]); | ||
} | ||
} else { | ||
// tbd, for pan mode - is there an info mode on click? | ||
} | ||
|
@@ -129,15 +154,18 @@ export const handleMapMouseMove = ( | |
const setHoverFeatures = mapStore.setHoverFeatures; | ||
const isPainting = mapStore.isPainting; | ||
const sourceLayer = mapStore.mapDocument?.parent_layer; | ||
const paintLayers = getLayerIdsToPaint(mapStore.mapDocument?.child_layer); | ||
const paintLayers = getLayerIdsToPaint( | ||
mapStore.mapDocument?.child_layer, | ||
activeTool, | ||
); | ||
const selectedFeatures = mapStore.paintFunction( | ||
map, | ||
e, | ||
mapStore.brushSize, | ||
paintLayers, | ||
); | ||
const isBrushingTool = | ||
sourceLayer && ["brush", "eraser"].includes(activeTool); | ||
sourceLayer && ["brush", "eraser", "shatter"].includes(activeTool); | ||
if (isBrushingTool) { | ||
setHoverFeatures(selectedFeatures); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PP: This could also be in the map component and use tailwind
cursor-x
propertiesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this suggestions but I'm sort of in a hurry so created new issue #145 so we can do this later