linsyking/messenger-core/17.1.1

NOTE: the latest version is 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.GeneralModel

General Model

General model is designed to be an abstract interface of layers, components, etc..

A General model has the ability to:

  • specialize its own data types
  • share some data types with objects in the same type
  • be initialized by some inputs
  • be updated by event and msgs
  • be updated in a list of same type objects
  • send msg to the objects in the same type
  • send msg to the parent object
  • render itself
  • identify itself by a matcher
type Msg othertar msg sommsg
= Parent (MsgBase msg sommsg)
| Other ( othertar, msg )

The Basic Msg Model.

Using Other when sending msg to objects in the same type. Make sure the othertar can pass the matcher of target object.

Examples:

  • Parent <| SOMMsg <| SOMChangeScene (Just NullSceneMsg) "SelectLevel" -- Parent
  • Other <| ( Type "Camera", CameraShakeMsg 1 200 ) -- Note here Type "Camera" is of Matcher Type (Defined by the user) which indicates the target of the message, and the desired message is the second entry of the tuple.
type MsgBase othermsg sommsg
= SOMMsg sommsg
| OtherMsg othermsg

MsgBase

Used when sending a msg to parent object.

Using SOMMsg when sending a SceneOutputMsg, which will be directly handled by Top-level. Use OtherMsg when sending a normal message to parent.

Examples:

  • Parent <| SOMMsg <| SOMChangeScene (Just NullSceneMsg) "SelectLevel" -- SOMMsg
  • Parent <| OtherMsg <| genMeteor env.commonData.playerPos env.globalData.globalStartTime -- In a component. This genMeteor message will be handled in the layer containing the component.
filterSOM : List (MsgBase othermsg sommsg) -> List sommsg

Filter SOMMsg from list of MsgBase.

  • Not very likely to be used. The messenger template will handle this for you automatically.
type alias ConcreteGeneralModel data env event tar msg ren bdata sommsg =
{ init : env -> msg -> ( data, bdata )
, update :
env
-> event
-> data
-> bdata
-> ( ( data, bdata ), List (Msg tar msg sommsg), ( env, Bool ) )
, updaterec :
env
-> msg
-> data
-> bdata
-> ( ( data, bdata ), List (Msg tar msg sommsg), env )
, view : env -> data -> bdata -> ren
, matcher : data -> bdata -> tar -> Bool
}

Concrete General Model.

Users deal with the fields in concrete model. That is to say, you should implement the init,update,updaterec,view and matcher function in the model.

type AbstractGeneralModel env event tar msg ren bdata sommsg
= Roll
(UnrolledAbstractGeneralModel
env
event
tar
msg
ren
bdata
sommsg
)

Rolled Abstract General Model.

Cannot be directedly modified. Used for storage.

AbstractGeneralModel env event tar msg ren bdata sommsg
-> UnrolledAbstractGeneralModel env event tar msg ren bdata sommsg

Unroll a rolled abstract model. In this way, you retrieve the data from the storage. This is useful when you want to manipulate and calculate the reactions between components, like in collision handling process. For example, the following function called by the layer can read the position of from AbstractComponent. let x_data = unroll x posX=x_data.baseData.position in ...

ConcreteGeneralModel data env event tar msg ren bdata sommsg
-> msg
-> env
-> AbstractGeneralModel env event tar msg ren bdata sommsg

Abstract a concrete model to an abstract model.

Initialize it with env and msg. Messenger will handle this for you.

Env common userdata
-> List
(Env common userdata)
tar
msg
Renderable
bdata
sommsg
)
-> List Renderable

View model list.

  • Not very likely to be used. The messenger template will handle this for you automatically.
type alias Matcher data tar =
data -> tar -> Bool

A general matcher type sugar

Similar to the matcher function implemented by user in the components and layers.

Result Remap

( ( List (Msg tar msg sommsg), ( env, Bool ) )
-> ( List (Msg tar msg sommsg), ( env, Bool ) )
)
-> AbstractGeneralModel env event tar msg ren bdata sommsg
-> AbstractGeneralModel env event tar msg ren bdata sommsg

Change the update function to remap the result and return the changed abstract general model.

  • Not very likely to be used. The messenger template will handle this for you automatically.
( ( List (Msg tar msg sommsg), env )
-> ( List (Msg tar msg sommsg), env )
)
-> AbstractGeneralModel env event tar msg ren bdata sommsg
-> AbstractGeneralModel env event tar msg ren bdata sommsg

Change the updaterec function to remap the result and return the changed abstract general model.

  • Not very likely to be used. The messenger template will handle this for you automatically.