index.erl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. -module(index).
  2. -compile({parse_transform, shen}).
  3. -compile(export_all).
  4. -include_lib("n2o/include/wf.hrl").
  5. -include_lib("server/include/requests.hrl").
  6. -include_lib("server/include/settings.hrl").
  7. -jsmacro([take/2,attach/1,join/1]).
  8. join(Game) ->
  9. ws:send(bert:encodebuf(bert:tuple(
  10. bert:atom('client'),
  11. bert:tuple(bert:atom("join_game"), Game)))).
  12. attach(Token) ->
  13. ws:send(bert:encodebuf(bert:tuple(
  14. bert:atom('client'),
  15. bert:tuple(bert:atom("session_attach"), Token)))).
  16. take(GameId,Place) ->
  17. ws:send(bert:encodebuf(bert:tuple(
  18. bert:atom('client'),
  19. bert:tuple(bert:atom("game_action"),GameId,bert:atom("okey_take"),[{pile,Place}])))).
  20. main() -> #dtl{file="index", bindings=[{title,<<"N2O">>},{body,body()}]}.
  21. body() ->
  22. [ #panel{ id=history },
  23. #dropdown { id=drop, value="2", postback=combo, source=[drop], options=[
  24. #option { label= <<"Option 1">>, value= <<"1">> },
  25. #option { label= <<"Option 2">>, value= <<"2">> },
  26. #option { label= <<"Option 3">>, value= <<"3">> }
  27. ]},
  28. #button{ id = attach, body = <<"Attach">>, postback = attach},
  29. #button{ id = join, body = <<"Join">>, postback = join},
  30. #button{ id = take, body = <<"Take">>, postback = take},
  31. #button{ id = discard, body = <<"Discard">>, postback = discard}
  32. ].
  33. event(init) ->
  34. {ok,GamePid} = game_session:start_link(self()),
  35. put(game_session,GamePid);
  36. event(combo) -> wf:info("Combo: ~p",[wf:q(drop)]);
  37. event(join) -> wf:wire(join("1000001"));
  38. event(attach) -> wf:wire(attach("'"++?TEST_TOKEN++"'"));
  39. event(take) -> wf:wire(take("1000001","0"));
  40. event(Event) -> wf:info("Event: ~p", [Event]).