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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
-module(shr_battle_summary).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
battle_summary,
{
id :: binary(),
name :: binary(),
last_edit :: binary(),
is_players_turn :: boolean()
}
).
-opaque type() :: #battle_summary{}.
-export_type([type/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export
(
[
new/4,
none/0
]
).
%%%% Accessors
-export
(
[
get_id/1,
get_name/1,
get_last_edit/1,
is_players_turn/1
]
).
-export
(
[
set_id/2,
set_name/2,
set_last_edit/2,
set_is_players_turn/2
]
).
-export
(
[
get_id_field/0,
get_name_field/0,
get_last_edit_field/0,
get_is_players_turn_field/0
]
).
%%%% Export
-export
(
[
encode/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec new (binary(), binary(), binary(), boolean()) -> type().
new (ID, Name, Time, IsPlayersTurn) ->
#battle_summary
{
id = ID,
name = Name,
last_edit = Time,
is_players_turn = IsPlayersTurn
}.
-spec none () -> type().
none () ->
#battle_summary
{
id = <<"">>,
name = <<"">>,
last_edit = <<"">>,
is_players_turn = false
}.
%%%% Accessors
-spec get_id (type()) -> binary().
get_id (BattleSummary) -> BattleSummary#battle_summary.id.
-spec get_name (type()) -> binary().
get_name (BattleSummary) -> BattleSummary#battle_summary.name.
-spec get_last_edit (type()) -> binary().
get_last_edit (BattleSummary) -> BattleSummary#battle_summary.last_edit.
-spec is_players_turn (type()) -> boolean().
is_players_turn (BattleSummary) -> BattleSummary#battle_summary.is_players_turn.
-spec set_id (binary(), type()) -> type().
set_id (Val, BattleSummary) -> BattleSummary#battle_summary{ id = Val }.
-spec set_name (binary(), type()) -> type().
set_name (Val, BattleSummary) -> BattleSummary#battle_summary{ name = Val }.
-spec set_last_edit (binary(), type()) -> type().
set_last_edit (Val, BattleSummary) ->
BattleSummary#battle_summary{ last_edit = Val }.
-spec set_is_players_turn (boolean(), type()) -> type().
set_is_players_turn (Val, BattleSummary) ->
BattleSummary#battle_summary{ is_players_turn = Val }.
-spec get_id_field () -> non_neg_integer().
get_id_field () -> #battle_summary.id.
-spec get_name_field () -> non_neg_integer().
get_name_field () -> #battle_summary.name.
-spec get_last_edit_field () -> non_neg_integer().
get_last_edit_field () -> #battle_summary.last_edit.
-spec get_is_players_turn_field () -> non_neg_integer().
get_is_players_turn_field () -> #battle_summary.is_players_turn.
-spec encode (type()) -> {list(any())}.
encode (BattleSummary) ->
{
[
{<<"id">>, BattleSummary#battle_summary.id},
{<<"nme">>, BattleSummary#battle_summary.name},
{<<"ldt">>, BattleSummary#battle_summary.last_edit},
{<<"ipt">>, BattleSummary#battle_summary.is_players_turn}
]
}.
|