Note: The config in the following type signatures is a record of all your config values, like...
type alias Config =
{ headerFontSize : Int
, bodyFontSize : Int
, backgroundColor : Color
}Also, Value is shorthand for Json.Encode.Value.
init will create both a valid Config and ConfigForm.
InitOptions are used to initialize your config and ConfigForm.
{ flags = flagsFromJavascript
, logics = Config.logics
, emptyConfig = Config.empty
}Config is your generated module that was made using ConfigFormGenerator.
If a particular value isn't found from localStorage or file, then it fallbacks to these values. It might be a good idea to use wild values that are easy to spot so you can quickly replace them with real values.
defaults =
{ int = -9999
, float = -9999
, string = "PLEASE REPLACE ME"
, bool = True
, color = Color.rgb 1 0 1 -- hot pink!
}A Msg is an opaque type for ConfigForm to communicate with your app through ConfigForm.update.
When you receive a Config.Msg, update your Config and ConfigForm using this. It returns a new Config and ConfigForm, plus possible json to pass through ports for pointerlock.
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ConfigFormMsg configFormMsg ->
let
( newConfig, newConfigForm, maybeJsonCmd ) =
ConfigForm.update
Config.logics
model.config
model.configForm
configFormMsg
newModel =
{ model
| config = newConfig
, configForm = newConfigForm
}
in
( newModel
, Cmd.batch
[ saveToLocalStorageCmd newModel
, case maybeJsonCmd of
Just jsonCmd ->
sendToPort
(Json.Encode.object
[ ( "id", Json.Encode.string "CONFIG" )
, ( "val", jsonCmd )
]
)
Nothing ->
Cmd.none
]
)Encodes the current Config (with some metadata) in your ConfigForm. Usually used for both localStorage and as a .json file.
View the config form.
Default options for viewing the config form.
Update the font size in px. Default is 18.
Update the row spacing in px. Default is 2.
Update the width of inputs in px. Default is 80.
Update the inner spacing of inputs by a ratio of its font size. Default is 1.40.
Update the row color when hovering field labels that are pointerlock-able. Default is yellow: (0.8, 0.8, 1).
Update the extra top spacing for sections in px. Default is 20.
Creates the logic for Int values
Creates the logic for Float values
Creates the logic for String values
Creates the logic for Bool values
Creates the logic for Color values
Creates the logic for Section values
ConfigForm is the state of the config form. Keep it in your model along with the
configrecord.