Beispiel #1
0
 public void dungeonEnded() {
   dungeonEndedClient();
   Socket socket = field.getClientCharacter().getRoom().getSocket();
   if (socket != null && socket.connected()) {
     socket.emit("dungeonEnded");
   }
 }
Beispiel #2
0
  public void sendUpdate(float delta) {
    timer += delta;
    if (timer >= UPDATE_TIME && screen.getPlayer() != null && screen.getPlayer().hasMoved) {
      JSONObject data = new JSONObject();
      try {
        data.put("x", screen.getPlayer().getX());
        data.put("y", screen.getPlayer().getY());
        data.put("l", screen.getPlayer().getLocationIdentifier());

        socket.emit(EVENT_PLAYER_MOVED, data);
      } catch (JSONException e) {
        Gdx.app.log("SocketIO", "Error sending update");
      }
    }
  }
Beispiel #3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_cards_now, container, false);

    initViewsAndAdapters();
    initListView();

    FrameLayout mFrameLayout = (FrameLayout) view.findViewById(R.id.now_cards_list);
    mFrameLayout.addView(getExpandableListView());

    mSocket.on(
        EVENT_INIT,
        args -> {
          UI.execute(
              () -> {
                JSONObject jsonObject = (JSONObject) args[0];

                try {
                  JSONArray jsonArray = jsonObject.getJSONArray(INIT_BEACONS_KEY);
                  for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject beacon = (JSONObject) jsonArray.get(i);
                    String identifier = beacon.getString(ID_KEY);
                    int floor = beacon.getInt(FLOOR_KEY);

                    BeaconLocationManager bm = HereAndNowApplication.getBeaconLocationManager();
                    bm.addBeacon(identifier, floor, getContext());
                  }

                  // Start the manager.
                  HereAndNowApplication.getBeaconLocationManager().resume();

                  // Initialize cards.
                  JSONArray cardsArray = jsonObject.getJSONArray(INIT_MESSAGES_KEY);
                  setupInitialView(cardsArray);
                } catch (JSONException e) {
                  e.printStackTrace();
                }
              });
        });

    mSocket.emit(EVENT_INIT); // Requests latest messages

    initTopicsAndCards(createPreBuiltTopics(), getSourceTopicModel(), getTopicListAdapter());
    filterModel();

    return view;
  }
Beispiel #4
0
 private void emitEvent(Event event) {
   if (socket != null && socket.connected()) {
     socket.emit("newEvent", event.toJSON());
   }
 }
Beispiel #5
0
 private void emit(final String event, final Object... args) {
   if (mSocket.connected()) mSocket.emit(event, args);
 }