Module

Reactor.Action

Package
purescript-grid-reactors
Repository
Eugleo/purescript-grid-reactors

#Action Source

newtype Action :: (Type -> Type) -> Type -> Type -> Typenewtype Action m world a

Constructors

Instances

#utilities Source

utilities :: forall world m. Action m world Utilities

Get a record of the following:

  • bound :: CoordinateSystem Point -> CoordinateSystem Point, a function that bounds the given point in the grid or the canvas, meaning the point won't be beyond the bounds of its coordinate system.
  • height :: Int, width :: Int, the dimensions of the grid
  • cellSize :: Int the size of one grid cell, in points. The size is set internally, and this is the only way to its value.

#randomPositive Source

randomPositive :: forall world m. Int -> Action m world Int

Get a random non-negative integer smaller than the given upper bound (inclusive). The distribution of these integers is discrete uniform.

#randomInRange Source

randomInRange :: forall world m. Int -> Int -> Action m world Int

Get a random integer between the given bounds (inclusive). The distribution of these integers is discrete uniform.

#modify Source

modify :: forall world m. (world -> world) -> Action m world world

Modify the current world by passing in a (world -> world) updating function. The 'world' is the current state of the reactor. Returns the value of the new world.

#modify_ Source

modify_ :: forall world m. (world -> world) -> Action m world Unit

Modify the current value of the world by passing in a (world -> world) updating function. The 'world' is the current state of the reactor. Doesn't return anything, as opposed to the modify action.

#get Source

get :: forall world m. Action m world world

Obtain the current value of the world.

#pause Source

pause :: forall world m. Action m { paused :: Boolean | world } Unit

Pause the reactor by setting the paused attribute in its world to true. A shorthand for

modify_ \w -> w { paused = true }

#unpause Source

unpause :: forall world m. Action m { paused :: Boolean | world } Unit

Unpause the reactor by setting the paused attribute in its world to false. A shorthand for

modify_ \w -> w { paused = false }

#togglePause Source

togglePause :: forall world m. Action m { paused :: Boolean | world } Unit

Toggle the paused attribute of the world from false to true and vice versa. A shorthand for

modify_ \w -> w { paused = not w.paused }

#preventDefaultBehavior Source

preventDefaultBehavior :: forall world m. Action m { paused :: Boolean | world } DefaultBehavior

Prevent the execution of the default behavior associated with the event. You can read more in the documentation of Reactor.Events.

Usually, this or executeDefaultBehavior is the last thing you'll call in your onMouse and onKey handlers. This one will usually get called in the events you handle (i.e. that have some functionality associated with them in your game).

#executeDefaultBehavior Source

executeDefaultBehavior :: forall world m. Action m { paused :: Boolean | world } DefaultBehavior

After handling the event, execute the default behavior as well. You can read more in the documentation of Reactor.Events.

Usually, this or preventDefaultBehavior is the last thing you'll call in your onMouse and onKey handlers. This one will usually get called in the events you only let pass through (i.e. when pressing 'J' doesn't 'do anything' in your game).

#ActionF Source

data ActionF :: (Type -> Type) -> Type -> Type -> Typedata ActionF m world a

A DSL for constructing actions. Mostly for internal use. Most of the time, you construct an action by calling the different helper functions in this module, like modify_, instead of building an ActionF manually.

Constructors

Instances

#Utilities Source

type Utilities = { bound :: CoordinateSystem Point -> CoordinateSystem Point, cellSize :: Int, height :: Int, width :: Int }