API Docs for: 2.7.3
Show:

HopperComponent2D Class

Extends BaseComponent2D
Module: Component
Parent Module: Wanaplan

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

(
  • core
)

Parameters:

  • core Core

    Wanaplan Core.

Methods

compute

()

Computes all the hoppers structures.

computeHopper

(
  • hopper
)

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:

destroy

()

Inherited from BaseComponent2D:

Method called when the component is destroyed

disable

()

Inherited from BaseComponent2D:

Disables the component

draw

(
  • hopper
  • ctx
  • translation
  • zoom
  • selected
)

Draws the hopper.

Parameters:

  • hopper HopperStructure

    The hopper structure.

  • ctx Context2D

    The 2d context.

  • translation BABYLON.Vector2

    The translation of the canvas.

  • zoom Number

    The zoom level of the canvas.

  • selected Boolean

    True if the hopper is currently selected, else false.

drawTarget

(
  • hopper
  • ctx
  • zoom
)

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:

  • hopper HopperStructure

    The hopper structure.

  • ctx Context2D

    The 2d context.

  • zoom Number

    The zoom level of the canvas.

enable

()

Inherited from BaseComponent2D:

Enables the component

getRoom

(
  • hopper
  • force
)
RoomStructure

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:

  • hopper HopperStructure

    The hopper structure.

  • force Boolean

    If set to true, ignore the internal attribute and try to attach to a room.

Returns:

RoomStructure:

The room where the hopper is.

getTargeted

(
  • vector
)
Object

Inherited from BaseComponent2D:

Finds out if the given position is over an element handled by the component

Parameters:

  • vector Vector
    A position, usually the cursor's one.

Returns:

Object: The targeted element, or null if nothing is found.

initialize

()

Inherited from BaseComponent2D:

Method called when Wanaplan is initialized. You don't need to call this method manually.

isPointInHopper

(
  • vector
  • hopper
)
Boolean

Tests the collision of a point with the area defined by the hopper.

Parameters:

  • vector BABYLON.Vector2

    The point.

  • hopper HopperStructure

    The hopper structure.

Returns:

Boolean:

True if the point collides, else false.

isPointInHopperSide

(
  • vector
  • hopper
)
Number | Boolean

Tests the collision of a point with the hopper's edges.

Parameters:

  • vector BABYLON.Vector2

    The point.

  • hopper HopperStructure

    The hopper structure.

Returns:

Number | Boolean:

False if the point does not collide with any of the hopper's edges. Else the index of the side that collides.

onAddHopper

()

Adds new events callbacks when the user is in Hopper mode. Triggered on event wnp.engine2d.onAddHopper

onAddHopperClick

(
  • event
  • target
  • mstate
  • data
)

Adds a new hopper on click. Triggered on event hopperComponent2D.add-hopper.click

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure added.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

onContextChanged

(
  • context
)

Inherited from BaseComponent2D:

Method called when the context is switched (2D -> 3D or 3D -> 2D)

Parameters:

  • context String
    The new context

onContextMenu

(
  • event
  • target
  • mstate
  • data
)

Opens the context menu of the hopper. Triggered on event HopperComponent2D.hopper.click

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

onContextMenuPropertyChanged

(
  • target
  • property
  • value
)

Called when a value is changed in the context menu of the hopper.

Parameters:

onContextMenuRemove

(
  • target
)

Called when the user closes the context menu.

Parameters:

onDblClick

(
  • event
  • target
  • mstate
  • data
)

Adds a point on the hover contour when the user double clicks on it. Triggered on event HopperComponent2D.hopper.dblclick

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure clicked.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

onDrag

(
  • event
  • target
  • mstate
  • data
)

Moves the hopper when it is dragged. Triggered on event hopperComponent2D.hopper.drag

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure dragged.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

onDragEnd

(
  • event
  • target
  • mstate
  • data
)

Calls computeHopper when the user stop dragging. Triggered on event hopperComponent2D.stair-hover.drag-end

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure dragged.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

onDragStart

(
  • event
  • target
  • mstate
  • data
)

Adds new events callbacks when the dragging starts. Triggered on event HopperComponent2D.hopper.drag-start

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure dragged.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

onHover

(
  • event
  • target
  • mstate
  • data
)

Enables all the possible actions when the mouse hovers the hopper. Triggered on event HopperComponent2D.hopper.hover

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure hovered.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

onHoverHopper

(
  • ctx
  • translation
  • zoom
  • data
)

Highlights the hopper. Triggered on event HopperComponent2D.hopper-hover.dynamic-draw

Parameters:

  • ctx CanvasRenderingContext2D

    2D context of the canvas.

  • translation BABYLON.Vector2

    The translation of the canvas.

  • zoom Number

    The current zoom of the canvas.

  • data Object

    Important data used to draw (null).

onLeave

(
  • event
  • target
  • mstate
  • data
)

Disables all the possible actions when the mouse leaves the hopper. Triggered on event HopperComponent2D.hopper.leave

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure leaved.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

onMouseMove

(
  • event
  • target
  • mstate
  • data
)

Moves the new hopper to add when the mouse moves. Triggered on event hopperComponent2D.dynamic-stair.mouse-move

Parameters:

  • event Event

    The event caught.

  • target HopperStructure

    The hopper structure moved.

  • mstate Object

    The current state of the pointer.

  • data Object

    Important data used to draw.

startListening

()

Inherited from BaseComponent2D:

Calls all the event listeners.

stopListening

()

Inherited from BaseComponent2D:

Removes all the event listeners.

update

()

Inherited from BaseComponent2D:

Generic update method, called on every frame

Properties

name

String

Inherited from BaseComponent2D:

Component name

priority

Number

Inherited from BaseComponent2D:

Priority of the component in the "update" and "draw" routines

structure

wnp.Structure

Inherited from BaseComponent2D:

Structure file instance (shortcut to wanaplan.structure). This is the base object where the whole plan is saved

Events

wnp.menu.main.add

Fired to add a menu item to the main menu.

wnp.menu.main.deselect

Fired to unselect the currently selected main menu item.