Reactor.Events
- Package
- purescript-grid-reactors
- Repository
- Eugleo/purescript-grid-reactors
This module defines the three types of events that the reactor needs to react to.
#optionallyPreventDefault Source
optionallyPreventDefault :: forall m. MonadEffect m => DefaultBehavior -> Event -> HookM m Unit
Used internally. You'll be better off using the preventDefaultBehavior
and executeDefaultBehavior
from Reactor.Action
.
#DefaultBehavior Source
data DefaultBehavior
This datatype is returned from your event handlers to signal to the reactor whether you want to prevent the default behavior that would normally happen as a response to the event.
In more detail: Some events have default behaviors associated with them; for example, pressing Ctrl+F
shows the find on the page dialog for the current page. When handling events, we often want to
'consume' them, and prevent the default behavior from happening — maybe Ctrl+F is used
for the 'fire' command in your game, and you don't want the find on the page dialog to show.
You pattern-match on this event in the onTick
handler.
Constructors
Instances
#mouseEventFromDOM Source
mouseEventFromDOM :: { cellSize :: Int, height :: Int, width :: Int } -> MouseEventType -> MouseEvent -> MouseEvent
Convert a DOM mouse event into our custom event. Used internally, you shouldn't need it.
#MouseEvent Source
data MouseEvent
This event is fired whenever the user presses a button on their mouse, or moves the mouse over the rendering grid. Explanation of each of the fields:
type
is the type of the event (drag, button up, etc.)x
andy
are the coordinates of the event. They are relative to the rendering grid, and denote the cell where the event hapened.control
,meta
,shift
, andalt
denote whether any modifier keys were pressed when the event happenedbutton
is an identifier of the button that has been pressed during the event, if applicable. See this entry in MDN Web Docs for more details. You pattern-match on this event in theonMouse
handler.
Constructors
MouseEvent { alt :: Boolean, button :: Int, control :: Boolean, meta :: Boolean, shift :: Boolean, type :: MouseEventType, x :: Int, y :: Int }
Instances
#MouseEventType Source
data MouseEventType
The main mouse event types, from the point of view of the rendered grid.
A Drag
occurs when the mouse button is down during a Move
.
Right-button clicks are not handled, those get handled by the browser.
Constructors
Instances
#keypressEventFromDOM Source
keypressEventFromDOM :: KeyboardEvent -> KeypressEvent
Convert a DOM keyboard event into our custom event. Used internally, you shouldn't need it.
#KeypressEvent Source
data KeypressEvent
This event is fired whenever the user presses down a key on the keyboard.
The key is passed in the event as a String
, with the following rules:
- Numbers, letters, and symbols all have intuitive codes (type A → get "A", type ů → get "ů").
Notably, pressing space produces an event with a literal space,
" "
. - Any modifier keys that were pressed simultaneously with the main key are passed in the record
{ shift, control, alt, meta }
. Ameta
key is the Windows button on Windows, and the Command button on the Mac. - Common special keys have intuitive names. For example:
ArrowLeft
,ArrowRight
,ArrowUp
,ArrowDown
. Full list can be seen on MDN Web Docs. You pattern-match on this event in theonKey
handler.
Constructors
#TickEvent Source
newtype TickEvent
This event is fired on every clock-tick in the reactor.
The attribute delta
is the time from the last tick, in seconds.
There's approximately 60 ticks per second, however, the number can vary depending on the browser's current available resources.
For the smoothest motion, you should calculate the traveled distance based on the
speed of the entity and the delta
.