HopperComponent2D
Summary
Hopper 2D. Component which handles :
- actions performed in 2D relatively to the hopper. Such as :
- adding a hopper
- displaying the hopper context menu
- translating the hopper
- modifying the shape of the hopper ( moving / adding / removing points )
- the 2D rendering of the hopper
Constructor
HopperComponent2D
Syntax
HopperComponent2D
-
core
Summary
Parameters:
-
coreCoreWanaplan Core.
Item Index
Methods
- compute
- computeHopper
- destroy
- disable
- draw
- drawTarget
- enable
- getRoom
- getTargeted
- initialize
- isPointInHopper
- isPointInHopperSide
- onAddHopper
- onAddHopperClick
- onContextChanged
- onContextMenu
- onContextMenuPropertyChanged
- onContextMenuRemove
- onDblClick
- onDrag
- onDragEnd
- onDragStart
- onHover
- onHoverHopper
- onLeave
- onMouseMove
- startListening
- stopListening
- update
Methods
compute
Syntax
compute
()
Summary
Computes all the hoppers structures.
computeHopper
Syntax
computeHopper
-
hopper
Summary
Checks the hopper consistency and deletes it if the hopper is no longer valid.
- merges vertices that are close enough.
- removes the hopper if it has less than 3 vertices ( invalid hopper ).
Parameters:
-
hopperHopperStructureThe hopper structure to compute.
destroy
Syntax
destroy
()
Summary
Method called when the component is destroyeddisable
Syntax
disable
()
Summary
Disables the componentdraw
Syntax
draw
-
hopper -
ctx -
translation -
zoom -
selected
Summary
Draws the hopper.
Parameters:
-
hopperHopperStructureThe hopper structure.
-
ctxContext2DThe 2d context.
-
translationBABYLON.Vector2The translation of the canvas.
-
zoomNumberThe zoom level of the canvas.
-
selectedBooleanTrue if the hopper is currently selected, else false.
drawTarget
Syntax
drawTarget
-
hopper -
ctx -
zoom
Summary
Draws the hopper guide. It displays visual information on the hopper, depending on the context. Basically, it draws a highlight when the mouse is hovering a hopper element ( the whole hopper, a side , a point ).
Parameters:
-
hopperHopperStructureThe hopper structure.
-
ctxContext2DThe 2d context.
-
zoomNumberThe zoom level of the canvas.
enable
Syntax
enable
()
Summary
Enables the componentgetRoom
Syntax
Summary
Returns the roomStructure of the room containing the hopper. Will try to attach the hopper to a room if hopper.room is not defined.
If force flag is up, try to attach the hopper even if hopper.room is already set.
Parameters:
-
hopperHopperStructureThe hopper structure.
-
forceBooleanIf set to true, ignore the internal attribute and try to attach to a room.
Returns:
The room where the hopper is.
getTargeted
Syntax
Summary
Finds out if the given position is over an element handled by the componentParameters:
-
vectorVectorA position, usually the cursor's one.
Returns:
initialize
Syntax
initialize
()
Summary
Method called when Wanaplan is initialized. You don't need to call this method manually.isPointInHopper
Syntax
Summary
Tests the collision of a point with the area defined by the hopper.
Parameters:
-
vectorBABYLON.Vector2The point.
-
hopperHopperStructureThe hopper structure.
Returns:
True if the point collides, else false.
isPointInHopperSide
Syntax
Summary
Tests the collision of a point with the hopper's edges.
Parameters:
-
vectorBABYLON.Vector2The point.
-
hopperHopperStructureThe hopper structure.
onAddHopper
Syntax
onAddHopper
()
Summary
Adds new events callbacks when the user is in Hopper mode.
Triggered on event wnp.engine2d.onAddHopper
onAddHopperClick
Syntax
onAddHopperClick
-
event -
target -
mstate -
data
Summary
Adds a new hopper on click.
Triggered on event hopperComponent2D.add-hopper.click
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure added.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.
onContextChanged
Syntax
onContextChanged
-
context
Summary
Method called when the context is switched (2D -> 3D or 3D -> 2D)Parameters:
-
contextStringThe new context
onContextMenu
Syntax
onContextMenu
-
event -
target -
mstate -
data
Summary
Opens the context menu of the hopper.
Triggered on event HopperComponent2D.hopper.click
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.
onContextMenuPropertyChanged
Syntax
onContextMenuPropertyChanged
-
target -
property -
value
Summary
Called when a value is changed in the context menu of the hopper.
Parameters:
-
targetHopperStructureThe hopper structure.
-
propertyStringThe property changed.
-
valueNumber | StringThe new value.
onContextMenuRemove
Syntax
onContextMenuRemove
-
target
Summary
Called when the user closes the context menu.
Parameters:
-
targetHopperStructureThe hopper structure.
onDblClick
Syntax
onDblClick
-
event -
target -
mstate -
data
Summary
Adds a point on the hover contour when the user double clicks on it.
Triggered on event HopperComponent2D.hopper.dblclick
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure clicked.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.
onDrag
Syntax
onDrag
-
event -
target -
mstate -
data
Summary
Moves the hopper when it is dragged.
Triggered on event hopperComponent2D.hopper.drag
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure dragged.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.
onDragEnd
Syntax
onDragEnd
-
event -
target -
mstate -
data
Summary
Calls computeHopper when the user stop dragging.
Triggered on event hopperComponent2D.stair-hover.drag-end
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure dragged.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.
onDragStart
Syntax
onDragStart
-
event -
target -
mstate -
data
Summary
Adds new events callbacks when the dragging starts.
Triggered on event HopperComponent2D.hopper.drag-start
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure dragged.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.
onHover
Syntax
onHover
-
event -
target -
mstate -
data
Summary
Enables all the possible actions when the mouse hovers the hopper.
Triggered on event HopperComponent2D.hopper.hover
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure hovered.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.
onHoverHopper
Syntax
onHoverHopper
-
ctx -
translation -
zoom -
data
Summary
Highlights the hopper.
Triggered on event HopperComponent2D.hopper-hover.dynamic-draw
onLeave
Syntax
onLeave
-
event -
target -
mstate -
data
Summary
Disables all the possible actions when the mouse leaves the hopper.
Triggered on event HopperComponent2D.hopper.leave
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure leaved.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.
onMouseMove
Syntax
onMouseMove
-
event -
target -
mstate -
data
Summary
Moves the new hopper to add when the mouse moves.
Triggered on event hopperComponent2D.dynamic-stair.mouse-move
Parameters:
-
eventEventThe event caught.
-
targetHopperStructureThe hopper structure moved.
-
mstateObjectThe current state of the pointer.
-
dataObjectImportant data used to draw.