<commit_before>window.tiny = {
  scenes: {}
}

window.resizeView = () ->
  tnH = $(".topnav").height()
  bodyHeight = window.innerHeight - tnH
  chatWidth = $(".chat").width()
  portWidth = $(".main").width()

  w = Math.floor(portWidth - portWidth*.01)
  h = Math.floor(bodyHeight - bodyHeight*.01)
  $('#gameport').css({
    "width": w,
    "height": h,
  });

  $(".chat").css({
    "height": h,
  })
  $('#gameport')[0].width = w
  $('#gameport')[0].height = h


$(document).ready(() ->
  window.resizeView()
  $( window ).resize( ->
    window.resizeView();
  );
  window.tinybusters = new tiny.busters($('#gameport')[0])
);

<commit_msg>Initial chat infrastructure (chat works)<commit_after>window.tiny = {
  scenes: {}
}

window.resizeView = () ->
  tnH = $(".topnav").height()
  bodyHeight = window.innerHeight - tnH
  chatWidth = $(".chat").width()
  portWidth = $(".main").width()

  w = Math.floor(portWidth - portWidth*.01)
  h = Math.floor(bodyHeight - bodyHeight*.01)
  $('#gameport').css({
    "width": w,
    "height": h,
  });

  $(".chat").css({
    "height": h,
  })
  $('#gameport')[0].width = w
  $('#gameport')[0].height = h


$(document).ready(() ->
  window.resizeView()
  $( window ).resize( ->
    window.resizeView();
  );
  window.tinybusters = new tiny.busters($('#gameport')[0])
  sendMessage = ->
    message = $(".txt-chat").val()
    message =
      _t: 1,
      s: false,
      m: message
    message = msgpack.encode(message)
    window.conn.send(message)
    $(".txt-chat").val("")

  $(".btn-chat").click(sendMessage)
  $(".txt-chat").keypress (e) ->
      if e.which == 13
        sendMessage()
        e.preventDefault()
);

makeid = (n) ->
    text = "";
    possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    for i in [0..n-1]
      text += possible.charAt(Math.floor(Math.random() * possible.length));
    return text;

if window["WebSocket"]
  template =
    chat: Handlebars.compile($("#chatTemplate").html());
    server: Handlebars.compile($("#serverMessageTemplate").html());

  window.conn = new WebSocket("ws://localhost:9001/connect?name=#{makeid(8)}");
  conn.binaryType = "arraybuffer";
  conn.onopen = () ->
    $(".chatlist").empty()
  conn.onclose = (evt) ->
    $(".chatlist").append(template.server(message: "Server connection closed."))
  conn.onmessage = (evt) ->
    mp = msgpack.decode(evt.data)
    if mp.s
      $(".chatlist").append(template.server(message: mp.m))
    else
      $(".chatlist").append(template.chat(name: mp.n, message: mp.m))
{'fraction_non_alphanumeric': 0.21994481671265273, 'fraction_numerical': 0.013401655498620418, 'mean_word_length': 3.222961730449251, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4910642', 'n_tokens_mistral': 915, 'n_tokens_neox': 896, 'n_words': 149}