From 11a7a03a0088b2c4b8edc394469396d54190dc53 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 12 Mar 2018 13:00:59 +0100 Subject: Starting to work on the timeline feature. --- src/struct/player.erl | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/struct/player.erl (limited to 'src/struct/player.erl') diff --git a/src/struct/player.erl b/src/struct/player.erl new file mode 100644 index 0000000..824e474 --- /dev/null +++ b/src/struct/player.erl @@ -0,0 +1,72 @@ +-module(player). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-type id() :: string(). + +-record +( + player, + { + id :: id(), + timeline :: list(any()) + } +). + +-opaque struct() :: #player{}. + +-export_type([struct/0, id/0]). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( + [ + get_id/1, + get_timeline/1, + add_to_timeline/2, + reset_timeline/1 + ] +). + +-export +( + [ + new/1 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec get_id (struct()) -> id(). +get_id (Player) -> Player#player.id. + +-spec get_timeline (struct()) -> list(any()). +get_timeline (Player) -> Player#player.timeline. + +-spec add_to_timeline (list(any()), struct()) -> struct(). +add_to_timeline (NewEvents, Player) -> + OldTimeline = Player#player.timeline, + + Player#player + { + timeline = (OldTimeline ++ NewEvents) + }. + +-spec reset_timeline (struct()) -> struct(). +reset_timeline (Player) -> Player#player{ timeline = [] }. + +-spec new (id()) -> struct(). +new (ID) -> + #player + { + id = ID, + timeline = [] + }. + -- cgit v1.2.3-70-g09d2