Skip to content

Commit b7541f0

Browse files
committed
Chat history revert
1 parent 8f600f9 commit b7541f0

File tree

8 files changed

+88
-32
lines changed

8 files changed

+88
-32
lines changed

coffee/src/client/module/Chat.coffee

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
class Chat
22
constructor:(game)->
33
@game=game
4-
@chatDiv = document.querySelector(".chat")
4+
@chatDiv=document.querySelector(".chat")
55
@listen()
6-
@history=[]
6+
@history=[""]
7+
@histState=0
8+
_this=@
9+
$(".com_i").on "input",()->
10+
_this.history[_this.history.length-1]=$(".com_i").val()
11+
console.log _this.history
12+
return
13+
chatGoBack:()->
14+
if @histState > 0
15+
@histState--
16+
$(".com_i").val @history[@histState]
17+
return
18+
chatGoForward:()->
19+
if @histState < @history.length-1
20+
@histState++
21+
$(".com_i").val @history[@histState]
722
return
823
listen:()->
924
_this=@
@@ -21,13 +36,15 @@ class Chat
2136
el.scrollTop = el.scrollHeight
2237
return
2338
log:(message)->
24-
atBottom = @isElementScrolledToBottom(@chatDiv)
25-
$(".chat").append(message+"<br>")
26-
if atBottom
27-
@scrollToBottom(@chatDiv)
39+
$(".chat").append "<span>#{message}<br></span>"
40+
@scrollToBottom @chatDiv
2841
return
42+
2943
command:(com)->
3044
if com isnt ""
31-
@history.push com
45+
@history[@history.length-1]=com
46+
@history.push ""
47+
@histState=@history.length-1
48+
console.log @history
3249
@game.socket.emit "command",com
3350
export {Chat}

coffee/src/client/module/FirstPersonControls.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class FirstPersonControls
3636
if z.keyCode is 27 and _this.gameState is "inventory"
3737
_this.setState "menu"
3838

39+
#Strzałki
40+
if z.keyCode is 38 and _this.gameState is "chat"
41+
_this.game.chat.chatGoBack()
42+
if z.keyCode is 40 and _this.gameState is "chat"
43+
_this.game.chat.chatGoForward()
44+
3945
#Klawisz Enter
4046
if z.keyCode is 13 and _this.gameState is "chat"
4147
_this.game.chat.command $(".com_i").val()

coffee/src/client/module/InventoryBar.coffee

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
class InventoryBar
3-
constructor:(options)->
3+
constructor:(game)->
4+
@game=game
45
for i in [0..9]
56
$(".player_hp").append("<span class='hp'></span> ")
67
for i in [0..9]
@@ -61,12 +62,13 @@ class InventoryBar
6162
@setFocus focus
6263
_this=@
6364
$(window).on 'wheel', (e)->
64-
if e.originalEvent.deltaY > 0
65-
focus++
66-
else
67-
focus--
68-
focus=focus %% 9
69-
_this.setFocus focus
65+
if _this.game.FPC.gameState is "gameLock"
66+
if e.originalEvent.deltaY > 0
67+
focus++
68+
else
69+
focus--
70+
focus=focus %% 9
71+
_this.setFocus focus
7072
tick:()->
7173
list = $(".item")
7274
for i in [0..list.length-1]

coffee/src/client/module/index.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class Game
6161
@bb=new BlockBreak @
6262
@world=new World @
6363
@chat=new Chat @
64+
@inv_bar = new InventoryBar @
6465
@FPC = new FirstPersonControls @
65-
@inv_bar = new InventoryBar
6666

6767
eventMap={
6868
"connect":()->
@@ -187,7 +187,7 @@ class Game
187187
if @FPC.gameState is "inventory"
188188
@pii.render()
189189
@inv_bar.tick()
190-
190+
191191
@renderer.render @scene, @camera
192192
return
193193
new Game()

src/client/module/Chat.js

Lines changed: 28 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/module/FirstPersonControls.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/module/InventoryBar.js

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/module/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)