Roman Dayneko 11 years ago
parent
commit
336cf8bdb9
6 changed files with 37 additions and 15 deletions
  1. 5 2
      .travis.yml
  2. 2 0
      README.md
  3. 1 1
      apps/face/priv/templates/index.html
  4. 3 3
      apps/face/src/index.erl
  5. 24 7
      apps/face/src/n2o_game.erl
  6. 2 2
      otp.mk

+ 5 - 2
.travis.yml

@@ -2,7 +2,10 @@ language: erlang
 otp_release:
 otp_release:
   - R16B
   - R16B
 notifications:
 notifications:
-  email: maxim@synrc.com
+  email: 
+    - maxim@synrc.com
+    - roman.dayneko@gmail.com
+    - sustel@kakaranet.com
   irc: "chat.freenode.net#n2o"
   irc: "chat.freenode.net#n2o"
 install: "make"
 install: "make"
-script: "make test"
+script: "make ct"

+ 2 - 0
README.md

@@ -1,6 +1,8 @@
 Kakaranet Application
 Kakaranet Application
 =====================
 =====================
 
 
+[![Build Status](https://travis-ci.org/kakaranet/games.svg?branch=master)](https://travis-ci.org/kakaranet/games)
+
 Run
 Run
 ---
 ---
 
 

+ 1 - 1
apps/face/priv/templates/index.html

@@ -6,7 +6,7 @@
 <body>
 <body>
 {{body}}
 {{body}}
 <script>var transition = {pid: '', port:'8000'};</script>
 <script>var transition = {pid: '', port:'8000'};</script>
-<script>function handle_web_socket(body) { console.log(body); } </script>
+<script>function handle_web_socket(body) { console.log(String(bert.decodebuf(body))); } </script>
 <script src='/static/nitrogen/jquery.js' type='text/javascript' charset='utf-8'></script>
 <script src='/static/nitrogen/jquery.js' type='text/javascript' charset='utf-8'></script>
 <script src='/static/nitrogen/bullet.js' type='text/javascript' charset='utf-8'></script>
 <script src='/static/nitrogen/bullet.js' type='text/javascript' charset='utf-8'></script>
 <script src='/static/nitrogen/n2o.js' type='text/javascript' charset='utf-8'></script>
 <script src='/static/nitrogen/n2o.js' type='text/javascript' charset='utf-8'></script>

+ 3 - 3
apps/face/src/index.erl

@@ -2,9 +2,9 @@
 -compile({parse_transform, shen}).
 -compile({parse_transform, shen}).
 -compile(export_all).
 -compile(export_all).
 -include_lib("n2o/include/wf.hrl").
 -include_lib("n2o/include/wf.hrl").
--include_lib("server/include/requests.hrl").
--include_lib("server/include/settings.hrl").
--jsmacro([take/2,attach/1,join/1, discard/3]).
+-include("../../server/include/requests.hrl").
+-include("../../server/include/settings.hrl").
+-jsmacro([take/2,attach/1,join/1]).
 
 
 join(Game) ->
 join(Game) ->
     ws:send(bert:encodebuf(bert:tuple(
     ws:send(bert:encodebuf(bert:tuple(

+ 24 - 7
apps/face/src/n2o_game.erl

@@ -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"),

+ 2 - 2
otp.mk

@@ -9,10 +9,10 @@ relx  := "{release,{$(RELEASE),\"$(VER)\"},[$(subst $(space),$(comma),$(APPS))]}
 \\n{extended_start_script,true}.\\n{generate_start_script,true}.\\n{sys_config,\"$(SYS)\"}.\
 \\n{extended_start_script,true}.\\n{generate_start_script,true}.\\n{sys_config,\"$(SYS)\"}.\
 \\n{vm_args,\"$(VM)\"}.\\n{overlay,[{mkdir,\"log/sasl\"}]}."
 \\n{vm_args,\"$(VM)\"}.\\n{overlay,[{mkdir,\"log/sasl\"}]}."
 
 
-test: eunit ct
+test: ct
 compile: get-deps static-link
 compile: get-deps static-link
 delete-deps get-deps compile clean update-deps:
 delete-deps get-deps compile clean update-deps:
-	rebar $(REBAR_D) $@ skip_deps=true
+	rebar $(REBAR_D) $@
 .applist:
 .applist:
 	./depman.erl $(APPS) > $@
 	./depman.erl $(APPS) > $@
 $(RUN_DIR) $(LOG_DIR):
 $(RUN_DIR) $(LOG_DIR):