summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2017-11-28 17:14:02 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2017-11-28 17:14:02 +0100 |
commit | f539b7072c357339328d9bfd54f1f1ed51828586 (patch) | |
tree | b6205dd79c78090831e812aceac177d2a9f35d28 /www/handler/battlemap/load_state.yaws | |
parent | 80358376b9300a0d73cb8b62dfa9fdd65240ca66 (diff) |
Trying to tidy up this mess.
Diffstat (limited to 'www/handler/battlemap/load_state.yaws')
-rw-r--r-- | www/handler/battlemap/load_state.yaws | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/www/handler/battlemap/load_state.yaws b/www/handler/battlemap/load_state.yaws deleted file mode 100644 index e04fd96..0000000 --- a/www/handler/battlemap/load_state.yaws +++ /dev/null @@ -1,123 +0,0 @@ -<erl> --record(input, {session_token, player_id, battlemap_id, instance_id}). - --include("/my/src/tacticians-server/src/timed_cache_data.hrl"). - -parse_input (Req) -> - JSONReqMap = jiffy:decode(Req, [return_maps]), - #input - { - session_token = maps:get(<<"session_token">>, JSONReqMap), - player_id = maps:get(<<"player_id">>, JSONReqMap), - battlemap_id = maps:get(<<"battlemap_id">>, JSONReqMap), - instance_id = maps:get(<<"instance_id">>, JSONReqMap) - }. - -generate_set_map (Battlemap) -> - jiffy:encode - ( - { - [ - {<<"width">>, Battlemap#battlemap.width}, - {<<"height">>, Battlemap#battlemap.height}, - {<<"content">>, array:sparse_to_list(Battlemap#battlemap.content)} - ] - } - ). - -generate_add_char (Char, CharInstance, BattlemapInstance, PlayerID) -> - jiffy:encode - ( - { - [ - {<<"id">>, Char#character.id}, - {<<"name">>, Char#character.name}, - {<<"icon">>, Char#character.icon}, - {<<"portrait">>, Char#character.portrait}, - {<<"loc_x">>, CharInstance#character_instance.x}, - {<<"loc_y">>, CharInstance#character_instance.y}, - {<<"team">>, CharInstance#character_instance.team}, - {<<"mov_pts">>, Char#character.mov_pts}, - {<<"atk_rg">>, Char#character.atk_rg}, - { - <<"enabled">>, - battlemap_instance:can_play_char_instance - ( - BattlemapInstance, - PlayerID, - Char#character.id - ) - } - ] - } - ). - -generate_reply (Battlemap, BattlemapInstance, Characters, PlayerID) -> - jiffy:encode - ( - [ - [ - <<"set_map">>, - generate_set_map(Battlemap) - ] - | - lists:map - ( - fun ({CharID, CharInstance}) -> - [ - <<"add_char">>, - generate_add_char - ( - CharID, - CharInstance, - BattlemapInstance, - PlayerID - ) - ] - end, - Characters - ) - ] - ). - -handle (Req) -> - %%%% Parse - Input = parse_input(Req), - %%%% Fetch - Battlemap = timed_cache:fetch(battlemap_db, Input#input.battlemap_id), - BattlemapInstance = - timed_cache:fetch - ( - battlemap_instance_db, - <<"0">> -% {Input#input.battlemap_id, Input#input.battlemap_instance_id} - ), - Characters = - lists:map - ( - fun ({CharID, CharInst}) -> - { - timed_cache:fetch(character_db, CharID), - CharInst - } - end, - dict:to_list(BattlemapInstance#battlemap_instance.chars) - ), - %%%% Calc - %%%% Commit - %%%% Reply - generate_reply - ( - Battlemap, - BattlemapInstance, - Characters, - Input#input.player_id - ). - -out(A) -> - { - content, - "application/json; charset=UTF-8", - handle(A#arg.clidata) - }. -</erl> |