|
@@ -1,9 +1,10 @@
|
|
-module(n2o_game).
|
|
-module(n2o_game).
|
|
-author('Maxim Sokhatsky').
|
|
-author('Maxim Sokhatsky').
|
|
-include_lib("n2o/include/wf.hrl").
|
|
-include_lib("n2o/include/wf.hrl").
|
|
--include_lib("server/include/requests.hrl").
|
|
|
|
--include_lib("server/include/game_okey.hrl").
|
|
|
|
--include_lib("server/include/game_tavla.hrl").
|
|
|
|
|
|
+-include("../../server/include/requests.hrl").
|
|
|
|
+-include("../../server/include/game_okey.hrl").
|
|
|
|
+-include("../../server/include/game_tavla.hrl").
|
|
|
|
+
|
|
|
|
|
|
-export([init/4]).
|
|
-export([init/4]).
|
|
-export([stream/3]).
|
|
-export([stream/3]).
|
|
@@ -44,7 +45,8 @@ html_events(Pro, State) ->
|
|
GenActions = get(actions),
|
|
GenActions = get(actions),
|
|
RenderGenActions = wf:render(GenActions),
|
|
RenderGenActions = wf:render(GenActions),
|
|
wf_context:clear_actions(),
|
|
wf_context:clear_actions(),
|
|
- [<<"EVAL">>,Render,RenderGenActions].
|
|
|
|
|
|
+ JS = iolist_to_binary([Render,RenderGenActions]),
|
|
|
|
+ wf:json([{eval,JS}]).
|
|
|
|
|
|
stream(<<"ping">>, Req, State) ->
|
|
stream(<<"ping">>, Req, State) ->
|
|
wf:info("ping received~n"),
|
|
wf:info("ping received~n"),
|
|
@@ -75,12 +77,26 @@ info({client,Message}, Req, State) ->
|
|
game_session:process_request(GamePid, Message),
|
|
game_session:process_request(GamePid, Message),
|
|
Module = State#context.module,
|
|
Module = State#context.module,
|
|
catch Module:event({client,Message}),
|
|
catch Module:event({client,Message}),
|
|
- {reply,<<"DATA">>,Req,State};
|
|
|
|
|
|
+ Actions = get(actions),
|
|
|
|
+ wf_context:clear_actions(),
|
|
|
|
+ Render = wf:render(Actions),
|
|
|
|
+ GenActions = get(actions),
|
|
|
|
+ RenderGenActions = wf:render(GenActions),
|
|
|
|
+ wf_context:clear_actions(),
|
|
|
|
+ {reply,wf:json([{eval,iolist_to_binary([Render,RenderGenActions])},
|
|
|
|
+ {data,binary_to_list(term_to_binary(Message))}]),Req,State};
|
|
|
|
|
|
info({send_message,Message}, Req, State) ->
|
|
info({send_message,Message}, Req, State) ->
|
|
Module = State#context.module,
|
|
Module = State#context.module,
|
|
catch Module:event({server,Message}),
|
|
catch Module:event({server,Message}),
|
|
- {reply,[<<"DATA">>,io_lib:format("~p",[Message])],Req,State};
|
|
|
|
|
|
+ Actions = get(actions),
|
|
|
|
+ wf_context:clear_actions(),
|
|
|
|
+ Render = wf:render(Actions),
|
|
|
|
+ GenActions = get(actions),
|
|
|
|
+ RenderGenActions = wf:render(GenActions),
|
|
|
|
+ wf_context:clear_actions(),
|
|
|
|
+ {reply,wf:json([{eval,iolist_to_binary([Render,RenderGenActions])},
|
|
|
|
+ {data,binary_to_list(term_to_binary(Message))}]),Req,State};
|
|
|
|
|
|
info(Pro, Req, State) ->
|
|
info(Pro, Req, State) ->
|
|
Render =
|
|
Render =
|
|
@@ -124,7 +140,8 @@ info(Pro, Req, State) ->
|
|
wf_context:clear_actions(),
|
|
wf_context:clear_actions(),
|
|
RenderGenActions = wf:render(GenActions),
|
|
RenderGenActions = wf:render(GenActions),
|
|
wf_context:clear_actions(),
|
|
wf_context:clear_actions(),
|
|
- {reply, [<<"EVAL">>,Render,RenderGenActions], Req, State}.
|
|
|
|
|
|
+ JS = iolist_to_binary([Render,RenderGenActions]),
|
|
|
|
+ {reply, wf:json([{eval,JS}]), Req, State}.
|
|
|
|
|
|
terminate(_Req, _State=#context{module=Module}) ->
|
|
terminate(_Req, _State=#context{module=Module}) ->
|
|
% wf:info("Bullet Terminated~n"),
|
|
% wf:info("Bullet Terminated~n"),
|