1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
module Struct.Model exposing
(
Type,
new,
invalidate,
reset,
clear_error,
set_flags
)
-- Elm -------------------------------------------------------------------------
import Array
-- Extension -------------------------------------------------------------------
import Struct.Error
import Struct.Flags
import Struct.Player
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type alias Type =
{
flags: Struct.Flags.Type,
players: (Array.Array Struct.Player.Type),
remaining_updates: Int,
error: (Maybe Struct.Error.Type)
}
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
set_flags : Struct.Flags.Type -> Type -> Type
set_flags flags t =
let
players_array = (Array.fromList (Struct.Flags.get_players flags))
in
{t |
flags = flags,
players = players_array,
remaining_updates = (Array.length players_array)
}
new : Struct.Flags.Type -> Type
new flags =
{
flags = flags,
players = (Array.fromList (Struct.Flags.get_players flags)),
remaining_updates = (List.length (Struct.Flags.get_players flags)),
error = Nothing
}
reset : Type -> Type
reset model = {model | error = Nothing}
invalidate : Struct.Error.Type -> Type -> Type
invalidate err model = {model | error = (Just err)}
clear_error : Type -> Type
clear_error model = {model | error = Nothing}
|