{"size": 1254, "ext": "js", "max_stars_repo_path": "shared/packets.js", "max_stars_repo_name": "funmaker/pixel-lobby", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "shared/packets.js", "max_issues_repo_name": "funmaker/pixel-lobby", "max_issues_repo_issues_event_min_datetime": "2020-08-10T12:17:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-10T12:17:15.000Z", "max_forks_repo_path": "shared/packets.js", "max_forks_repo_name": "funmaker/pixel-lobby", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 19.2923076923, "max_line_length": 62, "alphanum_fraction": 0.6427432217}
import BSON from "bson";

export const types = {
  JOIN: "JOIN",
  LEAVE: "LEAVE",
  STATE: "STATE",
  CREATE_ENTITY: "CREATE_ENTITY",
  REMOVE_ENTITY: "REMOVE_ENTITY",
  UPDATE: "UPDATE",
  CHAT: "CHAT",
  MOVE: "MOVE",
  INTERACT: "INTERACT",
  KICK: "KICK",
};

export const join = (auth) => BSON.serialize({
  type: types.JOIN,
  auth,
});

export const leave = () => BSON.serialize({
  type: types.LEAVE,
});

export const state = (room, player) => BSON.serialize({
  type: types.STATE,
  ...room.serialize(),
  localPlayer: player.id,
});

export const createEntity = (entity) => BSON.serialize({
  type: types.CREATE_ENTITY,
  ...entity.serialize(),
});

export const removeEntity = (entity) => BSON.serialize({
  type: types.REMOVE_ENTITY,
  id: entity.id,
});

export const update = (room) => BSON.serialize({
  type: types.UPDATE,
  ...room.getUpdate(),
});

export const chat = (text, name, playerId) => BSON.serialize({
  type: types.CHAT,
  text, name, playerId,
});

export const move = (key, pressed) => BSON.serialize({
  type: types.MOVE,
  key, pressed,
});

export const interact = (id, data) => BSON.serialize({
  type: types.INTERACT,
  id, data
});

export const kick = (reason) => BSON.serialize({
  type: types.KICK,
  reason
});
