justgook/elm-game-logic/1.0.0

NOTE: the latest version is 3.0.0

Logic.Launcher

document : Document flags world -> Launcher flags world

Main entry point, but have few difference from Browser.document

type alias Document flags world =
{ init : flags -> Task Error (World world)
, subscriptions : World world -> Sub (World world)
, update : World world -> ( World world, Cmd (Message world) )
, view : World world -> List (Html (World world -> World world))
}

difference from Browser.document:

  1. init takes as argument flags and returns Task, that results in world or fail (90% of games any way need get some data to start, images, level data, connection, etc.)

  2. subscriptions instead of returning msg - should return new World

  3. update have no Msg input

  4. view instead of Msg event have to return function

type Error
= Error Int String

Error type to hold all error of game init

type alias Launcher flags world =
Program flags (Model world) (Message world)
type alias World world =
Model world

just alias to Logic.GameFlow.Model world

(Result x a -> World world -> World world)
-> Task x a
-> Cmd (Message world)

Helper function, that allow convert Task into Cmd - for loading new World after init

{ init : flags -> Task Error (World world)
, subscriptions : World world -> Sub (World world)
, update : World world -> ( World world, Cmd (Message world) )
}
-> Launcher flags world

Main entry point, but have few difference from Platform.worker