summaryrefslogtreecommitdiff
blob: 43fde3de7c6b35012961fd841ee88ee06ae5cd1a (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
-module(battlemap_load_state).

-export(
   [
      handle/1
   ]
).

handle (Req) ->
   JSONReqMap = jiffy:decode(Req, [return_maps]),
   BattlemapID = maps:get(<<"battlemap_id">>, JSONReqMap),
   io:format("~nLoading Battlemap ~p...~n", [BattlemapID]),
   {Battlemap, CharList} =
      timed_cache_object:fetch(
         battlemaps_db,
         BattlemapID
      ),
%%   ok = users_manager:ping(UserToken),
   jiffy:encode(
      {
         [
            {
               <<"types">>,
               [
                  <<"SET_MAP">>,
                  lists:map(
                     fun (_Char) ->
                        <<"ADD_CHAR">>
                     end,
                     CharList
                  )
               ]
            },
            {
               <<"data">>,
               [
                  battlemap_battlemap:encode_in_json(Battlemap)
                  |
                  lists:map(
                     fun (Char) ->
                        battlemap_character:encode_in_json(Char)
                     end,
                     CharList
                  )
               ]
            }
         ]
      }
   ).