-
Notifications
You must be signed in to change notification settings - Fork 3
/
Government.elm
62 lines (49 loc) · 1.43 KB
/
Government.elm
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
module Government (Government, GovernmentForm(..), governmentFormToString, isAvailable, isHovered, isSelected) where
import Effect exposing (Effect)
import Ethos exposing (Ethos)
type GovernmentForm
= Autocracy
| Oligarchy
| Democracy
governmentFormToString : GovernmentForm -> String
governmentFormToString form' =
case form' of
Autocracy -> "Autocracy"
Oligarchy -> "Oligarchy"
Democracy -> "Democracy"
type alias Government =
{ name : String
, imgUrl : String
, form' : GovernmentForm
, description : String
, rulerTitle : String
, unlockedIf : List String
, lockedIf : List String
, effects : List Effect
}
isAvailable : List Ethos -> Government -> Bool
isAvailable selectedEthoses government =
let
isUnlockedByEthoses =
if List.isEmpty government.unlockedIf then
True
else
List.any (\e -> List.member e.name government.unlockedIf) selectedEthoses
isLockedByEthoses =
List.any (\e -> List.member e.name government.lockedIf) selectedEthoses
in
isUnlockedByEthoses && (not isLockedByEthoses)
isHovered : Maybe Government -> Government -> Bool
isHovered hoveredGovernment government =
case hoveredGovernment of
Nothing ->
False
Just g ->
government == g
isSelected : Maybe Government -> Government -> Bool
isSelected selectedGovernment government =
case selectedGovernment of
Nothing ->
False
Just g ->
government == g