summaryrefslogtreecommitdiff
blob: 8fe92c016872f8e374513390ecace4d540e08c4e (plain)
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
65
66
67
68
69
70
71
72
73
74
75
module BattleCharacters.Struct.Portrait exposing
   (
      Type,
      Ref,
      find,
      default,
      get_id,
      get_name,
      get_body_id,
      get_icon_id,
      decoder
   )

-- Elm -------------------------------------------------------------------------
import Dict

import Json.Decode
import Json.Decode.Pipeline

--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type alias Type =
   {
      id : String,
      name : String,
      body_id : String,
      icon_id : String
   }

type alias Ref = String

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
find : (Dict.Dict Ref Type) -> Ref -> Type
find dict ref =
   case (Dict.get ref dict) of
      (Just e) -> e
      Nothing -> default

default : Type
default =
   {
      id = "cat",
      name = "Black Cat",
      body_id = "mammal",
      icon_id = "cat"
   }

get_id : Type -> String
get_id p = p.id

get_name : Type -> String
get_name p = p.name

get_body_id : Type -> String
get_body_id p = p.body_id

get_icon_id : Type -> String
get_icon_id p = p.icon_id

decoder : (Json.Decode.Decoder Type)
decoder =
   (Json.Decode.succeed
      Type
      |> (Json.Decode.Pipeline.required "id" Json.Decode.string)
      |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
      |> (Json.Decode.Pipeline.required "bid" Json.Decode.string)
      |> (Json.Decode.Pipeline.required "iid" Json.Decode.string)
   )