forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChat.coffee
More file actions
51 lines (49 loc) · 1.12 KB
/
Chat.coffee
File metadata and controls
51 lines (49 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Chat
constructor:(game)->
@game=game
@chatDiv=document.querySelector(".chat")
@listen()
@history=[""]
@histState=0
_this=@
$(".com_i").on "input",()->
_this.history[_this.history.length-1]=$(".com_i").val()
console.log _this.history
return
chatGoBack:()->
if @histState > 0
@histState--
$(".com_i").val @history[@histState]
return
chatGoForward:()->
if @histState < @history.length-1
@histState++
$(".com_i").val @history[@histState]
return
listen:()->
_this=@
window.addEventListener "wheel", (e)->
if _this.game.FPC.gameState isnt "chat"
e.preventDefault()
return
, {passive: false}
return @
isElementScrolledToBottom:(el)->
if el.scrollTop >= (el.scrollHeight - el.offsetHeight)
return true
return false
scrollToBottom:(el)->
el.scrollTop = el.scrollHeight
return
log:(message)->
$(".chat").append "<span>#{message}<br></span>"
@scrollToBottom @chatDiv
return
command:(com)->
if com isnt ""
@history[@history.length-1]=com
@history.push ""
@histState=@history.length-1
console.log @history
@game.socket.emit "command",com
export {Chat}