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.
#DefaultBehavior Source
data DefaultBehavior
This datatype is used internally 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.
The default behavior is prevented automatically in your event handler. If you want to execture the default behavior for certain events, you have to explicitly call Reactor.Action.executeDefaultBehavior.
Constructors
Instances
#mouseEventFromDOM Source
mouseEventFromDOM :: { height :: Int, tileSize :: Int, width :: Int } -> MouseInteractionType -> MouseEvent -> Event
Convert a DOM mouse event into our custom event type. Used internally, you shouldn't need it.
#MouseInteractionType Source
data MouseInteractionType
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 -> Event
Convert a DOM keyboard event into our custom event type. Used internally, you shouldn't need it.
#Event Source
data Event
This type describes the different events that occur during the life of a reactor. You
pattern match on this in the handleEvent
function.
Tick Event
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.
Mouse Event
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.)position
is the position of the event relative to the rendering grid (i.e. in tiles).positionOnCanvas
is the position of the event relative to the rendering canvas (i.e. in pixels).- for more information on
modifiers
see the documentation of the typeModifiers
.
Keypress Event
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
modifiers
. - Common special keys have intuitive names. For example:
ArrowLeft
,ArrowRight
,ArrowUp
,ArrowDown
. Full list can be seen on MDN Web Docs.
Constructors
Tick { delta :: Number }
Mouse { modifiers :: Modifiers, position :: Coordinates, positionOnCanvas :: { x :: Number, y :: Number }, type :: MouseInteractionType }
KeyPress { key :: String, modifiers :: Modifiers }
Instances
#Modifiers Source
type Modifiers = { alt :: Boolean, control :: Boolean, meta :: Boolean, shift :: Boolean }
Mouse
and KeyPress
events carry the info about modifier keys that were pressed
when the event happened.
A meta
key is the Windows button on Windows, and the Command button on the Mac.
The rest are the common modifier keys.