linsyking/messenger-core/20.0.0

Renamed to elm-messenger/messenger-core. That is where the repository lives now. It has not been published as a package under the new name.

Versions published as linsyking/messenger-core still install under that name. 34 versions of 52 come from the new location (see their notes). 7 versions could not be recovered and cannot be installed.

Messenger.Base

Base Module

Some Basic Data Types for the game

= Tick Float
| KeyDown Int
| KeyUp Int
| MouseDown Int ( Float, Float )
| MouseUp Int ( Float, Float )
| MouseWheel Int
| Prompt String String

User Event

This is the User Event for the game.

Users can get outside information through these events.

Tick is triggered every timeInterval. The int attacked to it is

KeyDown, KeyUp records the keyboard events. "KeyDown" event is sent when the key is pressed, "KeyUp" is sent when the key is released.

  • Note: if you just want to check if a key is pressed or not, use getPressedKeys runtime instead. check all the keycodes here.

MouseDown, MouseUp records the button code and position when mouse up and down. Mouse code 0 represents the left mouse button, 1 represents middle mouse button and 2 represents right mouse button.

We have provide some key and mouse codes in messenger-extra.

MouseWheel records the wheel event for mouse, positive value means scrolling down while negative value means scrolling up. It can be also used for touchpad.

Prompt name result gives the result user entered in the prompt window.

type alias GlobalData userdata =
{ extraHTML : Maybe (Html WorldEvent)
, canvasAttributes : List (Attribute WorldEvent)
, userData : userdata
, camera : Camera
}

GlobalData

GlobalData is the user-facing global state.

It won't be reset if you change the scene.

It is mainly used for display and reading/writing some localstorage data. Runtime values like time, input state, scene name, and volume live in the separate read-only Runtime; use the getter functions below to read them.

  • userdata records the data that users set to save
  • extraHTML is used to render extra HTML tags. Be careful to use this
  • canvasAttributes is used to attach attributes to the game canvas
  • camera records the camera position and zoom level
type alias Runtime =
InternalData

Opaque internal engine data.

type alias Env common userdata =
{ globalData : GlobalData userdata
, commonData : common
}

Environment

Environment is provided to users almost all the time.

It stores GlobalData and CommonData (Similar to GlobalData but just for one scene), so you can get and modify them through the Env.

type alias Flags =
{ timeStamp : Float
, info : String
}

The main flags.

Get info from js script.

Learn more about flags here

removeCommonData : Env cdata userdata -> Env () userdata

Remove common data from environment.

Useful when dealing with portable components by yourself.

Most of the time it will not be used since it has been built into prepared update functions.

addCommonData : cdata -> Env () userdata -> Env cdata userdata

Add the common data to a Environment without common data.

type alias GlobalDataInit userdata =
{ camera : Camera
, volume : Float
, extraHTML : Maybe (Html WorldEvent)
, canvasAttributes : List (Attribute WorldEvent)
, userData : userdata
}

This type is for user to use when initializing the messenger. It is very useful when dealing with local storage.

Internal Data Getters

Safe access to internal engine state

getSceneStartTime : Runtime -> Float

Get elapsed time since the current scene started.

getGlobalStartTime : Runtime -> Float

Get elapsed time since the game started.

getGlobalStartFrame : Runtime -> Int

Get the frame count since the game started.

getSceneStartFrame : Runtime -> Int

Get the frame count since the current scene started.

getCurrentTimeStamp : Runtime -> Float

Get the current timestamp.

getWindowVisibility : Runtime -> Visibility

Get the current browser visibility.

getMousePos : Runtime -> ( Float, Float )

Get the mouse position in virtual coordinates.

getPressedMouseButtons : Runtime -> Set Int

Get the pressed mouse buttons.

getPressedKeys : Runtime -> Set Int

Get the pressed keys.

getVolume : Runtime -> Float

Get the current volume.

getCurrentScene : Runtime -> String

Get the current scene name.

getVirtualSize : Runtime -> ( Float, Float )

Get virtual coordinate dimensions

getRealSize : Runtime -> ( Float, Float )

Get real canvas dimensions

getViewPort : Runtime -> ( Float, Float )

Get browser viewport dimensions

getCanvasOffset : Runtime -> ( Float, Float )

Get canvas positioning offset

getLoadingProgress : Runtime -> ( Int, Int )

Get resource loading progress (loaded, total)

getFonts : Runtime -> Set String

Get set of loaded font names

getPrograms : Runtime -> Set String

Get set of loaded shader program names

getSprite : String -> Runtime -> Maybe Texture

Get a specific sprite texture by name

getAllSprites : Runtime -> Dict String Texture

Get all loaded sprite textures

getConfigData : String -> Runtime -> Maybe String

Get loaded config data by key.